gluesql / gluesql

GlueSQL is quite sticky. It attaches to anywhere.

Home Page:https://gluesql.org/docs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

gluesql-derive: Derive FromGlueSqlRow from Vec<Value> for structs

JakkuSakura opened this issue · comments

Hi, I just implemented a crate called gluesql-derive
https://crates.io/crates/gluesql-derive
https://github.com/JakkuSakura/gluesql-derive

You can write the following code now, no longer converting select results to structs manually

use gluesql_core::data::Value;
use gluesql_derive::FromGlueSqlRow;

#[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()],
    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);

I'm working on something related here - https://github.com/edezhic/prest/
Simple usage example can be found here - https://github.com/edezhic/prest/blob/main/examples/todo/src/main.rs
Besides from/into row it also provides utilities to easily CRUD table derived from the struct

I'm working on something related here - https://github.com/edezhic/prest/ Simple usage example can be found here - https://github.com/edezhic/prest/blob/main/examples/todo/src/main.rs Besides from/into row it also provides utilities to easily CRUD table derived from the struct

Table macro looks good. Just needs some docs.