indexes.d.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { entityKind } from "../entity.js";
  2. import type { SQL } from "../sql/sql.js";
  3. import type { AnySingleStoreColumn, SingleStoreColumn } from "./columns/index.js";
  4. import type { SingleStoreTable } from "./table.js";
  5. interface IndexConfig {
  6. name: string;
  7. columns: IndexColumn[];
  8. /**
  9. * If true, the index will be created as `create unique index` instead of `create index`.
  10. */
  11. unique?: boolean;
  12. /**
  13. * If set, the index will be created as `create index ... using { 'btree' | 'hash' }`.
  14. */
  15. using?: 'btree' | 'hash';
  16. /**
  17. * If set, the index will be created as `create index ... algorithm { 'default' | 'inplace' | 'copy' }`.
  18. */
  19. algorithm?: 'default' | 'inplace' | 'copy';
  20. /**
  21. * If set, adds locks to the index creation.
  22. */
  23. lock?: 'default' | 'none' | 'shared' | 'exclusive';
  24. }
  25. export type IndexColumn = SingleStoreColumn | SQL;
  26. export declare class IndexBuilderOn {
  27. private name;
  28. private unique;
  29. static readonly [entityKind]: string;
  30. constructor(name: string, unique: boolean);
  31. on(...columns: [IndexColumn, ...IndexColumn[]]): IndexBuilder;
  32. }
  33. export interface AnyIndexBuilder {
  34. build(table: SingleStoreTable): Index;
  35. }
  36. export interface IndexBuilder extends AnyIndexBuilder {
  37. }
  38. export declare class IndexBuilder implements AnyIndexBuilder {
  39. static readonly [entityKind]: string;
  40. constructor(name: string, columns: IndexColumn[], unique: boolean);
  41. using(using: IndexConfig['using']): this;
  42. algorithm(algorithm: IndexConfig['algorithm']): this;
  43. lock(lock: IndexConfig['lock']): this;
  44. }
  45. export declare class Index {
  46. static readonly [entityKind]: string;
  47. readonly config: IndexConfig & {
  48. table: SingleStoreTable;
  49. };
  50. constructor(config: IndexConfig, table: SingleStoreTable);
  51. }
  52. export type GetColumnsTableName<TColumns> = TColumns extends AnySingleStoreColumn<{
  53. tableName: infer TTableName extends string;
  54. }> | AnySingleStoreColumn<{
  55. tableName: infer TTableName extends string;
  56. }>[] ? TTableName : never;
  57. export declare function index(name: string): IndexBuilderOn;
  58. export declare function uniqueIndex(name: string): IndexBuilderOn;
  59. export {};
  60. /** @internal */
  61. /** @internal */
  62. /** @internal */