14 releases

new 0.2.5 Apr 27, 2024
0.2.4 Apr 27, 2024
0.1.7 Jan 23, 2024

#940 in Database interfaces

Download history 29/week @ 2024-01-19 1/week @ 2024-01-26 19/week @ 2024-02-23 2/week @ 2024-03-08 1/week @ 2024-03-15 40/week @ 2024-03-29 8/week @ 2024-04-05 401/week @ 2024-04-12 51/week @ 2024-04-19

500 downloads per month

MIT/Apache

25KB
677 lines

gluesql-derive

generate traits like ReflectGlueSqlRow, FromGlueSqlRow, ToGlueSqlRow to enable basic ORM functionality

Example

#[test]
fn test_reflectgluesql_field_struct() {
    #[allow(unused)]
    #[derive(ReflectGlueSqlRow)]
    struct Foo {
        a: i64,
        b: bool,
        c: String,
        d: Option<i64>,
    }
    assert_eq!(Foo::columns(), vec!["a", "b", "c", "d"]);
}

#[test]
fn test_fromgluesql_field_struct() {
    #[derive(FromGlueSqlRow)]
    struct Foo {
        a: i64,
        b: bool,
        c: String,
        d: Option<i64>,
    }
    let data = Foo::from_gluesql_row(
        &[
            "a".to_string(),
            "b".to_string(),
            "c".to_string(),
            "d".to_string(),
        ],
        vec![
            Value::I64(1),
            Value::Bool(true),
            Value::Str("hello".to_string()),
            Value::Null,
        ],
    )
        .unwrap();
    assert_eq!(data.a, 1);
    assert_eq!(data.b, true);
    assert_eq!(data.c, "hello");
    assert_eq!(data.d, None);
}

#[test]
fn test_togluesql_field_struct() {
    #[derive(ToGlueSqlRow)]
    struct Foo {
        a: i64,
        b: bool,
        c: String,
        d: Option<i64>,
        e: rust_decimal::Decimal,
    }
    let data = Foo {
        a: 1,
        b: true,
        c: "hello".to_string(),
        d: None,
        e: rust_decimal::Decimal::from_str("1.23").unwrap(),
    };
    let row = data.to_gluesql_row();
    println!("{:?}", row);
}

Dependencies

~15MB
~288K SLoC