medz/dart-orm
关于
支持类型安全的 Dart ORM,提供 Dart 模型和迁移、独立的数据库层,并支持 SQLite、PostgreSQL、MySQL 和 MariaDB。
数据与分析实测星标增长
- 24小时
- 0
- 7天
- -1
- 15天
- -1
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文Dart ORM
Plain Dart models, generated typed tables and explicit database sessions.
6.0.0-beta.12 requires Dart 3.13. Native SQLite and PostgreSQL 18 are verified on macOS and Linux. From beta.11, update the dependency; generated clients and reviewed migration definitions and fingerprints stay unchanged.
PostgreSQL typed reads and mutations address their physical table, excluding inherited rows. Migration verification rejects disabled or replica-only foreign-key checks, unsafe replication settings, partitions and inheritance links. Review unsupported topology and enforcement drift before resuming a history; see migration limits.
Native exceptions and error-code constants are available through the public PostgreSQL and SQLite modules. Catch failures outside the transaction; native errors retain their types and metadata without remapping or automatic retries.
From beta.10, regenerate clients to expose count(). Code copied from the
searchUsers example reads its returned .users and .total fields.
From beta.8, regenerate clients to use whereAny; keep reviewed migration
definitions and fingerprints unchanged.
Beta.8 introduced a breaking rewrite. When upgrading from beta.7 or earlier, migrate model declarations and application APIs, then regenerate clients. Earlier clients and migration definitions have no compatibility layer; existing databases require a separately reviewed baseline.
dart pub add orm:6.0.0-beta.12
import 'package:orm/query.dart';
import 'package:orm/sqlite.dart';
import 'package:orm/migration.dart';
import 'migrations/sqlite/history.dart' as migrations;
import 'models.dart';
import 'models.db.dart';
final db = AppDatabase(SqliteDriver.memory());
await MigrationRunner(db.database, migrations.history).apply();
final user = await db.users.create(username: 'seven', age: 28);
await db.users.update(user.id, nickname: 'Seven');
await db.users.update(user.id, nickname: null);
final cards = await db.users
.where(active: eq(true), age: gte(18))
.whereAny(username: startsWith('sev'), nickname: startsWith('sev'))
.orderBy(id: asc)
.limit(20)
.select<UserCard>();
print(cards.first.username);
await db.transaction((tx) async {
await tx.users.update(user.id, active: false);
});
await db.close();
create returns the inserted model. update returns the updated model or null
when the key and filters do not match. Omitted fields remain unchanged; explicit
null clears nullable fields. Selections are registered named records with direct
field access. Values are bound and identifiers are quoted.
From a repository checkout, run the complete example, including schema installation, typed reads, relationship loading and an idempotent order transaction:
dart pub get
dart run bin/orm.dart generate --schema example/models.dart --out example/models.db.dart --name AppDatabase --engine sqlite --check
dart run example/main.dart
- Models and generated queries
- Reviewed Dart migrations
- Complete order workflow
- Contributor checks and module boundaries
Each module has its own public import: schema.dart, query.dart,
database.dart, sqlite.dart, postgres.dart, migration.dart and dev.dart.
Implementation stays in lib/src/<module>/; modules depend on one another only
through those public entrypoints. All libraries are independent Dart files.
探索相关项目
加载中…