indexes.cjs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. "use strict";
  2. var __defProp = Object.defineProperty;
  3. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  4. var __getOwnPropNames = Object.getOwnPropertyNames;
  5. var __hasOwnProp = Object.prototype.hasOwnProperty;
  6. var __export = (target, all) => {
  7. for (var name in all)
  8. __defProp(target, name, { get: all[name], enumerable: true });
  9. };
  10. var __copyProps = (to, from, except, desc) => {
  11. if (from && typeof from === "object" || typeof from === "function") {
  12. for (let key of __getOwnPropNames(from))
  13. if (!__hasOwnProp.call(to, key) && key !== except)
  14. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  15. }
  16. return to;
  17. };
  18. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  19. var indexes_exports = {};
  20. __export(indexes_exports, {
  21. Index: () => Index,
  22. IndexBuilder: () => IndexBuilder,
  23. IndexBuilderOn: () => IndexBuilderOn,
  24. index: () => index,
  25. uniqueIndex: () => uniqueIndex
  26. });
  27. module.exports = __toCommonJS(indexes_exports);
  28. var import_sql = require("../sql/sql.cjs");
  29. var import_entity = require("../entity.cjs");
  30. var import_columns = require("./columns/index.cjs");
  31. class IndexBuilderOn {
  32. constructor(unique, name) {
  33. this.unique = unique;
  34. this.name = name;
  35. }
  36. static [import_entity.entityKind] = "GelIndexBuilderOn";
  37. on(...columns) {
  38. return new IndexBuilder(
  39. columns.map((it) => {
  40. if ((0, import_entity.is)(it, import_sql.SQL)) {
  41. return it;
  42. }
  43. it = it;
  44. const clonedIndexedColumn = new import_columns.IndexedColumn(it.name, !!it.keyAsName, it.columnType, it.indexConfig);
  45. it.indexConfig = JSON.parse(JSON.stringify(it.defaultConfig));
  46. return clonedIndexedColumn;
  47. }),
  48. this.unique,
  49. false,
  50. this.name
  51. );
  52. }
  53. onOnly(...columns) {
  54. return new IndexBuilder(
  55. columns.map((it) => {
  56. if ((0, import_entity.is)(it, import_sql.SQL)) {
  57. return it;
  58. }
  59. it = it;
  60. const clonedIndexedColumn = new import_columns.IndexedColumn(it.name, !!it.keyAsName, it.columnType, it.indexConfig);
  61. it.indexConfig = it.defaultConfig;
  62. return clonedIndexedColumn;
  63. }),
  64. this.unique,
  65. true,
  66. this.name
  67. );
  68. }
  69. /**
  70. * 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.
  71. *
  72. * If you have the `Gel_vector` extension installed in your database, you can use the `hnsw` and `ivfflat` options, which are predefined types.
  73. *
  74. * **You can always specify any string you want in the method, in case Drizzle doesn't have it natively in its types**
  75. *
  76. * @param method The name of the index method to be used
  77. * @param columns
  78. * @returns
  79. */
  80. using(method, ...columns) {
  81. return new IndexBuilder(
  82. columns.map((it) => {
  83. if ((0, import_entity.is)(it, import_sql.SQL)) {
  84. return it;
  85. }
  86. it = it;
  87. const clonedIndexedColumn = new import_columns.IndexedColumn(it.name, !!it.keyAsName, it.columnType, it.indexConfig);
  88. it.indexConfig = JSON.parse(JSON.stringify(it.defaultConfig));
  89. return clonedIndexedColumn;
  90. }),
  91. this.unique,
  92. true,
  93. this.name,
  94. method
  95. );
  96. }
  97. }
  98. class IndexBuilder {
  99. static [import_entity.entityKind] = "GelIndexBuilder";
  100. /** @internal */
  101. config;
  102. constructor(columns, unique, only, name, method = "btree") {
  103. this.config = {
  104. name,
  105. columns,
  106. unique,
  107. only,
  108. method
  109. };
  110. }
  111. concurrently() {
  112. this.config.concurrently = true;
  113. return this;
  114. }
  115. with(obj) {
  116. this.config.with = obj;
  117. return this;
  118. }
  119. where(condition) {
  120. this.config.where = condition;
  121. return this;
  122. }
  123. /** @internal */
  124. build(table) {
  125. return new Index(this.config, table);
  126. }
  127. }
  128. class Index {
  129. static [import_entity.entityKind] = "GelIndex";
  130. config;
  131. constructor(config, table) {
  132. this.config = { ...config, table };
  133. }
  134. }
  135. function index(name) {
  136. return new IndexBuilderOn(false, name);
  137. }
  138. function uniqueIndex(name) {
  139. return new IndexBuilderOn(true, name);
  140. }
  141. // Annotate the CommonJS export names for ESM import in node:
  142. 0 && (module.exports = {
  143. Index,
  144. IndexBuilder,
  145. IndexBuilderOn,
  146. index,
  147. uniqueIndex
  148. });
  149. //# sourceMappingURL=indexes.cjs.map