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

Fix id field during instantiation of Table derived struct based on proc attribute #78

Open
mjovanc opened this issue May 9, 2024 · 0 comments
Assignees
Labels
sqlite Issues related to SQLite
Milestone

Comments

@mjovanc
Copy link
Owner

mjovanc commented May 9, 2024

We need to add #[primary_key] or something similar over the field like this:

#[derive(Table)]
#[table_name = "categories"]
pub struct Category {
    #[primary_key]
    id: usize,
    name: String,
}

So when instantiating it, it should be enough to do:

let table_row: User = User {
        name: "mjovanc".to_string(),
    };

This is important since when doing INSERT operations when having autoincrement on the id field and not knowing the current id beforehand, and we definitely do not want to query to get that information before...

@mjovanc mjovanc added feature New feature or request sqlite Issues related to SQLite labels May 9, 2024
@mjovanc mjovanc added this to the v0.3.1-alpha milestone May 9, 2024
@mjovanc mjovanc self-assigned this May 9, 2024
@mjovanc mjovanc changed the title Generate id field during instantiation of Table derived struct based on proc attribute Fix id field during instantiation of Table derived struct based on proc attribute May 9, 2024
@mjovanc mjovanc removed the feature New feature or request label May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sqlite Issues related to SQLite
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

1 participant