indexes.d.ts 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { SQL } from "../sql/sql.js";
  2. import { entityKind } from "../entity.js";
  3. import type { GelColumn, GelExtraConfigColumn } from "./columns/index.js";
  4. import { IndexedColumn } from "./columns/index.js";
  5. import type { GelTable } from "./table.js";
  6. interface IndexConfig {
  7. name?: string;
  8. columns: Partial<IndexedColumn | SQL>[];
  9. /**
  10. * If true, the index will be created as `create unique index` instead of `create index`.
  11. */
  12. unique: boolean;
  13. /**
  14. * If true, the index will be created as `create index concurrently` instead of `create index`.
  15. */
  16. concurrently?: boolean;
  17. /**
  18. * If true, the index will be created as `create index ... on only <table>` instead of `create index ... on <table>`.
  19. */
  20. only: boolean;
  21. /**
  22. * Condition for partial index.
  23. */
  24. where?: SQL;
  25. /**
  26. * The optional WITH clause specifies storage parameters for the index
  27. */
  28. with?: Record<string, any>;
  29. /**
  30. * The optional WITH clause method for the index
  31. */
  32. method?: 'btree' | string;
  33. }
  34. export type IndexColumn = GelColumn;
  35. export type GelIndexMethod = 'btree' | 'hash' | 'gist' | 'sGelist' | 'gin' | 'brin' | 'hnsw' | 'ivfflat' | (string & {});
  36. export type GelIndexOpClass = 'abstime_ops' | 'access_method' | 'anyarray_eq' | 'anyarray_ge' | 'anyarray_gt' | 'anyarray_le' | 'anyarray_lt' | 'anyarray_ne' | 'bigint_ops' | 'bit_ops' | 'bool_ops' | 'box_ops' | 'bpchar_ops' | 'char_ops' | 'cidr_ops' | 'cstring_ops' | 'date_ops' | 'float_ops' | 'int2_ops' | 'int4_ops' | 'int8_ops' | 'interval_ops' | 'jsonb_ops' | 'macaddr_ops' | 'name_ops' | 'numeric_ops' | 'oid_ops' | 'oidint4_ops' | 'oidint8_ops' | 'oidname_ops' | 'oidvector_ops' | 'point_ops' | 'polygon_ops' | 'range_ops' | 'record_eq' | 'record_ge' | 'record_gt' | 'record_le' | 'record_lt' | 'record_ne' | 'text_ops' | 'time_ops' | 'timestamp_ops' | 'timestamptz_ops' | 'timetz_ops' | 'uuid_ops' | 'varbit_ops' | 'varchar_ops' | 'xml_ops' | 'vector_l2_ops' | 'vector_ip_ops' | 'vector_cosine_ops' | 'vector_l1_ops' | 'bit_hamming_ops' | 'bit_jaccard_ops' | 'halfvec_l2_ops' | 'sparsevec_l2_op' | (string & {});
  37. export declare class IndexBuilderOn {
  38. private unique;
  39. private name?;
  40. static readonly [entityKind]: string;
  41. constructor(unique: boolean, name?: string | undefined);
  42. on(...columns: [Partial<GelExtraConfigColumn> | SQL, ...Partial<GelExtraConfigColumn | SQL>[]]): IndexBuilder;
  43. onOnly(...columns: [Partial<GelExtraConfigColumn | SQL>, ...Partial<GelExtraConfigColumn | SQL>[]]): IndexBuilder;
  44. /**
  45. * Specify what index method to use. Choices are `btree`, `hash`, `gist`, `sGelist`, `gin`, `brin`, or user-installed access methods like `bloom`. The default method is `btree.
  46. *
  47. * If you have the `Gel_vector` extension installed in your database, you can use the `hnsw` and `ivfflat` options, which are predefined types.
  48. *
  49. * **You can always specify any string you want in the method, in case Drizzle doesn't have it natively in its types**
  50. *
  51. * @param method The name of the index method to be used
  52. * @param columns
  53. * @returns
  54. */
  55. using(method: GelIndexMethod, ...columns: [Partial<GelExtraConfigColumn | SQL>, ...Partial<GelExtraConfigColumn | SQL>[]]): IndexBuilder;
  56. }
  57. export interface AnyIndexBuilder {
  58. build(table: GelTable): Index;
  59. }
  60. export interface IndexBuilder extends AnyIndexBuilder {
  61. }
  62. export declare class IndexBuilder implements AnyIndexBuilder {
  63. static readonly [entityKind]: string;
  64. constructor(columns: Partial<IndexedColumn | SQL>[], unique: boolean, only: boolean, name?: string, method?: string);
  65. concurrently(): this;
  66. with(obj: Record<string, any>): this;
  67. where(condition: SQL): this;
  68. }
  69. export declare class Index {
  70. static readonly [entityKind]: string;
  71. readonly config: IndexConfig & {
  72. table: GelTable;
  73. };
  74. constructor(config: IndexConfig, table: GelTable);
  75. }
  76. export type GetColumnsTableName<TColumns> = TColumns extends GelColumn ? TColumns['_']['name'] : TColumns extends GelColumn[] ? TColumns[number]['_']['name'] : never;
  77. export declare function index(name?: string): IndexBuilderOn;
  78. export declare function uniqueIndex(name?: string): IndexBuilderOn;
  79. export {};