table.d.ts 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import type { BuildColumns, BuildExtraConfigColumns } from "../column-builder.js";
  2. import { entityKind } from "../entity.js";
  3. import { Table, type TableConfig as TableConfigBase, type UpdateTableConfig } from "../table.js";
  4. import type { CheckBuilder } from "./checks.js";
  5. import { type GelColumnsBuilders } from "./columns/all.js";
  6. import type { GelColumn, GelColumnBuilderBase } from "./columns/common.js";
  7. import type { ForeignKeyBuilder } from "./foreign-keys.js";
  8. import type { AnyIndexBuilder } from "./indexes.js";
  9. import type { GelPolicy } from "./policies.js";
  10. import type { PrimaryKeyBuilder } from "./primary-keys.js";
  11. import type { UniqueConstraintBuilder } from "./unique-constraint.js";
  12. export type GelTableExtraConfigValue = AnyIndexBuilder | CheckBuilder | ForeignKeyBuilder | PrimaryKeyBuilder | UniqueConstraintBuilder | GelPolicy;
  13. export type GelTableExtraConfig = Record<string, GelTableExtraConfigValue>;
  14. export type TableConfig = TableConfigBase<GelColumn>;
  15. export declare class GelTable<T extends TableConfig = TableConfig> extends Table<T> {
  16. static readonly [entityKind]: string;
  17. }
  18. export type AnyGelTable<TPartial extends Partial<TableConfig> = {}> = GelTable<UpdateTableConfig<TableConfig, TPartial>>;
  19. export type GelTableWithColumns<T extends TableConfig> = GelTable<T> & {
  20. [Key in keyof T['columns']]: T['columns'][Key];
  21. } & {
  22. enableRLS: () => Omit<GelTableWithColumns<T>, 'enableRLS'>;
  23. };
  24. export interface GelTableFn<TSchema extends string | undefined = undefined> {
  25. /**
  26. * @deprecated The third parameter of GelTable is changing and will only accept an array instead of an object
  27. *
  28. * @example
  29. * Deprecated version:
  30. * ```ts
  31. * export const users = gelTable("users", {
  32. * id: integer(),
  33. * }, (t) => ({
  34. * idx: index('custom_name').on(t.id)
  35. * }));
  36. * ```
  37. *
  38. * New API:
  39. * ```ts
  40. * export const users = gelTable("users", {
  41. * id: integer(),
  42. * }, (t) => [
  43. * index('custom_name').on(t.id)
  44. * ]);
  45. * ```
  46. */
  47. <TTableName extends string, TColumnsMap extends Record<string, GelColumnBuilderBase>>(name: TTableName, columns: TColumnsMap, extraConfig: (self: BuildExtraConfigColumns<TTableName, TColumnsMap, 'gel'>) => GelTableExtraConfig): GelTableWithColumns<{
  48. name: TTableName;
  49. schema: TSchema;
  50. columns: BuildColumns<TTableName, TColumnsMap, 'gel'>;
  51. dialect: 'gel';
  52. }>;
  53. /**
  54. * @deprecated The third parameter of gelTable is changing and will only accept an array instead of an object
  55. *
  56. * @example
  57. * Deprecated version:
  58. * ```ts
  59. * export const users = gelTable("users", {
  60. * id: integer(),
  61. * }, (t) => ({
  62. * idx: index('custom_name').on(t.id)
  63. * }));
  64. * ```
  65. *
  66. * New API:
  67. * ```ts
  68. * export const users = gelTable("users", {
  69. * id: integer(),
  70. * }, (t) => [
  71. * index('custom_name').on(t.id)
  72. * ]);
  73. * ```
  74. */
  75. <TTableName extends string, TColumnsMap extends Record<string, GelColumnBuilderBase>>(name: TTableName, columns: (columnTypes: GelColumnsBuilders) => TColumnsMap, extraConfig: (self: BuildExtraConfigColumns<TTableName, TColumnsMap, 'gel'>) => GelTableExtraConfig): GelTableWithColumns<{
  76. name: TTableName;
  77. schema: TSchema;
  78. columns: BuildColumns<TTableName, TColumnsMap, 'gel'>;
  79. dialect: 'gel';
  80. }>;
  81. <TTableName extends string, TColumnsMap extends Record<string, GelColumnBuilderBase>>(name: TTableName, columns: TColumnsMap, extraConfig?: (self: BuildExtraConfigColumns<TTableName, TColumnsMap, 'gel'>) => GelTableExtraConfigValue[]): GelTableWithColumns<{
  82. name: TTableName;
  83. schema: TSchema;
  84. columns: BuildColumns<TTableName, TColumnsMap, 'gel'>;
  85. dialect: 'gel';
  86. }>;
  87. <TTableName extends string, TColumnsMap extends Record<string, GelColumnBuilderBase>>(name: TTableName, columns: (columnTypes: GelColumnsBuilders) => TColumnsMap, extraConfig?: (self: BuildExtraConfigColumns<TTableName, TColumnsMap, 'gel'>) => GelTableExtraConfigValue[]): GelTableWithColumns<{
  88. name: TTableName;
  89. schema: TSchema;
  90. columns: BuildColumns<TTableName, TColumnsMap, 'gel'>;
  91. dialect: 'gel';
  92. }>;
  93. }
  94. export declare const gelTable: GelTableFn;
  95. export declare function gelTableCreator(customizeTableName: (name: string) => string): GelTableFn;