common.d.cts 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. import type { ColumnBuilderBase, ColumnBuilderBaseConfig, ColumnBuilderExtraConfig, ColumnBuilderRuntimeConfig, ColumnDataType, HasGenerated } from "../../column-builder.cjs";
  2. import { ColumnBuilder } from "../../column-builder.cjs";
  3. import type { ColumnBaseConfig } from "../../column.cjs";
  4. import { Column } from "../../column.cjs";
  5. import { entityKind } from "../../entity.cjs";
  6. import type { Simplify, Update } from "../../utils.cjs";
  7. import type { UpdateDeleteAction } from "../foreign-keys.cjs";
  8. import type { AnyGelTable, GelTable } from "../table.cjs";
  9. import type { SQL } from "../../sql/sql.cjs";
  10. import type { GelIndexOpClass } from "../indexes.cjs";
  11. export interface ReferenceConfig {
  12. ref: () => GelColumn;
  13. actions: {
  14. onUpdate?: UpdateDeleteAction;
  15. onDelete?: UpdateDeleteAction;
  16. };
  17. }
  18. export interface GelColumnBuilderBase<T extends ColumnBuilderBaseConfig<ColumnDataType, string> = ColumnBuilderBaseConfig<ColumnDataType, string>, TTypeConfig extends object = object> extends ColumnBuilderBase<T, TTypeConfig & {
  19. dialect: 'gel';
  20. }> {
  21. }
  22. export declare abstract class GelColumnBuilder<T extends ColumnBuilderBaseConfig<ColumnDataType, string> = ColumnBuilderBaseConfig<ColumnDataType, string>, TRuntimeConfig extends object = object, TTypeConfig extends object = object, TExtraConfig extends ColumnBuilderExtraConfig = ColumnBuilderExtraConfig> extends ColumnBuilder<T, TRuntimeConfig, TTypeConfig & {
  23. dialect: 'gel';
  24. }, TExtraConfig> implements GelColumnBuilderBase<T, TTypeConfig> {
  25. private foreignKeyConfigs;
  26. static readonly [entityKind]: string;
  27. array<TSize extends number | undefined = undefined>(size?: TSize): GelArrayBuilder<{
  28. name: T['name'];
  29. dataType: 'array';
  30. columnType: 'GelArray';
  31. data: T['data'][];
  32. driverParam: T['driverParam'][] | string;
  33. enumValues: T['enumValues'];
  34. size: TSize;
  35. baseBuilder: T;
  36. } & (T extends {
  37. notNull: true;
  38. } ? {
  39. notNull: true;
  40. } : {}) & (T extends {
  41. hasDefault: true;
  42. } ? {
  43. hasDefault: true;
  44. } : {}), T>;
  45. references(ref: ReferenceConfig['ref'], actions?: ReferenceConfig['actions']): this;
  46. unique(name?: string, config?: {
  47. nulls: 'distinct' | 'not distinct';
  48. }): this;
  49. generatedAlwaysAs(as: SQL | T['data'] | (() => SQL)): HasGenerated<this, {
  50. type: 'always';
  51. }>;
  52. }
  53. export declare abstract class GelColumn<T extends ColumnBaseConfig<ColumnDataType, string> = ColumnBaseConfig<ColumnDataType, string>, TRuntimeConfig extends object = {}, TTypeConfig extends object = {}> extends Column<T, TRuntimeConfig, TTypeConfig & {
  54. dialect: 'gel';
  55. }> {
  56. readonly table: GelTable;
  57. static readonly [entityKind]: string;
  58. constructor(table: GelTable, config: ColumnBuilderRuntimeConfig<T['data'], TRuntimeConfig>);
  59. }
  60. export type IndexedExtraConfigType = {
  61. order?: 'asc' | 'desc';
  62. nulls?: 'first' | 'last';
  63. opClass?: string;
  64. };
  65. export declare class GelExtraConfigColumn<T extends ColumnBaseConfig<ColumnDataType, string> = ColumnBaseConfig<ColumnDataType, string>> extends GelColumn<T, IndexedExtraConfigType> {
  66. static readonly [entityKind]: string;
  67. getSQLType(): string;
  68. indexConfig: IndexedExtraConfigType;
  69. defaultConfig: IndexedExtraConfigType;
  70. asc(): Omit<this, 'asc' | 'desc'>;
  71. desc(): Omit<this, 'asc' | 'desc'>;
  72. nullsFirst(): Omit<this, 'nullsFirst' | 'nullsLast'>;
  73. nullsLast(): Omit<this, 'nullsFirst' | 'nullsLast'>;
  74. /**
  75. * ### PostgreSQL documentation quote
  76. *
  77. * > An operator class with optional parameters can be specified for each column of an index.
  78. * The operator class identifies the operators to be used by the index for that column.
  79. * For example, a B-tree index on four-byte integers would use the int4_ops class;
  80. * this operator class includes comparison functions for four-byte integers.
  81. * In practice the default operator class for the column's data type is usually sufficient.
  82. * The main point of having operator classes is that for some data types, there could be more than one meaningful ordering.
  83. * For example, we might want to sort a complex-number data type either by absolute value or by real part.
  84. * We could do this by defining two operator classes for the data type and then selecting the proper class when creating an index.
  85. * More information about operator classes check:
  86. *
  87. * ### Useful links
  88. * https://www.postgresql.org/docs/current/sql-createindex.html
  89. *
  90. * https://www.postgresql.org/docs/current/indexes-opclass.html
  91. *
  92. * https://www.postgresql.org/docs/current/xindex.html
  93. *
  94. * ### Additional types
  95. * If you have the `Gel_vector` extension installed in your database, you can use the
  96. * `vector_l2_ops`, `vector_ip_ops`, `vector_cosine_ops`, `vector_l1_ops`, `bit_hamming_ops`, `bit_jaccard_ops`, `halfvec_l2_ops`, `sparsevec_l2_ops` options, which are predefined types.
  97. *
  98. * **You can always specify any string you want in the operator class, in case Drizzle doesn't have it natively in its types**
  99. *
  100. * @param opClass
  101. * @returns
  102. */
  103. op(opClass: GelIndexOpClass): Omit<this, 'op'>;
  104. }
  105. export declare class IndexedColumn {
  106. static readonly [entityKind]: string;
  107. constructor(name: string | undefined, keyAsName: boolean, type: string, indexConfig: IndexedExtraConfigType);
  108. name: string | undefined;
  109. keyAsName: boolean;
  110. type: string;
  111. indexConfig: IndexedExtraConfigType;
  112. }
  113. export type AnyGelColumn<TPartial extends Partial<ColumnBaseConfig<ColumnDataType, string>> = {}> = GelColumn<Required<Update<ColumnBaseConfig<ColumnDataType, string>, TPartial>>>;
  114. export type GelArrayColumnBuilderBaseConfig = ColumnBuilderBaseConfig<'array', 'GelArray'> & {
  115. size: number | undefined;
  116. baseBuilder: ColumnBuilderBaseConfig<ColumnDataType, string>;
  117. };
  118. export declare class GelArrayBuilder<T extends GelArrayColumnBuilderBaseConfig, TBase extends ColumnBuilderBaseConfig<ColumnDataType, string> | GelArrayColumnBuilderBaseConfig> extends GelColumnBuilder<T, {
  119. baseBuilder: TBase extends GelArrayColumnBuilderBaseConfig ? GelArrayBuilder<TBase, TBase extends {
  120. baseBuilder: infer TBaseBuilder extends ColumnBuilderBaseConfig<any, any>;
  121. } ? TBaseBuilder : never> : GelColumnBuilder<TBase, {}, Simplify<Omit<TBase, keyof ColumnBuilderBaseConfig<any, any>>>>;
  122. size: T['size'];
  123. }, {
  124. baseBuilder: TBase extends GelArrayColumnBuilderBaseConfig ? GelArrayBuilder<TBase, TBase extends {
  125. baseBuilder: infer TBaseBuilder extends ColumnBuilderBaseConfig<any, any>;
  126. } ? TBaseBuilder : never> : GelColumnBuilder<TBase, {}, Simplify<Omit<TBase, keyof ColumnBuilderBaseConfig<any, any>>>>;
  127. size: T['size'];
  128. }> {
  129. static readonly [entityKind] = "GelArrayBuilder";
  130. constructor(name: string, baseBuilder: GelArrayBuilder<T, TBase>['config']['baseBuilder'], size: T['size']);
  131. }
  132. export declare class GelArray<T extends ColumnBaseConfig<'array', 'GelArray'> & {
  133. size: number | undefined;
  134. baseBuilder: ColumnBuilderBaseConfig<ColumnDataType, string>;
  135. }, TBase extends ColumnBuilderBaseConfig<ColumnDataType, string>> extends GelColumn<T, {}, {
  136. size: T['size'];
  137. baseBuilder: T['baseBuilder'];
  138. }> {
  139. readonly baseColumn: GelColumn;
  140. readonly range?: [number | undefined, number | undefined] | undefined;
  141. readonly size: T['size'];
  142. static readonly [entityKind]: string;
  143. constructor(table: AnyGelTable<{
  144. name: T['tableName'];
  145. }>, config: GelArrayBuilder<T, TBase>['config'], baseColumn: GelColumn, range?: [number | undefined, number | undefined] | undefined);
  146. getSQLType(): string;
  147. }