Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/myuon/debil
Lightweight ORM for Rust
https://github.com/myuon/debil
Last synced: 23 days ago
JSON representation
Lightweight ORM for Rust
- Host: GitHub
- URL: https://github.com/myuon/debil
- Owner: myuon
- License: mit
- Created: 2019-10-23T13:22:37.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2022-05-14T06:27:49.000Z (over 2 years ago)
- Last Synced: 2024-10-12T01:49:37.871Z (26 days ago)
- Language: Rust
- Homepage:
- Size: 101 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# debil [![debil at crates.io](https://img.shields.io/crates/v/debil.svg)](https://crates.io/crates/debil)
ORM aims to provide Table macro and auto migration
## Table macro
You need to specify `sql_type` to be something that each DB crate provides.
```rust
#[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](https://docs.rs/debil/).
## Accessor macro
Accessor macro provides safe way to access to each column. This is useful for constructing a query.
```rust
// 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!
```