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

Composite primary keys #185

Open
jayvdb opened this issue Feb 1, 2024 · 0 comments
Open

Composite primary keys #185

jayvdb opened this issue Feb 1, 2024 · 0 comments

Comments

@jayvdb
Copy link
Collaborator

jayvdb commented Feb 1, 2024

I believe that we can rather easily implement composite primary keys without adding any new attributes, if we put the composite key into a separate struct, e.g.

pub struct OrderPrimaryKey {
    pub order_id: u64,
    pub product_id: u64,
}

#[model]
#[derive(Deserialize, Serialize)]
pub struct Order {
    #[serde(flatten)]
    #[pk]
    pub pk: OrderPrimaryKey,
    pub quantity: u64,
    pub price: Decimal,
}

Then the two fields of OrderPrimaryKey would become columns of the Order table. #[pk] would need to do a bit more work to support this, and we may need to put #[derive(FieldType)] on OrderPrimaryKey so it can do some additional preparation work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant