drizzle-kit 0.29.0-3f3eb73 → 0.29.0-7c72529

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/api.js +318 -224
  2. package/api.mjs +318 -224
  3. package/bin.cjs +11 -20
  4. package/package.json +1 -1
package/api.js CHANGED
@@ -12331,7 +12331,7 @@ var init_sqlgenerator = __esm({
12331
12331
  const { tableName, schema: schema5, columns, compositePKs, uniqueConstraints, checkConstraints, policies, isRLSEnabled } = st;
12332
12332
  let statement = "";
12333
12333
  const name2 = schema5 ? `"${schema5}"."${tableName}"` : `"${tableName}"`;
12334
- statement += `CREATE TABLE IF NOT EXISTS ${name2} (
12334
+ statement += `CREATE TABLE ${name2} (
12335
12335
  `;
12336
12336
  for (let i = 0; i < columns.length; i++) {
12337
12337
  const column5 = columns[i];
@@ -13169,7 +13169,7 @@ WITH ${withCheckOption} CHECK OPTION` : "";
13169
13169
  convert(statement) {
13170
13170
  const { tableName, columnName, schema: schema5 } = statement;
13171
13171
  const tableNameWithSchema = schema5 ? `"${schema5}"."${tableName}"` : `"${tableName}"`;
13172
- return `ALTER TABLE ${tableNameWithSchema} DROP COLUMN IF EXISTS "${columnName}";`;
13172
+ return `ALTER TABLE ${tableNameWithSchema} DROP COLUMN "${columnName}";`;
13173
13173
  }
13174
13174
  };
13175
13175
  MySqlAlterTableDropColumnConvertor = class extends Convertor {
@@ -13590,7 +13590,7 @@ WITH ${withCheckOption} CHECK OPTION` : "";
13590
13590
  for (const table5 of Object.values(json22.tables)) {
13591
13591
  for (const index5 of Object.values(table5.indexes)) {
13592
13592
  const unsquashed = SQLiteSquasher.unsquashIdx(index5);
13593
- sqlStatements.push(`DROP INDEX IF EXISTS "${unsquashed.name}";`);
13593
+ sqlStatements.push(`DROP INDEX "${unsquashed.name}";`);
13594
13594
  indexes.push({ ...unsquashed, tableName: table5.name });
13595
13595
  }
13596
13596
  }
@@ -14104,13 +14104,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${statement.newC
14104
14104
  const toColumnsString = columnsTo.map((it) => `"${it}"`).join(",");
14105
14105
  const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${tableFrom}"` : `"${tableFrom}"`;
14106
14106
  const tableToNameWithSchema = schemaTo ? `"${schemaTo}"."${tableTo}"` : `"${tableTo}"`;
14107
- const alterStatement = `ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${name2}" FOREIGN KEY (${fromColumnsString}) REFERENCES ${tableToNameWithSchema}(${toColumnsString})${onDeleteStatement}${onUpdateStatement}`;
14108
- let sql2 = "DO $$ BEGIN\n";
14109
- sql2 += " " + alterStatement + ";\n";
14110
- sql2 += "EXCEPTION\n";
14111
- sql2 += " WHEN duplicate_object THEN null;\n";
14112
- sql2 += "END $$;\n";
14113
- return sql2;
14107
+ const alterStatement = `ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${name2}" FOREIGN KEY (${fromColumnsString}) REFERENCES ${tableToNameWithSchema}(${toColumnsString})${onDeleteStatement}${onUpdateStatement};`;
14108
+ return alterStatement;
14114
14109
  }
14115
14110
  };
14116
14111
  LibSQLCreateForeignKeyConvertor = class extends Convertor {
@@ -14167,12 +14162,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${statement.newC
14167
14162
  const toColumnsString = newFk.columnsTo.map((it) => `"${it}"`).join(",");
14168
14163
  const tableFromNameWithSchema = oldFk.schemaTo ? `"${oldFk.schemaTo}"."${oldFk.tableFrom}"` : `"${oldFk.tableFrom}"`;
14169
14164
  const tableToNameWithSchema = newFk.schemaTo ? `"${newFk.schemaTo}"."${newFk.tableFrom}"` : `"${newFk.tableFrom}"`;
14170
- const alterStatement = `ALTER TABLE ${tableFromNameWithSchema} ADD CONSTRAINT "${newFk.name}" FOREIGN KEY (${fromColumnsString}) REFERENCES ${tableToNameWithSchema}(${toColumnsString})${onDeleteStatement}${onUpdateStatement}`;
14171
- sql2 += "DO $$ BEGIN\n";
14172
- sql2 += " " + alterStatement + ";\n";
14173
- sql2 += "EXCEPTION\n";
14174
- sql2 += " WHEN duplicate_object THEN null;\n";
14175
- sql2 += "END $$;\n";
14165
+ const alterStatement = `ALTER TABLE ${tableFromNameWithSchema} ADD CONSTRAINT "${newFk.name}" FOREIGN KEY (${fromColumnsString}) REFERENCES ${tableToNameWithSchema}(${toColumnsString})${onDeleteStatement}${onUpdateStatement};`;
14166
+ sql2 += alterStatement;
14176
14167
  return sql2;
14177
14168
  }
14178
14169
  };
@@ -14228,7 +14219,7 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${statement.newC
14228
14219
  reversedString = reversedString.slice(0, -1);
14229
14220
  return reversedString;
14230
14221
  }
14231
- return `CREATE ${indexPart}${concurrently ? " CONCURRENTLY" : ""} IF NOT EXISTS "${name2}" ON ${tableNameWithSchema} USING ${method} (${value})${Object.keys(withMap).length !== 0 ? ` WITH (${reverseLogic(withMap)})` : ""}${where ? ` WHERE ${where}` : ""};`;
14222
+ return `CREATE ${indexPart}${concurrently ? " CONCURRENTLY" : ""} "${name2}" ON ${tableNameWithSchema} USING ${method} (${value})${Object.keys(withMap).length !== 0 ? ` WITH (${reverseLogic(withMap)})` : ""}${where ? ` WHERE ${where}` : ""};`;
14232
14223
  }
14233
14224
  };
14234
14225
  CreateMySqlIndexConvertor = class extends Convertor {
@@ -14283,7 +14274,7 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${statement.newC
14283
14274
  }
14284
14275
  convert(statement) {
14285
14276
  const { name: name2 } = PgSquasher.unsquashIdx(statement.data);
14286
- return `DROP INDEX IF EXISTS "${name2}";`;
14277
+ return `DROP INDEX "${name2}";`;
14287
14278
  }
14288
14279
  };
14289
14280
  PgCreateSchemaConvertor = class extends Convertor {
@@ -14354,7 +14345,7 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${statement.newC
14354
14345
  }
14355
14346
  convert(statement) {
14356
14347
  const { name: name2 } = PgSquasher.unsquashIdx(statement.data);
14357
- return `DROP INDEX IF EXISTS \`${name2}\`;`;
14348
+ return `DROP INDEX \`${name2}\`;`;
14358
14349
  }
14359
14350
  };
14360
14351
  MySqlDropIndexConvertor = class extends Convertor {
@@ -37129,6 +37120,12 @@ var init_dialect3 = __esm({
37129
37120
  buildOrderBy(orderBy) {
37130
37121
  return orderBy && orderBy.length > 0 ? sql` order by ${sql.join(orderBy, sql`, `)}` : void 0;
37131
37122
  }
37123
+ buildIndex({
37124
+ indexes,
37125
+ indexFor
37126
+ }) {
37127
+ return indexes && indexes.length > 0 ? sql` ${sql.raw(indexFor)} INDEX (${sql.raw(indexes.join(`, `))})` : void 0;
37128
+ }
37132
37129
  buildSelectQuery({
37133
37130
  withList,
37134
37131
  fields,
@@ -37143,7 +37140,10 @@ var init_dialect3 = __esm({
37143
37140
  offset,
37144
37141
  lockingClause,
37145
37142
  distinct,
37146
- setOperators
37143
+ setOperators,
37144
+ useIndex,
37145
+ forceIndex,
37146
+ ignoreIndex
37147
37147
  }) {
37148
37148
  const fieldsList = fieldsFlat ?? orderSelectedFields(fields);
37149
37149
  for (const f of fieldsList) {
@@ -37179,8 +37179,11 @@ var init_dialect3 = __esm({
37179
37179
  const tableSchema = table22[MySqlTable.Symbol.Schema];
37180
37180
  const origTableName = table22[MySqlTable.Symbol.OriginalName];
37181
37181
  const alias = tableName === origTableName ? void 0 : joinMeta.alias;
37182
+ const useIndexSql2 = this.buildIndex({ indexes: joinMeta.useIndex, indexFor: "USE" });
37183
+ const forceIndexSql2 = this.buildIndex({ indexes: joinMeta.forceIndex, indexFor: "FORCE" });
37184
+ const ignoreIndexSql2 = this.buildIndex({ indexes: joinMeta.ignoreIndex, indexFor: "IGNORE" });
37182
37185
  joinsArray.push(
37183
- sql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`} on ${joinMeta.on}`
37186
+ sql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(origTableName)}${useIndexSql2}${forceIndexSql2}${ignoreIndexSql2}${alias && sql` ${sql.identifier(alias)}`} on ${joinMeta.on}`
37184
37187
  );
37185
37188
  } else if (is(table22, View3)) {
37186
37189
  const viewName = table22[ViewBaseConfig].name;
@@ -37207,6 +37210,9 @@ var init_dialect3 = __esm({
37207
37210
  const groupBySql = groupBy && groupBy.length > 0 ? sql` group by ${sql.join(groupBy, sql`, `)}` : void 0;
37208
37211
  const limitSql = this.buildLimit(limit);
37209
37212
  const offsetSql = offset ? sql` offset ${offset}` : void 0;
37213
+ const useIndexSql = this.buildIndex({ indexes: useIndex, indexFor: "USE" });
37214
+ const forceIndexSql = this.buildIndex({ indexes: forceIndex, indexFor: "FORCE" });
37215
+ const ignoreIndexSql = this.buildIndex({ indexes: ignoreIndex, indexFor: "IGNORE" });
37210
37216
  let lockingClausesSql;
37211
37217
  if (lockingClause) {
37212
37218
  const { config, strength } = lockingClause;
@@ -37217,7 +37223,7 @@ var init_dialect3 = __esm({
37217
37223
  lockingClausesSql.append(sql` skip locked`);
37218
37224
  }
37219
37225
  }
37220
- const finalQuery = sql`${withSql}select${distinctSql} ${selection} from ${tableSql}${joinsSql}${whereSql}${groupBySql}${havingSql}${orderBySql}${limitSql}${offsetSql}${lockingClausesSql}`;
37226
+ const finalQuery = sql`${withSql}select${distinctSql} ${selection} from ${tableSql}${useIndexSql}${forceIndexSql}${ignoreIndexSql}${joinsSql}${whereSql}${groupBySql}${havingSql}${orderBySql}${limitSql}${offsetSql}${lockingClausesSql}`;
37221
37227
  if (setOperators.length > 0) {
37222
37228
  return this.buildSetOperations(finalQuery, setOperators);
37223
37229
  }
@@ -37785,6 +37791,186 @@ var init_dialect3 = __esm({
37785
37791
  }
37786
37792
  });
37787
37793
 
37794
+ // ../drizzle-orm/dist/mysql-core/indexes.js
37795
+ var _a302, IndexBuilderOn3, _a303, IndexBuilder3, _a304, Index5;
37796
+ var init_indexes3 = __esm({
37797
+ "../drizzle-orm/dist/mysql-core/indexes.js"() {
37798
+ "use strict";
37799
+ init_entity();
37800
+ _a302 = entityKind;
37801
+ IndexBuilderOn3 = class {
37802
+ constructor(name2, unique) {
37803
+ this.name = name2;
37804
+ this.unique = unique;
37805
+ }
37806
+ on(...columns) {
37807
+ return new IndexBuilder3(this.name, columns, this.unique);
37808
+ }
37809
+ };
37810
+ __publicField(IndexBuilderOn3, _a302, "MySqlIndexBuilderOn");
37811
+ _a303 = entityKind;
37812
+ IndexBuilder3 = class {
37813
+ constructor(name2, columns, unique) {
37814
+ /** @internal */
37815
+ __publicField(this, "config");
37816
+ this.config = {
37817
+ name: name2,
37818
+ columns,
37819
+ unique
37820
+ };
37821
+ }
37822
+ using(using) {
37823
+ this.config.using = using;
37824
+ return this;
37825
+ }
37826
+ algorythm(algorythm) {
37827
+ this.config.algorythm = algorythm;
37828
+ return this;
37829
+ }
37830
+ lock(lock) {
37831
+ this.config.lock = lock;
37832
+ return this;
37833
+ }
37834
+ /** @internal */
37835
+ build(table5) {
37836
+ return new Index5(this.config, table5);
37837
+ }
37838
+ };
37839
+ __publicField(IndexBuilder3, _a303, "MySqlIndexBuilder");
37840
+ _a304 = entityKind;
37841
+ Index5 = class {
37842
+ constructor(config, table5) {
37843
+ __publicField(this, "config");
37844
+ this.config = { ...config, table: table5 };
37845
+ }
37846
+ };
37847
+ __publicField(Index5, _a304, "MySqlIndex");
37848
+ }
37849
+ });
37850
+
37851
+ // ../drizzle-orm/dist/mysql-core/primary-keys.js
37852
+ var _a305, PrimaryKeyBuilder3, _a306, PrimaryKey3;
37853
+ var init_primary_keys3 = __esm({
37854
+ "../drizzle-orm/dist/mysql-core/primary-keys.js"() {
37855
+ "use strict";
37856
+ init_entity();
37857
+ init_table4();
37858
+ _a305 = entityKind;
37859
+ PrimaryKeyBuilder3 = class {
37860
+ constructor(columns, name2) {
37861
+ /** @internal */
37862
+ __publicField(this, "columns");
37863
+ /** @internal */
37864
+ __publicField(this, "name");
37865
+ this.columns = columns;
37866
+ this.name = name2;
37867
+ }
37868
+ /** @internal */
37869
+ build(table5) {
37870
+ return new PrimaryKey3(table5, this.columns, this.name);
37871
+ }
37872
+ };
37873
+ __publicField(PrimaryKeyBuilder3, _a305, "MySqlPrimaryKeyBuilder");
37874
+ _a306 = entityKind;
37875
+ PrimaryKey3 = class {
37876
+ constructor(table5, columns, name2) {
37877
+ __publicField(this, "columns");
37878
+ __publicField(this, "name");
37879
+ this.table = table5;
37880
+ this.columns = columns;
37881
+ this.name = name2;
37882
+ }
37883
+ getName() {
37884
+ return this.name ?? `${this.table[MySqlTable.Symbol.Name]}_${this.columns.map((column5) => column5.name).join("_")}_pk`;
37885
+ }
37886
+ };
37887
+ __publicField(PrimaryKey3, _a306, "MySqlPrimaryKey");
37888
+ }
37889
+ });
37890
+
37891
+ // ../drizzle-orm/dist/mysql-core/view-common.js
37892
+ var MySqlViewConfig;
37893
+ var init_view_common3 = __esm({
37894
+ "../drizzle-orm/dist/mysql-core/view-common.js"() {
37895
+ "use strict";
37896
+ MySqlViewConfig = Symbol.for("drizzle:MySqlViewConfig");
37897
+ }
37898
+ });
37899
+
37900
+ // ../drizzle-orm/dist/mysql-core/utils.js
37901
+ function getTableConfig3(table5) {
37902
+ const columns = Object.values(table5[MySqlTable.Symbol.Columns]);
37903
+ const indexes = [];
37904
+ const checks = [];
37905
+ const primaryKeys = [];
37906
+ const uniqueConstraints = [];
37907
+ const foreignKeys = Object.values(table5[MySqlTable.Symbol.InlineForeignKeys]);
37908
+ const name2 = table5[Table2.Symbol.Name];
37909
+ const schema5 = table5[Table2.Symbol.Schema];
37910
+ const baseName = table5[Table2.Symbol.BaseName];
37911
+ const extraConfigBuilder = table5[MySqlTable.Symbol.ExtraConfigBuilder];
37912
+ if (extraConfigBuilder !== void 0) {
37913
+ const extraConfig = extraConfigBuilder(table5[MySqlTable.Symbol.Columns]);
37914
+ for (const builder of Object.values(extraConfig)) {
37915
+ if (is(builder, IndexBuilder3)) {
37916
+ indexes.push(builder.build(table5));
37917
+ } else if (is(builder, CheckBuilder3)) {
37918
+ checks.push(builder.build(table5));
37919
+ } else if (is(builder, UniqueConstraintBuilder3)) {
37920
+ uniqueConstraints.push(builder.build(table5));
37921
+ } else if (is(builder, PrimaryKeyBuilder3)) {
37922
+ primaryKeys.push(builder.build(table5));
37923
+ } else if (is(builder, ForeignKeyBuilder3)) {
37924
+ foreignKeys.push(builder.build(table5));
37925
+ }
37926
+ }
37927
+ }
37928
+ return {
37929
+ columns,
37930
+ indexes,
37931
+ foreignKeys,
37932
+ checks,
37933
+ primaryKeys,
37934
+ uniqueConstraints,
37935
+ name: name2,
37936
+ schema: schema5,
37937
+ baseName
37938
+ };
37939
+ }
37940
+ function getViewConfig3(view4) {
37941
+ return {
37942
+ ...view4[ViewBaseConfig],
37943
+ ...view4[MySqlViewConfig]
37944
+ };
37945
+ }
37946
+ function convertIndexToString({
37947
+ table: table5,
37948
+ indexes
37949
+ }) {
37950
+ return indexes.map((idx) => {
37951
+ if (typeof idx === "object") {
37952
+ return is(idx, UniqueConstraintBuilder3) ? idx.build(table5).getName() : idx.config.name;
37953
+ } else {
37954
+ return idx;
37955
+ }
37956
+ });
37957
+ }
37958
+ var init_utils8 = __esm({
37959
+ "../drizzle-orm/dist/mysql-core/utils.js"() {
37960
+ "use strict";
37961
+ init_entity();
37962
+ init_table();
37963
+ init_view_common();
37964
+ init_checks3();
37965
+ init_foreign_keys3();
37966
+ init_indexes3();
37967
+ init_primary_keys3();
37968
+ init_table4();
37969
+ init_unique_constraint3();
37970
+ init_view_common3();
37971
+ }
37972
+ });
37973
+
37788
37974
  // ../drizzle-orm/dist/mysql-core/query-builders/select.js
37789
37975
  function createSetOperator3(type, isAll) {
37790
37976
  return (leftSelect, rightSelect, ...restSelects) => {
@@ -37803,11 +37989,12 @@ function createSetOperator3(type, isAll) {
37803
37989
  return leftSelect.addSetOperators(setOperators);
37804
37990
  };
37805
37991
  }
37806
- var _a302, MySqlSelectBuilder, _a303, _b224, MySqlSelectQueryBuilderBase, _a304, _b225, MySqlSelectBase, getMySqlSetOperators, union3, unionAll3, intersect3, intersectAll2, except3, exceptAll2;
37992
+ var _a307, MySqlSelectBuilder, _a308, _b224, MySqlSelectQueryBuilderBase, _a309, _b225, MySqlSelectBase, getMySqlSetOperators, union3, unionAll3, intersect3, intersectAll2, except3, exceptAll2;
37807
37993
  var init_select4 = __esm({
37808
37994
  "../drizzle-orm/dist/mysql-core/query-builders/select.js"() {
37809
37995
  "use strict";
37810
37996
  init_entity();
37997
+ init_table4();
37811
37998
  init_query_builder();
37812
37999
  init_query_promise();
37813
38000
  init_selection_proxy();
@@ -37817,8 +38004,9 @@ var init_select4 = __esm({
37817
38004
  init_utils2();
37818
38005
  init_utils2();
37819
38006
  init_view_common();
38007
+ init_utils8();
37820
38008
  init_view_base3();
37821
- _a302 = entityKind;
38009
+ _a307 = entityKind;
37822
38010
  MySqlSelectBuilder = class {
37823
38011
  constructor(config) {
37824
38012
  __publicField(this, "fields");
@@ -37834,7 +38022,7 @@ var init_select4 = __esm({
37834
38022
  }
37835
38023
  this.distinct = config.distinct;
37836
38024
  }
37837
- from(source) {
38025
+ from(source, onIndex) {
37838
38026
  const isPartialSelect = !!this.fields;
37839
38027
  let fields;
37840
38028
  if (this.fields) {
@@ -37850,6 +38038,20 @@ var init_select4 = __esm({
37850
38038
  } else {
37851
38039
  fields = getTableColumns(source);
37852
38040
  }
38041
+ let useIndex = [];
38042
+ let forceIndex = [];
38043
+ let ignoreIndex = [];
38044
+ if (is(source, MySqlTable) && onIndex) {
38045
+ if (onIndex.useIndex) {
38046
+ useIndex = convertIndexToString({ table: source, indexes: onIndex.useIndex });
38047
+ }
38048
+ if (onIndex.forceIndex) {
38049
+ forceIndex = convertIndexToString({ table: source, indexes: onIndex.forceIndex });
38050
+ }
38051
+ if (onIndex.ignoreIndex) {
38052
+ ignoreIndex = convertIndexToString({ table: source, indexes: onIndex.ignoreIndex });
38053
+ }
38054
+ }
37853
38055
  return new MySqlSelectBase(
37854
38056
  {
37855
38057
  table: source,
@@ -37858,14 +38060,17 @@ var init_select4 = __esm({
37858
38060
  session: this.session,
37859
38061
  dialect: this.dialect,
37860
38062
  withList: this.withList,
37861
- distinct: this.distinct
38063
+ distinct: this.distinct,
38064
+ useIndex,
38065
+ forceIndex,
38066
+ ignoreIndex
37862
38067
  }
37863
38068
  );
37864
38069
  }
37865
38070
  };
37866
- __publicField(MySqlSelectBuilder, _a302, "MySqlSelectBuilder");
37867
- MySqlSelectQueryBuilderBase = class extends (_b224 = TypedQueryBuilder, _a303 = entityKind, _b224) {
37868
- constructor({ table: table5, fields, isPartialSelect, session, dialect: dialect6, withList, distinct }) {
38071
+ __publicField(MySqlSelectBuilder, _a307, "MySqlSelectBuilder");
38072
+ MySqlSelectQueryBuilderBase = class extends (_b224 = TypedQueryBuilder, _a308 = entityKind, _b224) {
38073
+ constructor({ table: table5, fields, isPartialSelect, session, dialect: dialect6, withList, distinct, useIndex, forceIndex, ignoreIndex }) {
37869
38074
  super();
37870
38075
  __publicField(this, "_");
37871
38076
  __publicField(this, "config");
@@ -37900,6 +38105,16 @@ var init_select4 = __esm({
37900
38105
  * })
37901
38106
  * .from(users)
37902
38107
  * .leftJoin(pets, eq(users.id, pets.ownerId))
38108
+ *
38109
+ * // Select userId and petId with use index hint
38110
+ * const usersIdsAndPetIds: { userId: number; petId: number | null }[] = await db.select({
38111
+ * userId: users.id,
38112
+ * petId: pets.id,
38113
+ * })
38114
+ * .from(users)
38115
+ * .leftJoin(pets, eq(users.id, pets.ownerId), {
38116
+ * useIndex: ['pets_owner_id_index']
38117
+ * })
37903
38118
  * ```
37904
38119
  */
37905
38120
  __publicField(this, "leftJoin", this.createJoin("left"));
@@ -37928,6 +38143,16 @@ var init_select4 = __esm({
37928
38143
  * })
37929
38144
  * .from(users)
37930
38145
  * .rightJoin(pets, eq(users.id, pets.ownerId))
38146
+ *
38147
+ * // Select userId and petId with use index hint
38148
+ * const usersIdsAndPetIds: { userId: number; petId: number | null }[] = await db.select({
38149
+ * userId: users.id,
38150
+ * petId: pets.id,
38151
+ * })
38152
+ * .from(users)
38153
+ * .leftJoin(pets, eq(users.id, pets.ownerId), {
38154
+ * useIndex: ['pets_owner_id_index']
38155
+ * })
37931
38156
  * ```
37932
38157
  */
37933
38158
  __publicField(this, "rightJoin", this.createJoin("right"));
@@ -37956,6 +38181,16 @@ var init_select4 = __esm({
37956
38181
  * })
37957
38182
  * .from(users)
37958
38183
  * .innerJoin(pets, eq(users.id, pets.ownerId))
38184
+ *
38185
+ * // Select userId and petId with use index hint
38186
+ * const usersIdsAndPetIds: { userId: number; petId: number | null }[] = await db.select({
38187
+ * userId: users.id,
38188
+ * petId: pets.id,
38189
+ * })
38190
+ * .from(users)
38191
+ * .leftJoin(pets, eq(users.id, pets.ownerId), {
38192
+ * useIndex: ['pets_owner_id_index']
38193
+ * })
37959
38194
  * ```
37960
38195
  */
37961
38196
  __publicField(this, "innerJoin", this.createJoin("inner"));
@@ -37984,6 +38219,16 @@ var init_select4 = __esm({
37984
38219
  * })
37985
38220
  * .from(users)
37986
38221
  * .fullJoin(pets, eq(users.id, pets.ownerId))
38222
+ *
38223
+ * // Select userId and petId with use index hint
38224
+ * const usersIdsAndPetIds: { userId: number; petId: number | null }[] = await db.select({
38225
+ * userId: users.id,
38226
+ * petId: pets.id,
38227
+ * })
38228
+ * .from(users)
38229
+ * .leftJoin(pets, eq(users.id, pets.ownerId), {
38230
+ * useIndex: ['pets_owner_id_index']
38231
+ * })
37987
38232
  * ```
37988
38233
  */
37989
38234
  __publicField(this, "fullJoin", this.createJoin("full"));
@@ -38178,7 +38423,10 @@ var init_select4 = __esm({
38178
38423
  table: table5,
38179
38424
  fields: { ...fields },
38180
38425
  distinct,
38181
- setOperators: []
38426
+ setOperators: [],
38427
+ useIndex,
38428
+ forceIndex,
38429
+ ignoreIndex
38182
38430
  };
38183
38431
  this.isPartialSelect = isPartialSelect;
38184
38432
  this.session = session;
@@ -38190,7 +38438,7 @@ var init_select4 = __esm({
38190
38438
  this.joinsNotNullableMap = typeof this.tableName === "string" ? { [this.tableName]: true } : {};
38191
38439
  }
38192
38440
  createJoin(joinType) {
38193
- return (table5, on) => {
38441
+ return (table5, on, onIndex) => {
38194
38442
  const baseTableName = this.tableName;
38195
38443
  const tableName = getTableLikeName(table5);
38196
38444
  if (typeof tableName === "string" && this.config.joins?.some((join) => join.alias === tableName)) {
@@ -38218,7 +38466,21 @@ var init_select4 = __esm({
38218
38466
  if (!this.config.joins) {
38219
38467
  this.config.joins = [];
38220
38468
  }
38221
- this.config.joins.push({ on, table: table5, joinType, alias: tableName });
38469
+ let useIndex = [];
38470
+ let forceIndex = [];
38471
+ let ignoreIndex = [];
38472
+ if (is(table5, MySqlTable) && onIndex) {
38473
+ if (onIndex.useIndex) {
38474
+ useIndex = convertIndexToString({ table: table5, indexes: onIndex.useIndex });
38475
+ }
38476
+ if (onIndex.forceIndex) {
38477
+ forceIndex = convertIndexToString({ table: table5, indexes: onIndex.forceIndex });
38478
+ }
38479
+ if (onIndex.ignoreIndex) {
38480
+ ignoreIndex = convertIndexToString({ table: table5, indexes: onIndex.ignoreIndex });
38481
+ }
38482
+ }
38483
+ this.config.joins.push({ on, table: table5, joinType, alias: tableName, useIndex, forceIndex, ignoreIndex });
38222
38484
  if (typeof tableName === "string") {
38223
38485
  switch (joinType) {
38224
38486
  case "left": {
@@ -38465,8 +38727,8 @@ var init_select4 = __esm({
38465
38727
  return this;
38466
38728
  }
38467
38729
  };
38468
- __publicField(MySqlSelectQueryBuilderBase, _a303, "MySqlSelectQueryBuilder");
38469
- MySqlSelectBase = class extends (_b225 = MySqlSelectQueryBuilderBase, _a304 = entityKind, _b225) {
38730
+ __publicField(MySqlSelectQueryBuilderBase, _a308, "MySqlSelectQueryBuilder");
38731
+ MySqlSelectBase = class extends (_b225 = MySqlSelectQueryBuilderBase, _a309 = entityKind, _b225) {
38470
38732
  constructor() {
38471
38733
  super(...arguments);
38472
38734
  __publicField(this, "execute", (placeholderValues) => {
@@ -38490,7 +38752,7 @@ var init_select4 = __esm({
38490
38752
  return query;
38491
38753
  }
38492
38754
  };
38493
- __publicField(MySqlSelectBase, _a304, "MySqlSelect");
38755
+ __publicField(MySqlSelectBase, _a309, "MySqlSelect");
38494
38756
  applyMixins(MySqlSelectBase, [QueryPromise]);
38495
38757
  getMySqlSetOperators = () => ({
38496
38758
  union: union3,
@@ -38510,7 +38772,7 @@ var init_select4 = __esm({
38510
38772
  });
38511
38773
 
38512
38774
  // ../drizzle-orm/dist/mysql-core/query-builders/query-builder.js
38513
- var _a305, QueryBuilder3;
38775
+ var _a310, QueryBuilder3;
38514
38776
  var init_query_builder4 = __esm({
38515
38777
  "../drizzle-orm/dist/mysql-core/query-builders/query-builder.js"() {
38516
38778
  "use strict";
@@ -38519,7 +38781,7 @@ var init_query_builder4 = __esm({
38519
38781
  init_selection_proxy();
38520
38782
  init_subquery();
38521
38783
  init_select4();
38522
- _a305 = entityKind;
38784
+ _a310 = entityKind;
38523
38785
  QueryBuilder3 = class {
38524
38786
  constructor(dialect6) {
38525
38787
  __publicField(this, "dialect");
@@ -38581,12 +38843,12 @@ var init_query_builder4 = __esm({
38581
38843
  return this.dialect;
38582
38844
  }
38583
38845
  };
38584
- __publicField(QueryBuilder3, _a305, "MySqlQueryBuilder");
38846
+ __publicField(QueryBuilder3, _a310, "MySqlQueryBuilder");
38585
38847
  }
38586
38848
  });
38587
38849
 
38588
38850
  // ../drizzle-orm/dist/mysql-core/query-builders/insert.js
38589
- var _a306, MySqlInsertBuilder, _a307, _b226, MySqlInsertBase;
38851
+ var _a311, MySqlInsertBuilder, _a312, _b226, MySqlInsertBase;
38590
38852
  var init_insert3 = __esm({
38591
38853
  "../drizzle-orm/dist/mysql-core/query-builders/insert.js"() {
38592
38854
  "use strict";
@@ -38596,7 +38858,7 @@ var init_insert3 = __esm({
38596
38858
  init_table();
38597
38859
  init_utils2();
38598
38860
  init_query_builder4();
38599
- _a306 = entityKind;
38861
+ _a311 = entityKind;
38600
38862
  MySqlInsertBuilder = class {
38601
38863
  constructor(table5, session, dialect6) {
38602
38864
  __publicField(this, "shouldIgnore", false);
@@ -38634,8 +38896,8 @@ var init_insert3 = __esm({
38634
38896
  return new MySqlInsertBase(this.table, select, this.shouldIgnore, this.session, this.dialect, true);
38635
38897
  }
38636
38898
  };
38637
- __publicField(MySqlInsertBuilder, _a306, "MySqlInsertBuilder");
38638
- MySqlInsertBase = class extends (_b226 = QueryPromise, _a307 = entityKind, _b226) {
38899
+ __publicField(MySqlInsertBuilder, _a311, "MySqlInsertBuilder");
38900
+ MySqlInsertBase = class extends (_b226 = QueryPromise, _a312 = entityKind, _b226) {
38639
38901
  constructor(table5, values, ignore, session, dialect6, select) {
38640
38902
  super();
38641
38903
  __publicField(this, "config");
@@ -38716,7 +38978,7 @@ var init_insert3 = __esm({
38716
38978
  return this;
38717
38979
  }
38718
38980
  };
38719
- __publicField(MySqlInsertBase, _a307, "MySqlInsert");
38981
+ __publicField(MySqlInsertBase, _a312, "MySqlInsert");
38720
38982
  }
38721
38983
  });
38722
38984
 
@@ -38728,7 +38990,7 @@ var init_select_types3 = __esm({
38728
38990
  });
38729
38991
 
38730
38992
  // ../drizzle-orm/dist/mysql-core/query-builders/update.js
38731
- var _a308, MySqlUpdateBuilder, _a309, _b227, MySqlUpdateBase;
38993
+ var _a313, MySqlUpdateBuilder, _a314, _b227, MySqlUpdateBase;
38732
38994
  var init_update3 = __esm({
38733
38995
  "../drizzle-orm/dist/mysql-core/query-builders/update.js"() {
38734
38996
  "use strict";
@@ -38737,7 +38999,7 @@ var init_update3 = __esm({
38737
38999
  init_selection_proxy();
38738
39000
  init_table();
38739
39001
  init_utils2();
38740
- _a308 = entityKind;
39002
+ _a313 = entityKind;
38741
39003
  MySqlUpdateBuilder = class {
38742
39004
  constructor(table5, session, dialect6, withList) {
38743
39005
  this.table = table5;
@@ -38749,8 +39011,8 @@ var init_update3 = __esm({
38749
39011
  return new MySqlUpdateBase(this.table, mapUpdateSet(this.table, values), this.session, this.dialect, this.withList);
38750
39012
  }
38751
39013
  };
38752
- __publicField(MySqlUpdateBuilder, _a308, "MySqlUpdateBuilder");
38753
- MySqlUpdateBase = class extends (_b227 = QueryPromise, _a309 = entityKind, _b227) {
39014
+ __publicField(MySqlUpdateBuilder, _a313, "MySqlUpdateBuilder");
39015
+ MySqlUpdateBase = class extends (_b227 = QueryPromise, _a314 = entityKind, _b227) {
38754
39016
  constructor(table5, set, session, dialect6, withList) {
38755
39017
  super();
38756
39018
  __publicField(this, "config");
@@ -38843,7 +39105,7 @@ var init_update3 = __esm({
38843
39105
  return this;
38844
39106
  }
38845
39107
  };
38846
- __publicField(MySqlUpdateBase, _a309, "MySqlUpdate");
39108
+ __publicField(MySqlUpdateBase, _a314, "MySqlUpdate");
38847
39109
  }
38848
39110
  });
38849
39111
 
@@ -38861,14 +39123,14 @@ var init_query_builders3 = __esm({
38861
39123
  });
38862
39124
 
38863
39125
  // ../drizzle-orm/dist/mysql-core/query-builders/query.js
38864
- var _a310, RelationalQueryBuilder3, _a311, _b228, MySqlRelationalQuery;
39126
+ var _a315, RelationalQueryBuilder3, _a316, _b228, MySqlRelationalQuery;
38865
39127
  var init_query3 = __esm({
38866
39128
  "../drizzle-orm/dist/mysql-core/query-builders/query.js"() {
38867
39129
  "use strict";
38868
39130
  init_entity();
38869
39131
  init_query_promise();
38870
39132
  init_relations();
38871
- _a310 = entityKind;
39133
+ _a315 = entityKind;
38872
39134
  RelationalQueryBuilder3 = class {
38873
39135
  constructor(fullSchema, schema5, tableNamesMap, table5, tableConfig, dialect6, session, mode) {
38874
39136
  this.fullSchema = fullSchema;
@@ -38909,8 +39171,8 @@ var init_query3 = __esm({
38909
39171
  );
38910
39172
  }
38911
39173
  };
38912
- __publicField(RelationalQueryBuilder3, _a310, "MySqlRelationalQueryBuilder");
38913
- MySqlRelationalQuery = class extends (_b228 = QueryPromise, _a311 = entityKind, _b228) {
39174
+ __publicField(RelationalQueryBuilder3, _a315, "MySqlRelationalQueryBuilder");
39175
+ MySqlRelationalQuery = class extends (_b228 = QueryPromise, _a316 = entityKind, _b228) {
38914
39176
  constructor(fullSchema, schema5, tableNamesMap, table5, tableConfig, dialect6, session, config, queryMode, mode) {
38915
39177
  super();
38916
39178
  this.fullSchema = fullSchema;
@@ -38974,12 +39236,12 @@ var init_query3 = __esm({
38974
39236
  return this.prepare().execute();
38975
39237
  }
38976
39238
  };
38977
- __publicField(MySqlRelationalQuery, _a311, "MySqlRelationalQuery");
39239
+ __publicField(MySqlRelationalQuery, _a316, "MySqlRelationalQuery");
38978
39240
  }
38979
39241
  });
38980
39242
 
38981
39243
  // ../drizzle-orm/dist/mysql-core/db.js
38982
- var _a312, MySqlDatabase;
39244
+ var _a317, MySqlDatabase;
38983
39245
  var init_db3 = __esm({
38984
39246
  "../drizzle-orm/dist/mysql-core/db.js"() {
38985
39247
  "use strict";
@@ -38990,7 +39252,7 @@ var init_db3 = __esm({
38990
39252
  init_count3();
38991
39253
  init_query_builders3();
38992
39254
  init_query3();
38993
- _a312 = entityKind;
39255
+ _a317 = entityKind;
38994
39256
  MySqlDatabase = class {
38995
39257
  constructor(dialect6, session, schema5, mode) {
38996
39258
  __publicField(this, "query");
@@ -39203,113 +39465,7 @@ var init_db3 = __esm({
39203
39465
  return this.session.transaction(transaction, config);
39204
39466
  }
39205
39467
  };
39206
- __publicField(MySqlDatabase, _a312, "MySqlDatabase");
39207
- }
39208
- });
39209
-
39210
- // ../drizzle-orm/dist/mysql-core/indexes.js
39211
- var _a313, IndexBuilderOn3, _a314, IndexBuilder3, _a315, Index5;
39212
- var init_indexes3 = __esm({
39213
- "../drizzle-orm/dist/mysql-core/indexes.js"() {
39214
- "use strict";
39215
- init_entity();
39216
- _a313 = entityKind;
39217
- IndexBuilderOn3 = class {
39218
- constructor(name2, unique) {
39219
- this.name = name2;
39220
- this.unique = unique;
39221
- }
39222
- on(...columns) {
39223
- return new IndexBuilder3(this.name, columns, this.unique);
39224
- }
39225
- };
39226
- __publicField(IndexBuilderOn3, _a313, "MySqlIndexBuilderOn");
39227
- _a314 = entityKind;
39228
- IndexBuilder3 = class {
39229
- constructor(name2, columns, unique) {
39230
- /** @internal */
39231
- __publicField(this, "config");
39232
- this.config = {
39233
- name: name2,
39234
- columns,
39235
- unique
39236
- };
39237
- }
39238
- using(using) {
39239
- this.config.using = using;
39240
- return this;
39241
- }
39242
- algorythm(algorythm) {
39243
- this.config.algorythm = algorythm;
39244
- return this;
39245
- }
39246
- lock(lock) {
39247
- this.config.lock = lock;
39248
- return this;
39249
- }
39250
- /** @internal */
39251
- build(table5) {
39252
- return new Index5(this.config, table5);
39253
- }
39254
- };
39255
- __publicField(IndexBuilder3, _a314, "MySqlIndexBuilder");
39256
- _a315 = entityKind;
39257
- Index5 = class {
39258
- constructor(config, table5) {
39259
- __publicField(this, "config");
39260
- this.config = { ...config, table: table5 };
39261
- }
39262
- };
39263
- __publicField(Index5, _a315, "MySqlIndex");
39264
- }
39265
- });
39266
-
39267
- // ../drizzle-orm/dist/mysql-core/primary-keys.js
39268
- var _a316, PrimaryKeyBuilder3, _a317, PrimaryKey3;
39269
- var init_primary_keys3 = __esm({
39270
- "../drizzle-orm/dist/mysql-core/primary-keys.js"() {
39271
- "use strict";
39272
- init_entity();
39273
- init_table4();
39274
- _a316 = entityKind;
39275
- PrimaryKeyBuilder3 = class {
39276
- constructor(columns, name2) {
39277
- /** @internal */
39278
- __publicField(this, "columns");
39279
- /** @internal */
39280
- __publicField(this, "name");
39281
- this.columns = columns;
39282
- this.name = name2;
39283
- }
39284
- /** @internal */
39285
- build(table5) {
39286
- return new PrimaryKey3(table5, this.columns, this.name);
39287
- }
39288
- };
39289
- __publicField(PrimaryKeyBuilder3, _a316, "MySqlPrimaryKeyBuilder");
39290
- _a317 = entityKind;
39291
- PrimaryKey3 = class {
39292
- constructor(table5, columns, name2) {
39293
- __publicField(this, "columns");
39294
- __publicField(this, "name");
39295
- this.table = table5;
39296
- this.columns = columns;
39297
- this.name = name2;
39298
- }
39299
- getName() {
39300
- return this.name ?? `${this.table[MySqlTable.Symbol.Name]}_${this.columns.map((column5) => column5.name).join("_")}_pk`;
39301
- }
39302
- };
39303
- __publicField(PrimaryKey3, _a317, "MySqlPrimaryKey");
39304
- }
39305
- });
39306
-
39307
- // ../drizzle-orm/dist/mysql-core/view-common.js
39308
- var MySqlViewConfig;
39309
- var init_view_common3 = __esm({
39310
- "../drizzle-orm/dist/mysql-core/view-common.js"() {
39311
- "use strict";
39312
- MySqlViewConfig = Symbol.for("drizzle:MySqlViewConfig");
39468
+ __publicField(MySqlDatabase, _a317, "MySqlDatabase");
39313
39469
  }
39314
39470
  });
39315
39471
 
@@ -39534,68 +39690,6 @@ var init_subquery4 = __esm({
39534
39690
  }
39535
39691
  });
39536
39692
 
39537
- // ../drizzle-orm/dist/mysql-core/utils.js
39538
- function getTableConfig3(table5) {
39539
- const columns = Object.values(table5[MySqlTable.Symbol.Columns]);
39540
- const indexes = [];
39541
- const checks = [];
39542
- const primaryKeys = [];
39543
- const uniqueConstraints = [];
39544
- const foreignKeys = Object.values(table5[MySqlTable.Symbol.InlineForeignKeys]);
39545
- const name2 = table5[Table2.Symbol.Name];
39546
- const schema5 = table5[Table2.Symbol.Schema];
39547
- const baseName = table5[Table2.Symbol.BaseName];
39548
- const extraConfigBuilder = table5[MySqlTable.Symbol.ExtraConfigBuilder];
39549
- if (extraConfigBuilder !== void 0) {
39550
- const extraConfig = extraConfigBuilder(table5[MySqlTable.Symbol.Columns]);
39551
- for (const builder of Object.values(extraConfig)) {
39552
- if (is(builder, IndexBuilder3)) {
39553
- indexes.push(builder.build(table5));
39554
- } else if (is(builder, CheckBuilder3)) {
39555
- checks.push(builder.build(table5));
39556
- } else if (is(builder, UniqueConstraintBuilder3)) {
39557
- uniqueConstraints.push(builder.build(table5));
39558
- } else if (is(builder, PrimaryKeyBuilder3)) {
39559
- primaryKeys.push(builder.build(table5));
39560
- } else if (is(builder, ForeignKeyBuilder3)) {
39561
- foreignKeys.push(builder.build(table5));
39562
- }
39563
- }
39564
- }
39565
- return {
39566
- columns,
39567
- indexes,
39568
- foreignKeys,
39569
- checks,
39570
- primaryKeys,
39571
- uniqueConstraints,
39572
- name: name2,
39573
- schema: schema5,
39574
- baseName
39575
- };
39576
- }
39577
- function getViewConfig3(view4) {
39578
- return {
39579
- ...view4[ViewBaseConfig],
39580
- ...view4[MySqlViewConfig]
39581
- };
39582
- }
39583
- var init_utils8 = __esm({
39584
- "../drizzle-orm/dist/mysql-core/utils.js"() {
39585
- "use strict";
39586
- init_entity();
39587
- init_table();
39588
- init_view_common();
39589
- init_checks3();
39590
- init_foreign_keys3();
39591
- init_indexes3();
39592
- init_primary_keys3();
39593
- init_table4();
39594
- init_unique_constraint3();
39595
- init_view_common3();
39596
- }
39597
- });
39598
-
39599
39693
  // ../drizzle-orm/dist/mysql-core/index.js
39600
39694
  var init_mysql_core = __esm({
39601
39695
  "../drizzle-orm/dist/mysql-core/index.js"() {