Support composite primary key of length up to 12#1508
Conversation
0b08c40 to
877a9c2
Compare
src/executor/cursor.rs
Outdated
| .add(f(c2, v2)), | ||
| ) | ||
| .add(f(c1, v1)), | ||
| (Identity::Many(col_vec), ValueTuple::Many(value_vec)) |
There was a problem hiding this comment.
Oh wow... I was thinking, how did you come up with this algorithm?
There was a problem hiding this comment.
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.
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.
How can we verify this is actually correct
There was a problem hiding this comment.
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.
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.
A comprehensive testing on its way :P
* 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::Manysea-query#564New Features
IntoIdentityforIdentityIdentitysupports up to identity tuple ofDynIdenwith length up to 12IntoIdentityfor tuple ofIdenStaticwith length up to 12IdentityOffor tuple ofColumnTraitwith length up to 12TryGetableManyfor tuple ofTryGetablewith length up to 12TryFromU64for tuple ofTryFromU64with length up to 12Breaking Changes
Identity::Many