Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

type aliases unsupported #35

Open
maxomatic458 opened this issue Oct 13, 2023 · 1 comment
Open

type aliases unsupported #35

maxomatic458 opened this issue Oct 13, 2023 · 1 comment
Labels
help wanted Extra attention is needed

Comments

@maxomatic458
Copy link

the following example will not store the data correctly

type StringType = String;
type Number = i64;


#[derive(Turbosql, Default)]
struct Person {
    rowid: Option<i64>,
    name: Option<StringType>,
    age: Option<Number>,
    image_jpg: Option<Vec<u8>>
}

fn main() -> Result<(), Box<dyn std::error::Error>> {

    let name = "Joe";

    let rowid = Person {
        name: Some(name.to_string()),
        age: Some(42),
        ..Default::default()
    }.insert()?;

    Ok(())
}

the name will be stored as the name, but inside quotation marks
the age will be stored as regular text

when trying to query the database for a name, it will not find a match, because it is stored with quotation marks

without type aliases everything works fine

@trevyn trevyn added the help wanted Extra attention is needed label Nov 15, 2023
@trevyn
Copy link
Owner

trevyn commented Dec 31, 2023

Right, unrecognized arbitrary types are stored JSON-serialized. Unfortunately, as a macro, there's no straightforward way to get underlying type information.

I'm thinking the most reasonable/flexible way to handle this is to allow specifying a different storage type:

#[derive(Turbosql, Default)]
struct Person {
    rowid: Option<i64>,
    #[turbosql(as = "String")]
    name: Option<StringType>,
    #[turbosql(as = "i64")]
    age: Option<Number>,
    image_jpg: Option<Vec<u8>>
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants