table.d.ts 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import type { BuildColumns } 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 SQLiteColumnBuilders } from "./columns/all.js";
  6. import type { SQLiteColumn, SQLiteColumnBuilderBase } from "./columns/common.js";
  7. import type { ForeignKeyBuilder } from "./foreign-keys.js";
  8. import type { IndexBuilder } from "./indexes.js";
  9. import type { PrimaryKeyBuilder } from "./primary-keys.js";
  10. import type { UniqueConstraintBuilder } from "./unique-constraint.js";
  11. export type SQLiteTableExtraConfigValue = IndexBuilder | CheckBuilder | ForeignKeyBuilder | PrimaryKeyBuilder | UniqueConstraintBuilder;
  12. export type SQLiteTableExtraConfig = Record<string, SQLiteTableExtraConfigValue>;
  13. export type TableConfig = TableConfigBase<SQLiteColumn<any>>;
  14. export declare class SQLiteTable<T extends TableConfig = TableConfig> extends Table<T> {
  15. static readonly [entityKind]: string;
  16. }
  17. export type AnySQLiteTable<TPartial extends Partial<TableConfig> = {}> = SQLiteTable<UpdateTableConfig<TableConfig, TPartial>>;
  18. export type SQLiteTableWithColumns<T extends TableConfig> = SQLiteTable<T> & {
  19. [Key in keyof T['columns']]: T['columns'][Key];
  20. };
  21. export interface SQLiteTableFn<TSchema extends string | undefined = undefined> {
  22. <TTableName extends string, TColumnsMap extends Record<string, SQLiteColumnBuilderBase>>(name: TTableName, columns: TColumnsMap, extraConfig?: (self: BuildColumns<TTableName, TColumnsMap, 'sqlite'>) => SQLiteTableExtraConfigValue[]): SQLiteTableWithColumns<{
  23. name: TTableName;
  24. schema: TSchema;
  25. columns: BuildColumns<TTableName, TColumnsMap, 'sqlite'>;
  26. dialect: 'sqlite';
  27. }>;
  28. <TTableName extends string, TColumnsMap extends Record<string, SQLiteColumnBuilderBase>>(name: TTableName, columns: (columnTypes: SQLiteColumnBuilders) => TColumnsMap, extraConfig?: (self: BuildColumns<TTableName, TColumnsMap, 'sqlite'>) => SQLiteTableExtraConfigValue[]): SQLiteTableWithColumns<{
  29. name: TTableName;
  30. schema: TSchema;
  31. columns: BuildColumns<TTableName, TColumnsMap, 'sqlite'>;
  32. dialect: 'sqlite';
  33. }>;
  34. /**
  35. * @deprecated The third parameter of sqliteTable is changing and will only accept an array instead of an object
  36. *
  37. * @example
  38. * Deprecated version:
  39. * ```ts
  40. * export const users = sqliteTable("users", {
  41. * id: int(),
  42. * }, (t) => ({
  43. * idx: index('custom_name').on(t.id)
  44. * }));
  45. * ```
  46. *
  47. * New API:
  48. * ```ts
  49. * export const users = sqliteTable("users", {
  50. * id: int(),
  51. * }, (t) => [
  52. * index('custom_name').on(t.id)
  53. * ]);
  54. * ```
  55. */
  56. <TTableName extends string, TColumnsMap extends Record<string, SQLiteColumnBuilderBase>>(name: TTableName, columns: TColumnsMap, extraConfig?: (self: BuildColumns<TTableName, TColumnsMap, 'sqlite'>) => SQLiteTableExtraConfig): SQLiteTableWithColumns<{
  57. name: TTableName;
  58. schema: TSchema;
  59. columns: BuildColumns<TTableName, TColumnsMap, 'sqlite'>;
  60. dialect: 'sqlite';
  61. }>;
  62. /**
  63. * @deprecated The third parameter of sqliteTable is changing and will only accept an array instead of an object
  64. *
  65. * @example
  66. * Deprecated version:
  67. * ```ts
  68. * export const users = sqliteTable("users", {
  69. * id: int(),
  70. * }, (t) => ({
  71. * idx: index('custom_name').on(t.id)
  72. * }));
  73. * ```
  74. *
  75. * New API:
  76. * ```ts
  77. * export const users = sqliteTable("users", {
  78. * id: int(),
  79. * }, (t) => [
  80. * index('custom_name').on(t.id)
  81. * ]);
  82. * ```
  83. */
  84. <TTableName extends string, TColumnsMap extends Record<string, SQLiteColumnBuilderBase>>(name: TTableName, columns: (columnTypes: SQLiteColumnBuilders) => TColumnsMap, extraConfig?: (self: BuildColumns<TTableName, TColumnsMap, 'sqlite'>) => SQLiteTableExtraConfig): SQLiteTableWithColumns<{
  85. name: TTableName;
  86. schema: TSchema;
  87. columns: BuildColumns<TTableName, TColumnsMap, 'sqlite'>;
  88. dialect: 'sqlite';
  89. }>;
  90. }
  91. export declare const sqliteTable: SQLiteTableFn;
  92. export declare function sqliteTableCreator(customizeTableName: (name: string) => string): SQLiteTableFn;