Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jakkusakura/gluesql-derive
generate traits like FromGlueSqlRow to enable basic ORM functionality
https://github.com/jakkusakura/gluesql-derive
Last synced: about 6 hours ago
JSON representation
generate traits like FromGlueSqlRow to enable basic ORM functionality
- Host: GitHub
- URL: https://github.com/jakkusakura/gluesql-derive
- Owner: JakkuSakura
- License: mit
- Created: 2024-01-23T09:35:22.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-01-23T15:24:36.000Z (12 months ago)
- Last Synced: 2024-03-23T17:48:42.877Z (10 months ago)
- Language: Rust
- Homepage:
- Size: 14.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gluesql-derive
generate traits like ReflectGlueSqlRow, FromGlueSqlRow, ToGlueSqlRow to enable basic ORM functionality
# Example
```rust
#[test]
fn test_reflectgluesql_field_struct() {
#[allow(unused)]
#[derive(ReflectGlueSqlRow)]
struct Foo {
a: i64,
b: bool,
c: String,
d: Option,
}
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,
}
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,
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);
}```