CoolFace
Apppublic

AK-21/Graphite-Industrial-Intelligence

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
indexes.js121 linesDownload Raw Back to gel-core
1import { SQL } from "../sql/sql.js";2import { entityKind, is } from "../entity.js";3import { IndexedColumn } from "./columns/index.js";4class IndexBuilderOn {5  constructor(unique, name) {6    this.unique = unique;7    this.name = name;8  }9  static [entityKind] = "GelIndexBuilderOn";10  on(...columns) {11    return new IndexBuilder(12      columns.map((it) => {13        if (is(it, SQL)) {14          return it;15        }16        it = it;17        const clonedIndexedColumn = new IndexedColumn(it.name, !!it.keyAsName, it.columnType, it.indexConfig);18        it.indexConfig = JSON.parse(JSON.stringify(it.defaultConfig));19        return clonedIndexedColumn;20      }),21      this.unique,22      false,23      this.name24    );25  }26  onOnly(...columns) {27    return new IndexBuilder(28      columns.map((it) => {29        if (is(it, SQL)) {30          return it;31        }32        it = it;33        const clonedIndexedColumn = new IndexedColumn(it.name, !!it.keyAsName, it.columnType, it.indexConfig);34        it.indexConfig = it.defaultConfig;35        return clonedIndexedColumn;36      }),37      this.unique,38      true,39      this.name40    );41  }42  /**43   * 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.44   *45   * If you have the `Gel_vector` extension installed in your database, you can use the `hnsw` and `ivfflat` options, which are predefined types.46   *47   * **You can always specify any string you want in the method, in case Drizzle doesn't have it natively in its types**48   *49   * @param method The name of the index method to be used50   * @param columns51   * @returns52   */53  using(method, ...columns) {54    return new IndexBuilder(55      columns.map((it) => {56        if (is(it, SQL)) {57          return it;58        }59        it = it;60        const clonedIndexedColumn = new IndexedColumn(it.name, !!it.keyAsName, it.columnType, it.indexConfig);61        it.indexConfig = JSON.parse(JSON.stringify(it.defaultConfig));62        return clonedIndexedColumn;63      }),64      this.unique,65      true,66      this.name,67      method68    );69  }70}71class IndexBuilder {72  static [entityKind] = "GelIndexBuilder";73  /** @internal */74  config;75  constructor(columns, unique, only, name, method = "btree") {76    this.config = {77      name,78      columns,79      unique,80      only,81      method82    };83  }84  concurrently() {85    this.config.concurrently = true;86    return this;87  }88  with(obj) {89    this.config.with = obj;90    return this;91  }92  where(condition) {93    this.config.where = condition;94    return this;95  }96  /** @internal */97  build(table) {98    return new Index(this.config, table);99  }100}101class Index {102  static [entityKind] = "GelIndex";103  config;104  constructor(config, table) {105    this.config = { ...config, table };106  }107}108function index(name) {109  return new IndexBuilderOn(false, name);110}111function uniqueIndex(name) {112  return new IndexBuilderOn(true, name);113}114export {115  Index,116  IndexBuilder,117  IndexBuilderOn,118  index,119  uniqueIndex120};121//# sourceMappingURL=indexes.js.map