duxt_orm 0.2.1
duxt_orm: ^0.2.1 copied to clipboard
ActiveRecord-style ORM for Dart. Supports PostgreSQL, MySQL, and SQLite with auto-migrations, query builder, and schema definitions.
0.2.1 #
Added #
- Pivot table support for many-to-many relationships
Entity.registerPivotTable()- Register pivot tables with composite primary keysattach(relation, id)- Attach a related model through pivot tabledetach(relation, id)- Detach a related model from pivot tablesync(relation, ids)- Sync relations (replace all with given IDs)
- Composite primary keys - Schema now supports multi-column primary keys for pivot tables
- Pivot tables are automatically migrated with
DuxtOrm.migrate()
Example #
// In Post model
Entity.registerRelation<Post>('tags', BelongsToMany<Tag>(
pivotTable: 'post_tags',
foreignPivotKey: 'post_id',
relatedPivotKey: 'tag_id',
));
Entity.registerPivotTable('post_tags', schema: {
'post_id': Column.integer().notNull().references('posts'),
'tag_id': Column.integer().notNull().references('tags'),
}, primaryKey: ['post_id', 'tag_id']);
// Usage
await post.attach('tags', tagId);
await post.detach('tags', tagId);
await post.sync('tags', [1, 2, 3]);
0.2.0 #
Added #
- Relations support - Define relationships between models
HasMany<T>- One-to-many relationships (e.g., Category has many Posts)BelongsTo<T>- Inverse of has-many (e.g., Post belongs to Category)HasOne<T>- One-to-one relationships (e.g., User has one Profile)BelongsToMany<T>- Many-to-many through pivot tables
- Eager loading - Load related models in a single query with
.with_()// Load posts with their categories (no N+1 queries!) final posts = await Model.query<Post>() .with_(['category']) .get(); for (final post in posts) { print(post.category?.name); // Already loaded } - Relation accessors -
getRelation<T>(),setRelation(),relationLoaded() - Model registration for relations -
Model.registerRelation<T>(name, relation)
Changed #
toMap()should now include the id field for relations to work correctly
0.1.0 #
- Initial release
- ActiveRecord-style ORM with GORM-like auto-migrations
- Database adapters for PostgreSQL, MySQL, and SQLite
- Query builder with fluent API
- Schema definition with column types and modifiers
- Auto table name inference from class names
- Transaction support
- Raw query execution
- Aggregate functions (count, sum, avg, max, min)
- Bulk update and delete operations