debil debil at crates.io

Lightweight ORM for Rust

To use a specific DB, see debil-xxx family.

How to use

Basically debil provides Table macro and Accessor macro.

Table macro

You need to specify sql_type to be something that each DB crate provides.

```rust

[derive(Table)]

[sql(tablename = "ex1", sqltype = "...", primarykey = "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

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(tablename = "ex1", sqltype = "...", primarykey = "pk")]

struct Ex1 { field1: String, aaaa: i32, pk: i32, }

// Use accessor! macro to access to a field with tablename prefixed asserteq!(accessor!(Ex1::field1), "ex_1.field1");

// If you only need field name, use accessorname! macro asserteq!(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! ```