lref-macros
Procedural macros for Rust Entity Framework (lref).
Provides:
#[derive(EntityType)]�?generatesEntityType,FromRow,GetKeyValues, andEntitySnapshottrait implementationscolumn!()�?resolves entity fields to database column names at compile time
Usage
use *;
use column;
// Type-safe column reference
let col = column!; // expands to Blog::COLUMN_URL �?"url"
Generated Code
For each struct, #[derive(EntityType)] generates:
EntityTypeimpl �?returnsEntityTypeMetawith table name, columns, keys, navigationsFromRowimpl �?materializes entities from&[String]database row dataGetKeyValuesimpl �?returns primary key values for SaveChanges WHERE clausesEntitySnapshotimpl �?returns all scalar property values for INSERT/UPDATECOLUMN_*constants �?type-safe column name references (used bycolumn!())
Supported Field Attributes
| Attribute | Description | Example |
|---|---|---|
#[primary_key] |
Primary key column | pub id: i32 |
#[auto_increment] |
Auto-increment / identity | pub id: i32 |
#[required] |
NOT NULL constraint | pub name: String |
#[max_length(200)] |
Max string length | pub url: String |
#[column("db_col")] |
Different DB column name | pub rust_name: String |
#[foreign_key(User)] |
Foreign key reference | pub user_id: i32 |
#[navigation] |
Navigation property | pub blog: BelongsTo<Blog> |
#[not_mapped] |
Exclude from mapping | pub temp: String |
#[index] |
Create database index | pub email: String |
#[unique] |
Create unique index | pub username: String |
#[concurrency_check] |
Optimistic concurrency token | pub version: i32 |
License
MIT �?see LICENSE