Crates.io | debil |
lib.rs | debil |
version | 0.5.0 |
source | src |
created_at | 2020-01-25 07:26:34.274046 |
updated_at | 2022-03-27 07:31:04.907707 |
description | Lightweight ORM for Rust |
homepage | |
repository | https://github.com/myuon/debil |
max_upload_size | |
id | 201829 |
size | 61,801 |
ORM aims to provide Table macro and auto migration
You need to specify sql_type
to be something that each DB crate provides.
#[derive(Table)]
#[sql(table_name = "ex_1", sql_type = "...", primary_key = "pk")]
struct Ex1 {
#[sql(size = 50, unique = true, not_null = true)]
field1: String,
aaaa: i32,
pk: i32,
}
This example derives some useful mapper functions for this struct. See functions in debil's docs.
Accessor macro provides safe way to access to each column. This is useful for constructing a query.
// Use Accessor derive here!
#[derive(Table, Accessor)]
#[sql(table_name = "ex_1", sql_type = "...", primary_key = "pk")]
struct Ex1 {
field1: String,
aaaa: i32,
pk: i32,
}
// Use accessor! macro to access to a field with table_name prefixed
assert_eq!(accessor!(Ex1::field1), "ex_1.field1");
// If you only need field name, use accessor_name! macro
assert_eq!(accessor_name!(Ex1::aaaa), "aaaa");
// Or you can just call the field name function directly, which is derived by Accessor derive
assert_eq!(Ex1::field1(), "field1");
// accessor!(Ex1::foobar) <- compile error!