-
-
Notifications
You must be signed in to change notification settings - Fork 521
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
Support composite primary key of length up to 12 #1508
Conversation
0b08c40
to
877a9c2
Compare
src/executor/cursor.rs
Outdated
@@ -101,6 +101,28 @@ where | |||
.add(f(c2, v2)), | |||
) | |||
.add(f(c1, v1)), | |||
(Identity::Many(col_vec), ValueTuple::Many(value_vec)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh wow... I was thinking, how did you come up with this algorithm?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added some test cases to ensure its correctness. Since it's originally written by you can you please double check it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied it from stack overflow... umm actually from issue #1209
src/executor/cursor.rs
Outdated
r#"SELECT "m"."w", "m"."x", "m"."y", "m"."z""#, | ||
r#"FROM "m""#, | ||
r#"WHERE ("m"."w" = $1 AND "m"."x" = $2 AND "m"."y" = $3 AND "m"."z" > $4)"#, | ||
r#"OR ("m"."w" = $5 AND "m"."x" = $6 AND "m"."y" > $7)"#, | ||
r#"OR ("m"."w" = $8 AND "m"."x" > $9)"#, | ||
r#"OR "m"."w" > $10"#, | ||
r#"ORDER BY "m"."w" ASC, "m"."x" ASC, "m"."y" ASC, "m"."z" ASC"#, | ||
r#"LIMIT $11"#, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can we verify this is actually correct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An induction proof? e933b57
Assume the logic of Many
is correct. Then, Many
with its inner Vec
of length 1, 2 and 3 should produce the same SQL of it counterpart One
, Two
, Three
.
E.g. for One
, both should yield the same SQL statement.
Entity::find()
.cursor_by(Column::Id)
.before(10)
.first(2)
Entity::find()
.cursor_by(Identity::Many(vec![Column::Id.into_iden()]))
.before(ValueTuple::Many(vec![10.into()]))
.first(2)
Repeat the assertion for Two
and Three
as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, but that's only the basis of the induction. I am more concerned with why it should be correct from 4 onwards.
// WHERE | ||
// (col_1 = val_1 AND col_2 = val_2 AND ... AND col_n > val_n) | ||
// OR (col_1 = val_1 AND col_2 = val_2 AND ... AND col_n-1 > val_n-1) | ||
// OR (col_1 = val_1 AND col_2 = val_2 AND ... AND col_n-2 > val_n-2) | ||
// OR ... | ||
// OR (col_1 = val_1 AND col_2 > val_2) | ||
// OR (col_1 > val_1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greatly appreciated! 💯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A comprehensive testing on its way :P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check this. The algorithm in action. 2bec23a
* Optional Field SeaQL/sea-orm#1513 * .gitignore SeaQL/sea-orm#1334 * migration table custom name SeaQL/sea-orm#1511 * OR condition relation SeaQL/sea-orm#1433 * DerivePartialModel SeaQL/sea-orm#1597 * space for migration file naming SeaQL/sea-orm#1570 * composite key up to 12 SeaQL/sea-orm#1508 * seaography integration SeaQL/sea-orm#1599 * QuerySelect SimpleExpr SeaQL/sea-orm#1702 * sqlErr SeaQL/sea-orm#1707 * migration check SeaQL/sea-orm#1519 * postgres array SeaQL/sea-orm#1565 * param intoString SeaQL/sea-orm#1439 * **skipped** re-export SeaQL/sea-orm#1661 * ping SeaQL/sea-orm#1627 * on empty do nothing SeaQL/sea-orm#1708 * on conflict do nothing SeaQL/sea-orm#1712 * **skipped** upgrade versions * active enum fail safe SeaQL/sea-orm#1374 * relation generation check SeaQL/sea-orm#1435 * entity generation bug SeaQL/sea-schema#105 * **skipped** bug fix that does not require edits * EnumIter change SeaQL/sea-orm#1535 * completed and fixed a previous todo SeaQL/sea-orm#1570 * amended wordings and structures * Edit * Remove temp file --------- Co-authored-by: Billy Chan <[email protected]>
🎉 Released In 0.12.1 🎉Thank you everyone for the contribution! |
PR Info
Closes large composite key table #1294
Dependencies:
ValueTuple::Many
sea-query#564New Features
IntoIdentity
forIdentity
Identity
supports up to identity tuple ofDynIden
with length up to 12IntoIdentity
for tuple ofIdenStatic
with length up to 12IdentityOf
for tuple ofColumnTrait
with length up to 12TryGetableMany
for tuple ofTryGetable
with length up to 12TryFromU64
for tuple ofTryFromU64
with length up to 12Breaking Changes
Identity::Many