foreign-keys.d.cts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { entityKind } from "../entity.cjs";
  2. import type { AnySQLiteColumn, SQLiteColumn } from "./columns/index.cjs";
  3. import type { SQLiteTable } 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: SQLiteColumn[];
  8. readonly foreignTable: SQLiteTable;
  9. readonly foreignColumns: SQLiteColumn[];
  10. };
  11. export declare class ForeignKeyBuilder {
  12. static readonly [entityKind]: string;
  13. _: {
  14. brand: 'SQLiteForeignKeyBuilder';
  15. foreignTableName: 'TForeignTableName';
  16. };
  17. constructor(config: () => {
  18. name?: string;
  19. columns: SQLiteColumn[];
  20. foreignColumns: SQLiteColumn[];
  21. }, actions?: {
  22. onUpdate?: UpdateDeleteAction;
  23. onDelete?: UpdateDeleteAction;
  24. } | undefined);
  25. onUpdate(action: UpdateDeleteAction): this;
  26. onDelete(action: UpdateDeleteAction): this;
  27. }
  28. export declare class ForeignKey {
  29. readonly table: SQLiteTable;
  30. static readonly [entityKind]: string;
  31. readonly reference: Reference;
  32. readonly onUpdate: UpdateDeleteAction | undefined;
  33. readonly onDelete: UpdateDeleteAction | undefined;
  34. constructor(table: SQLiteTable, builder: ForeignKeyBuilder);
  35. getName(): string;
  36. }
  37. type ColumnsWithTable<TTableName extends string, TColumns extends SQLiteColumn[]> = {
  38. [Key in keyof TColumns]: AnySQLiteColumn<{
  39. tableName: TTableName;
  40. }>;
  41. };
  42. /**
  43. * @deprecated please use `foreignKey({ columns: [], foreignColumns: [] })` syntax without callback
  44. * @param config
  45. * @returns
  46. */
  47. export declare function foreignKey<TTableName extends string, TForeignTableName extends string, TColumns extends [AnySQLiteColumn<{
  48. tableName: TTableName;
  49. }>, ...AnySQLiteColumn<{
  50. tableName: TTableName;
  51. }>[]]>(config: () => {
  52. name?: string;
  53. columns: TColumns;
  54. foreignColumns: ColumnsWithTable<TForeignTableName, TColumns>;
  55. }): ForeignKeyBuilder;
  56. export declare function foreignKey<TTableName extends string, TForeignTableName extends string, TColumns extends [AnySQLiteColumn<{
  57. tableName: TTableName;
  58. }>, ...AnySQLiteColumn<{
  59. tableName: TTableName;
  60. }>[]]>(config: {
  61. name?: string;
  62. columns: TColumns;
  63. foreignColumns: ColumnsWithTable<TForeignTableName, TColumns>;
  64. }): ForeignKeyBuilder;
  65. export {};