lref — Core ORM Crate
Interface-oriented ORM core: traits, query builder, change tracking, migration engine, DI integration.
Quick Example
use *;
// DI registration
use ServiceCollection;
use *;
use DbContextOptionsBuilderExt as _;
let provider = new
.
.build.unwrap;
let ctx: = provider.get;
Module Map
lref/src/
├── entity.rs — IEntityType, IFromRow, IGetKeyValues, IEntitySnapshot
├── metadata.rs — EntityTypeMeta, PropertyMeta, NavigationMeta
├── provider.rs — IDatabaseProvider, ISqlGenerator, IAsyncConnection, DbValue
├── db_context.rs — IDbContext, IDbContextExt, DbContext, DbContextOptions
├── db_set.rs — IDbSet<T>, DbSet<T>
├── query.rs — IQueryable<T>, QueryBuilder<T>
├── change_executor.rs — ChangeExecutor (INSERT/UPDATE/DELETE)
├── model_builder.rs — ModelBuilder, IEntityTypeConfiguration<T>
├── tracking.rs — ChangeTracker (property-level snapshots)
├── relations.rs — BelongsTo, HasMany, HasOne (no trait bounds)
├── migration.rs — MigrationEngine
├── di.rs — lrdi integration (add_dbcontext / FromDbContextOptions)
├── cache.rs — DbCache (Identity Map)
└── error.rs — LrefError, LrefResult
Core Traits
Entity
Session (object-safe)
Collection
Provider
DI Integration
use ServiceCollection;
use *;
use DbContextOptionsBuilderExt as _;
let provider = new
.
.build.unwrap;
let ctx: = provider.get;
Provider factory: use_sqlite() injects a closure into DbContextOptions. DbContext::from_options() calls it to create the provider — core stays fully decoupled.
QueryBuilder API
// Filtering
query.filter_column.filter_in
.filter_is_null.filter_is_not_null.filter_between
// Ordering, pagination, JOIN, grouping
.order_by_column.order_by_desc_column.skip.take
.inner_join.left_join
.group_by.having
// Eager loading
.include_named
// Terminal
.to_list.await? // Vec<T>
.first.await? // T
.first_or_default.await? // Option<T>
.count.await? // i64
.any.await? // bool
.sum.await? // f64
.avg.await? // f64
// Bulk
.execute_update.set_column.execute.await?
.execute_delete.await?
License
MIT