Oyelowo / surreal-orm

Powerful & expressive ORM/query-builder/static checker for raw queries/Fully Automated migration tooling , designed to offer an intuitive API, strict type-checking, novel features, & full specification support. It provides a fresh perspective in data management. Currently supports SurrealDB engine. RDMSs(PG, MYSQL etc) and others coming soon
85 stars 2 forks source link

47 support optional and complex vector type autoinferences #48

Closed Oyelowo closed 10 months ago

Oyelowo commented 10 months ago

This update is all about smarter type inference, stronger compile-time checks, and cleaner, more maintainable code structures. These advancements will streamline your development workflow and improve the robustness of your applications. Changes include:

#[derive(Node, Serialize, Deserialize, Debug, Clone, Default)]
#[serde(rename_all = "camelCase")]
#[surreal_orm(table_name = "test_stuff")]
pub struct TestStuff {
    pub id: SurrealSimpleId<Self>,
    #[surreal_orm(type_ = "option<string>")]
    pub amt: Option<Strength>,

    // Would be throw a compile-time error since we cannot directly guess the 'Strength' type from the AST. Use explicit type if you want. You can use `#[surreal_orm(type_ = "int")]` to fix this. You can also use the type - "any"
    pub amt2: Option<Strength>,

    // Would be autoinferred as option<int>
    pub amt3: Option<u64>,

     // Inner type is now autoinferred as vec<int>
    pub amt4: Vec<u64>,

    pub count: u64,
}

#[derive(Node, Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
#[surreal_orm(table_name = "company")]
struct Company {
    id: SurrealId<Self, i32>,

    // Now works 
    #[surreal_orm(nest_array = "Person")]
    founders: Vec<Person>,

    // Now works
    #[surreal_orm(nest_array = "Person")]
    founders_multiple_nesting: Vec<Vec<Person>>,

    #[surreal_orm(nest_array = "Person")]
    founders: Vec<Person>,

    #[surreal_orm(nest_array = "Person")]
    founders_multiple_nesting: Vec<Vec<Person>>,

    #[surreal_orm(nest_array = "Person")]
    founders_10: Vec<Vec<Vec<Vec<Vec<Vec<Vec<Vec<Vec<Vec<Person>>>>>>>>>>,

}