| 538 | } |
| 539 | |
| 540 | function relationBuilder< |
| 541 | Tables extends Record<string, AnyTable>, |
| 542 | K extends keyof Tables, |
| 543 | >(tables: Tables, k: K): RelationBuilder<Tables, K> { |
| 544 | const referencer = tables[k]; |
| 545 | |
| 546 | return { |
| 547 | one(another, ...on) { |
| 548 | if (on.length > 0) { |
| 549 | const init = new ExplicitRelationInit( |
| 550 | "one", |
| 551 | tables[another], |
| 552 | referencer |
| 553 | ); |
| 554 | init.on = on as [string, string][]; |
| 555 | return init; |
| 556 | } |
| 557 | |
| 558 | return new ImplicitRelationInit( |
| 559 | "one", |
| 560 | tables[another], |
| 561 | referencer |
| 562 | ) as any; |
| 563 | }, |
| 564 | many(another) { |
| 565 | return new ImplicitRelationInit("many", tables[another], referencer); |
| 566 | }, |
| 567 | }; |
| 568 | } |
| 569 | |
| 570 | export function table<Columns extends Record<string, AnyColumn>>( |
| 571 | name: string | Partial<NameVariants>, |