foreign-keys.d.cts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { entityKind } from "../entity.cjs";
  2. import type { AnyGelColumn, GelColumn } from "./columns/index.cjs";
  3. import type { GelTable } from "./table.cjs";
  4. export type UpdateDeleteAction = 'cascade' | 'restrict' | 'no action' | 'set null' | 'set default';
  5. export type Reference = () => {
  6. readonly name?: string;
  7. readonly columns: GelColumn[];
  8. readonly foreignTable: GelTable;
  9. readonly foreignColumns: GelColumn[];
  10. };
  11. export declare class ForeignKeyBuilder {
  12. static readonly [entityKind]: string;
  13. constructor(config: () => {
  14. name?: string;
  15. columns: GelColumn[];
  16. foreignColumns: GelColumn[];
  17. }, actions?: {
  18. onUpdate?: UpdateDeleteAction;
  19. onDelete?: UpdateDeleteAction;
  20. } | undefined);
  21. onUpdate(action: UpdateDeleteAction): this;
  22. onDelete(action: UpdateDeleteAction): this;
  23. }
  24. export type AnyForeignKeyBuilder = ForeignKeyBuilder;
  25. export declare class ForeignKey {
  26. readonly table: GelTable;
  27. static readonly [entityKind]: string;
  28. readonly reference: Reference;
  29. readonly onUpdate: UpdateDeleteAction | undefined;
  30. readonly onDelete: UpdateDeleteAction | undefined;
  31. constructor(table: GelTable, builder: ForeignKeyBuilder);
  32. getName(): string;
  33. }
  34. type ColumnsWithTable<TTableName extends string, TColumns extends GelColumn[]> = {
  35. [Key in keyof TColumns]: AnyGelColumn<{
  36. tableName: TTableName;
  37. }>;
  38. };
  39. export declare function foreignKey<TTableName extends string, TForeignTableName extends string, TColumns extends [AnyGelColumn<{
  40. tableName: TTableName;
  41. }>, ...AnyGelColumn<{
  42. tableName: TTableName;
  43. }>[]]>(config: {
  44. name?: string;
  45. columns: TColumns;
  46. foreignColumns: ColumnsWithTable<TForeignTableName, TColumns>;
  47. }): ForeignKeyBuilder;
  48. export {};