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.mjs CHANGED
@@ -12336,7 +12336,7 @@ var init_sqlgenerator = __esm({
12336
12336
  const { tableName, schema: schema5, columns, compositePKs, uniqueConstraints, checkConstraints, policies, isRLSEnabled } = st;
12337
12337
  let statement = "";
12338
12338
  const name2 = schema5 ? `"${schema5}"."${tableName}"` : `"${tableName}"`;
12339
- statement += `CREATE TABLE IF NOT EXISTS ${name2} (
12339
+ statement += `CREATE TABLE ${name2} (
12340
12340
  `;
12341
12341
  for (let i = 0; i < columns.length; i++) {
12342
12342
  const column5 = columns[i];
@@ -13174,7 +13174,7 @@ WITH ${withCheckOption} CHECK OPTION` : "";
13174
13174
  convert(statement) {
13175
13175
  const { tableName, columnName, schema: schema5 } = statement;
13176
13176
  const tableNameWithSchema = schema5 ? `"${schema5}"."${tableName}"` : `"${tableName}"`;
13177
- return `ALTER TABLE ${tableNameWithSchema} DROP COLUMN IF EXISTS "${columnName}";`;
13177
+ return `ALTER TABLE ${tableNameWithSchema} DROP COLUMN "${columnName}";`;
13178
13178
  }
13179
13179
  };
13180
13180
  MySqlAlterTableDropColumnConvertor = class extends Convertor {
@@ -13595,7 +13595,7 @@ WITH ${withCheckOption} CHECK OPTION` : "";
13595
13595
  for (const table5 of Object.values(json22.tables)) {
13596
13596
  for (const index5 of Object.values(table5.indexes)) {
13597
13597
  const unsquashed = SQLiteSquasher.unsquashIdx(index5);
13598
- sqlStatements.push(`DROP INDEX IF EXISTS "${unsquashed.name}";`);
13598
+ sqlStatements.push(`DROP INDEX "${unsquashed.name}";`);
13599
13599
  indexes.push({ ...unsquashed, tableName: table5.name });
13600
13600
  }
13601
13601
  }
@@ -14109,13 +14109,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${statement.newC
14109
14109
  const toColumnsString = columnsTo.map((it) => `"${it}"`).join(",");
14110
14110
  const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${tableFrom}"` : `"${tableFrom}"`;
14111
14111
  const tableToNameWithSchema = schemaTo ? `"${schemaTo}"."${tableTo}"` : `"${tableTo}"`;
14112
- const alterStatement = `ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${name2}" FOREIGN KEY (${fromColumnsString}) REFERENCES ${tableToNameWithSchema}(${toColumnsString})${onDeleteStatement}${onUpdateStatement}`;
14113
- let sql2 = "DO $$ BEGIN\n";
14114
- sql2 += " " + alterStatement + ";\n";
14115
- sql2 += "EXCEPTION\n";
14116
- sql2 += " WHEN duplicate_object THEN null;\n";
14117
- sql2 += "END $$;\n";
14118
- return sql2;
14112
+ const alterStatement = `ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${name2}" FOREIGN KEY (${fromColumnsString}) REFERENCES ${tableToNameWithSchema}(${toColumnsString})${onDeleteStatement}${onUpdateStatement};`;
14113
+ return alterStatement;
14119
14114
  }
14120
14115
  };
14121
14116
  LibSQLCreateForeignKeyConvertor = class extends Convertor {
@@ -14172,12 +14167,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${statement.newC
14172
14167
  const toColumnsString = newFk.columnsTo.map((it) => `"${it}"`).join(",");
14173
14168
  const tableFromNameWithSchema = oldFk.schemaTo ? `"${oldFk.schemaTo}"."${oldFk.tableFrom}"` : `"${oldFk.tableFrom}"`;
14174
14169
  const tableToNameWithSchema = newFk.schemaTo ? `"${newFk.schemaTo}"."${newFk.tableFrom}"` : `"${newFk.tableFrom}"`;
14175
- const alterStatement = `ALTER TABLE ${tableFromNameWithSchema} ADD CONSTRAINT "${newFk.name}" FOREIGN KEY (${fromColumnsString}) REFERENCES ${tableToNameWithSchema}(${toColumnsString})${onDeleteStatement}${onUpdateStatement}`;
14176
- sql2 += "DO $$ BEGIN\n";
14177
- sql2 += " " + alterStatement + ";\n";
14178
- sql2 += "EXCEPTION\n";
14179
- sql2 += " WHEN duplicate_object THEN null;\n";
14180
- sql2 += "END $$;\n";
14170
+ const alterStatement = `ALTER TABLE ${tableFromNameWithSchema} ADD CONSTRAINT "${newFk.name}" FOREIGN KEY (${fromColumnsString}) REFERENCES ${tableToNameWithSchema}(${toColumnsString})${onDeleteStatement}${onUpdateStatement};`;
14171
+ sql2 += alterStatement;
14181
14172
  return sql2;
14182
14173
  }
14183
14174
  };
@@ -14233,7 +14224,7 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${statement.newC
14233
14224
  reversedString = reversedString.slice(0, -1);
14234
14225
  return reversedString;
14235
14226
  }
14236
- 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}` : ""};`;
14227
+ return `CREATE ${indexPart}${concurrently ? " CONCURRENTLY" : ""} "${name2}" ON ${tableNameWithSchema} USING ${method} (${value})${Object.keys(withMap).length !== 0 ? ` WITH (${reverseLogic(withMap)})` : ""}${where ? ` WHERE ${where}` : ""};`;
14237
14228
  }
14238
14229
  };
14239
14230
  CreateMySqlIndexConvertor = class extends Convertor {
@@ -14288,7 +14279,7 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${statement.newC
14288
14279
  }
14289
14280
  convert(statement) {
14290
14281
  const { name: name2 } = PgSquasher.unsquashIdx(statement.data);
14291
- return `DROP INDEX IF EXISTS "${name2}";`;
14282
+ return `DROP INDEX "${name2}";`;
14292
14283
  }
14293
14284
  };
14294
14285
  PgCreateSchemaConvertor = class extends Convertor {
@@ -14359,7 +14350,7 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${statement.newC
14359
14350
  }
14360
14351
  convert(statement) {
14361
14352
  const { name: name2 } = PgSquasher.unsquashIdx(statement.data);
14362
- return `DROP INDEX IF EXISTS \`${name2}\`;`;
14353
+ return `DROP INDEX \`${name2}\`;`;
14363
14354
  }
14364
14355
  };
14365
14356
  MySqlDropIndexConvertor = class extends Convertor {
@@ -37134,6 +37125,12 @@ var init_dialect3 = __esm({
37134
37125
  buildOrderBy(orderBy) {
37135
37126
  return orderBy && orderBy.length > 0 ? sql` order by ${sql.join(orderBy, sql`, `)}` : void 0;
37136
37127
  }
37128
+ buildIndex({
37129
+ indexes,
37130
+ indexFor
37131
+ }) {
37132
+ return indexes && indexes.length > 0 ? sql` ${sql.raw(indexFor)} INDEX (${sql.raw(indexes.join(`, `))})` : void 0;
37133
+ }
37137
37134
  buildSelectQuery({
37138
37135
  withList,
37139
37136
  fields,
@@ -37148,7 +37145,10 @@ var init_dialect3 = __esm({
37148
37145
  offset,
37149
37146
  lockingClause,
37150
37147
  distinct,
37151
- setOperators
37148
+ setOperators,
37149
+ useIndex,
37150
+ forceIndex,
37151
+ ignoreIndex
37152
37152
  }) {
37153
37153
  const fieldsList = fieldsFlat ?? orderSelectedFields(fields);
37154
37154
  for (const f of fieldsList) {
@@ -37184,8 +37184,11 @@ var init_dialect3 = __esm({
37184
37184
  const tableSchema = table22[MySqlTable.Symbol.Schema];
37185
37185
  const origTableName = table22[MySqlTable.Symbol.OriginalName];
37186
37186
  const alias = tableName === origTableName ? void 0 : joinMeta.alias;
37187
+ const useIndexSql2 = this.buildIndex({ indexes: joinMeta.useIndex, indexFor: "USE" });
37188
+ const forceIndexSql2 = this.buildIndex({ indexes: joinMeta.forceIndex, indexFor: "FORCE" });
37189
+ const ignoreIndexSql2 = this.buildIndex({ indexes: joinMeta.ignoreIndex, indexFor: "IGNORE" });
37187
37190
  joinsArray.push(
37188
- 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}`
37191
+ 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}`
37189
37192
  );
37190
37193
  } else if (is(table22, View3)) {
37191
37194
  const viewName = table22[ViewBaseConfig].name;
@@ -37212,6 +37215,9 @@ var init_dialect3 = __esm({
37212
37215
  const groupBySql = groupBy && groupBy.length > 0 ? sql` group by ${sql.join(groupBy, sql`, `)}` : void 0;
37213
37216
  const limitSql = this.buildLimit(limit);
37214
37217
  const offsetSql = offset ? sql` offset ${offset}` : void 0;
37218
+ const useIndexSql = this.buildIndex({ indexes: useIndex, indexFor: "USE" });
37219
+ const forceIndexSql = this.buildIndex({ indexes: forceIndex, indexFor: "FORCE" });
37220
+ const ignoreIndexSql = this.buildIndex({ indexes: ignoreIndex, indexFor: "IGNORE" });
37215
37221
  let lockingClausesSql;
37216
37222
  if (lockingClause) {
37217
37223
  const { config, strength } = lockingClause;
@@ -37222,7 +37228,7 @@ var init_dialect3 = __esm({
37222
37228
  lockingClausesSql.append(sql` skip locked`);
37223
37229
  }
37224
37230
  }
37225
- const finalQuery = sql`${withSql}select${distinctSql} ${selection} from ${tableSql}${joinsSql}${whereSql}${groupBySql}${havingSql}${orderBySql}${limitSql}${offsetSql}${lockingClausesSql}`;
37231
+ const finalQuery = sql`${withSql}select${distinctSql} ${selection} from ${tableSql}${useIndexSql}${forceIndexSql}${ignoreIndexSql}${joinsSql}${whereSql}${groupBySql}${havingSql}${orderBySql}${limitSql}${offsetSql}${lockingClausesSql}`;
37226
37232
  if (setOperators.length > 0) {
37227
37233
  return this.buildSetOperations(finalQuery, setOperators);
37228
37234
  }
@@ -37790,6 +37796,186 @@ var init_dialect3 = __esm({
37790
37796
  }
37791
37797
  });
37792
37798
 
37799
+ // ../drizzle-orm/dist/mysql-core/indexes.js
37800
+ var _a302, IndexBuilderOn3, _a303, IndexBuilder3, _a304, Index5;
37801
+ var init_indexes3 = __esm({
37802
+ "../drizzle-orm/dist/mysql-core/indexes.js"() {
37803
+ "use strict";
37804
+ init_entity();
37805
+ _a302 = entityKind;
37806
+ IndexBuilderOn3 = class {
37807
+ constructor(name2, unique) {
37808
+ this.name = name2;
37809
+ this.unique = unique;
37810
+ }
37811
+ on(...columns) {
37812
+ return new IndexBuilder3(this.name, columns, this.unique);
37813
+ }
37814
+ };
37815
+ __publicField(IndexBuilderOn3, _a302, "MySqlIndexBuilderOn");
37816
+ _a303 = entityKind;
37817
+ IndexBuilder3 = class {
37818
+ constructor(name2, columns, unique) {
37819
+ /** @internal */
37820
+ __publicField(this, "config");
37821
+ this.config = {
37822
+ name: name2,
37823
+ columns,
37824
+ unique
37825
+ };
37826
+ }
37827
+ using(using) {
37828
+ this.config.using = using;
37829
+ return this;
37830
+ }
37831
+ algorythm(algorythm) {
37832
+ this.config.algorythm = algorythm;
37833
+ return this;
37834
+ }
37835
+ lock(lock) {
37836
+ this.config.lock = lock;
37837
+ return this;
37838
+ }
37839
+ /** @internal */
37840
+ build(table5) {
37841
+ return new Index5(this.config, table5);
37842
+ }
37843
+ };
37844
+ __publicField(IndexBuilder3, _a303, "MySqlIndexBuilder");
37845
+ _a304 = entityKind;
37846
+ Index5 = class {
37847
+ constructor(config, table5) {
37848
+ __publicField(this, "config");
37849
+ this.config = { ...config, table: table5 };
37850
+ }
37851
+ };
37852
+ __publicField(Index5, _a304, "MySqlIndex");
37853
+ }
37854
+ });
37855
+
37856
+ // ../drizzle-orm/dist/mysql-core/primary-keys.js
37857
+ var _a305, PrimaryKeyBuilder3, _a306, PrimaryKey3;
37858
+ var init_primary_keys3 = __esm({
37859
+ "../drizzle-orm/dist/mysql-core/primary-keys.js"() {
37860
+ "use strict";
37861
+ init_entity();
37862
+ init_table4();
37863
+ _a305 = entityKind;
37864
+ PrimaryKeyBuilder3 = class {
37865
+ constructor(columns, name2) {
37866
+ /** @internal */
37867
+ __publicField(this, "columns");
37868
+ /** @internal */
37869
+ __publicField(this, "name");
37870
+ this.columns = columns;
37871
+ this.name = name2;
37872
+ }
37873
+ /** @internal */
37874
+ build(table5) {
37875
+ return new PrimaryKey3(table5, this.columns, this.name);
37876
+ }
37877
+ };
37878
+ __publicField(PrimaryKeyBuilder3, _a305, "MySqlPrimaryKeyBuilder");
37879
+ _a306 = entityKind;
37880
+ PrimaryKey3 = class {
37881
+ constructor(table5, columns, name2) {
37882
+ __publicField(this, "columns");
37883
+ __publicField(this, "name");
37884
+ this.table = table5;
37885
+ this.columns = columns;
37886
+ this.name = name2;
37887
+ }
37888
+ getName() {
37889
+ return this.name ?? `${this.table[MySqlTable.Symbol.Name]}_${this.columns.map((column5) => column5.name).join("_")}_pk`;
37890
+ }
37891
+ };
37892
+ __publicField(PrimaryKey3, _a306, "MySqlPrimaryKey");
37893
+ }
37894
+ });
37895
+
37896
+ // ../drizzle-orm/dist/mysql-core/view-common.js
37897
+ var MySqlViewConfig;
37898
+ var init_view_common3 = __esm({
37899
+ "../drizzle-orm/dist/mysql-core/view-common.js"() {
37900
+ "use strict";
37901
+ MySqlViewConfig = Symbol.for("drizzle:MySqlViewConfig");
37902
+ }
37903
+ });
37904
+
37905
+ // ../drizzle-orm/dist/mysql-core/utils.js
37906
+ function getTableConfig3(table5) {
37907
+ const columns = Object.values(table5[MySqlTable.Symbol.Columns]);
37908
+ const indexes = [];
37909
+ const checks = [];
37910
+ const primaryKeys = [];
37911
+ const uniqueConstraints = [];
37912
+ const foreignKeys = Object.values(table5[MySqlTable.Symbol.InlineForeignKeys]);
37913
+ const name2 = table5[Table2.Symbol.Name];
37914
+ const schema5 = table5[Table2.Symbol.Schema];
37915
+ const baseName = table5[Table2.Symbol.BaseName];
37916
+ const extraConfigBuilder = table5[MySqlTable.Symbol.ExtraConfigBuilder];
37917
+ if (extraConfigBuilder !== void 0) {
37918
+ const extraConfig = extraConfigBuilder(table5[MySqlTable.Symbol.Columns]);
37919
+ for (const builder of Object.values(extraConfig)) {
37920
+ if (is(builder, IndexBuilder3)) {
37921
+ indexes.push(builder.build(table5));
37922
+ } else if (is(builder, CheckBuilder3)) {
37923
+ checks.push(builder.build(table5));
37924
+ } else if (is(builder, UniqueConstraintBuilder3)) {
37925
+ uniqueConstraints.push(builder.build(table5));
37926
+ } else if (is(builder, PrimaryKeyBuilder3)) {
37927
+ primaryKeys.push(builder.build(table5));
37928
+ } else if (is(builder, ForeignKeyBuilder3)) {
37929
+ foreignKeys.push(builder.build(table5));
37930
+ }
37931
+ }
37932
+ }
37933
+ return {
37934
+ columns,
37935
+ indexes,
37936
+ foreignKeys,
37937
+ checks,
37938
+ primaryKeys,
37939
+ uniqueConstraints,
37940
+ name: name2,
37941
+ schema: schema5,
37942
+ baseName
37943
+ };
37944
+ }
37945
+ function getViewConfig3(view4) {
37946
+ return {
37947
+ ...view4[ViewBaseConfig],
37948
+ ...view4[MySqlViewConfig]
37949
+ };
37950
+ }
37951
+ function convertIndexToString({
37952
+ table: table5,
37953
+ indexes
37954
+ }) {
37955
+ return indexes.map((idx) => {
37956
+ if (typeof idx === "object") {
37957
+ return is(idx, UniqueConstraintBuilder3) ? idx.build(table5).getName() : idx.config.name;
37958
+ } else {
37959
+ return idx;
37960
+ }
37961
+ });
37962
+ }
37963
+ var init_utils8 = __esm({
37964
+ "../drizzle-orm/dist/mysql-core/utils.js"() {
37965
+ "use strict";
37966
+ init_entity();
37967
+ init_table();
37968
+ init_view_common();
37969
+ init_checks3();
37970
+ init_foreign_keys3();
37971
+ init_indexes3();
37972
+ init_primary_keys3();
37973
+ init_table4();
37974
+ init_unique_constraint3();
37975
+ init_view_common3();
37976
+ }
37977
+ });
37978
+
37793
37979
  // ../drizzle-orm/dist/mysql-core/query-builders/select.js
37794
37980
  function createSetOperator3(type, isAll) {
37795
37981
  return (leftSelect, rightSelect, ...restSelects) => {
@@ -37808,11 +37994,12 @@ function createSetOperator3(type, isAll) {
37808
37994
  return leftSelect.addSetOperators(setOperators);
37809
37995
  };
37810
37996
  }
37811
- var _a302, MySqlSelectBuilder, _a303, _b224, MySqlSelectQueryBuilderBase, _a304, _b225, MySqlSelectBase, getMySqlSetOperators, union3, unionAll3, intersect3, intersectAll2, except3, exceptAll2;
37997
+ var _a307, MySqlSelectBuilder, _a308, _b224, MySqlSelectQueryBuilderBase, _a309, _b225, MySqlSelectBase, getMySqlSetOperators, union3, unionAll3, intersect3, intersectAll2, except3, exceptAll2;
37812
37998
  var init_select4 = __esm({
37813
37999
  "../drizzle-orm/dist/mysql-core/query-builders/select.js"() {
37814
38000
  "use strict";
37815
38001
  init_entity();
38002
+ init_table4();
37816
38003
  init_query_builder();
37817
38004
  init_query_promise();
37818
38005
  init_selection_proxy();
@@ -37822,8 +38009,9 @@ var init_select4 = __esm({
37822
38009
  init_utils2();
37823
38010
  init_utils2();
37824
38011
  init_view_common();
38012
+ init_utils8();
37825
38013
  init_view_base3();
37826
- _a302 = entityKind;
38014
+ _a307 = entityKind;
37827
38015
  MySqlSelectBuilder = class {
37828
38016
  constructor(config) {
37829
38017
  __publicField(this, "fields");
@@ -37839,7 +38027,7 @@ var init_select4 = __esm({
37839
38027
  }
37840
38028
  this.distinct = config.distinct;
37841
38029
  }
37842
- from(source) {
38030
+ from(source, onIndex) {
37843
38031
  const isPartialSelect = !!this.fields;
37844
38032
  let fields;
37845
38033
  if (this.fields) {
@@ -37855,6 +38043,20 @@ var init_select4 = __esm({
37855
38043
  } else {
37856
38044
  fields = getTableColumns(source);
37857
38045
  }
38046
+ let useIndex = [];
38047
+ let forceIndex = [];
38048
+ let ignoreIndex = [];
38049
+ if (is(source, MySqlTable) && onIndex) {
38050
+ if (onIndex.useIndex) {
38051
+ useIndex = convertIndexToString({ table: source, indexes: onIndex.useIndex });
38052
+ }
38053
+ if (onIndex.forceIndex) {
38054
+ forceIndex = convertIndexToString({ table: source, indexes: onIndex.forceIndex });
38055
+ }
38056
+ if (onIndex.ignoreIndex) {
38057
+ ignoreIndex = convertIndexToString({ table: source, indexes: onIndex.ignoreIndex });
38058
+ }
38059
+ }
37858
38060
  return new MySqlSelectBase(
37859
38061
  {
37860
38062
  table: source,
@@ -37863,14 +38065,17 @@ var init_select4 = __esm({
37863
38065
  session: this.session,
37864
38066
  dialect: this.dialect,
37865
38067
  withList: this.withList,
37866
- distinct: this.distinct
38068
+ distinct: this.distinct,
38069
+ useIndex,
38070
+ forceIndex,
38071
+ ignoreIndex
37867
38072
  }
37868
38073
  );
37869
38074
  }
37870
38075
  };
37871
- __publicField(MySqlSelectBuilder, _a302, "MySqlSelectBuilder");
37872
- MySqlSelectQueryBuilderBase = class extends (_b224 = TypedQueryBuilder, _a303 = entityKind, _b224) {
37873
- constructor({ table: table5, fields, isPartialSelect, session, dialect: dialect6, withList, distinct }) {
38076
+ __publicField(MySqlSelectBuilder, _a307, "MySqlSelectBuilder");
38077
+ MySqlSelectQueryBuilderBase = class extends (_b224 = TypedQueryBuilder, _a308 = entityKind, _b224) {
38078
+ constructor({ table: table5, fields, isPartialSelect, session, dialect: dialect6, withList, distinct, useIndex, forceIndex, ignoreIndex }) {
37874
38079
  super();
37875
38080
  __publicField(this, "_");
37876
38081
  __publicField(this, "config");
@@ -37905,6 +38110,16 @@ var init_select4 = __esm({
37905
38110
  * })
37906
38111
  * .from(users)
37907
38112
  * .leftJoin(pets, eq(users.id, pets.ownerId))
38113
+ *
38114
+ * // Select userId and petId with use index hint
38115
+ * const usersIdsAndPetIds: { userId: number; petId: number | null }[] = await db.select({
38116
+ * userId: users.id,
38117
+ * petId: pets.id,
38118
+ * })
38119
+ * .from(users)
38120
+ * .leftJoin(pets, eq(users.id, pets.ownerId), {
38121
+ * useIndex: ['pets_owner_id_index']
38122
+ * })
37908
38123
  * ```
37909
38124
  */
37910
38125
  __publicField(this, "leftJoin", this.createJoin("left"));
@@ -37933,6 +38148,16 @@ var init_select4 = __esm({
37933
38148
  * })
37934
38149
  * .from(users)
37935
38150
  * .rightJoin(pets, eq(users.id, pets.ownerId))
38151
+ *
38152
+ * // Select userId and petId with use index hint
38153
+ * const usersIdsAndPetIds: { userId: number; petId: number | null }[] = await db.select({
38154
+ * userId: users.id,
38155
+ * petId: pets.id,
38156
+ * })
38157
+ * .from(users)
38158
+ * .leftJoin(pets, eq(users.id, pets.ownerId), {
38159
+ * useIndex: ['pets_owner_id_index']
38160
+ * })
37936
38161
  * ```
37937
38162
  */
37938
38163
  __publicField(this, "rightJoin", this.createJoin("right"));
@@ -37961,6 +38186,16 @@ var init_select4 = __esm({
37961
38186
  * })
37962
38187
  * .from(users)
37963
38188
  * .innerJoin(pets, eq(users.id, pets.ownerId))
38189
+ *
38190
+ * // Select userId and petId with use index hint
38191
+ * const usersIdsAndPetIds: { userId: number; petId: number | null }[] = await db.select({
38192
+ * userId: users.id,
38193
+ * petId: pets.id,
38194
+ * })
38195
+ * .from(users)
38196
+ * .leftJoin(pets, eq(users.id, pets.ownerId), {
38197
+ * useIndex: ['pets_owner_id_index']
38198
+ * })
37964
38199
  * ```
37965
38200
  */
37966
38201
  __publicField(this, "innerJoin", this.createJoin("inner"));
@@ -37989,6 +38224,16 @@ var init_select4 = __esm({
37989
38224
  * })
37990
38225
  * .from(users)
37991
38226
  * .fullJoin(pets, eq(users.id, pets.ownerId))
38227
+ *
38228
+ * // Select userId and petId with use index hint
38229
+ * const usersIdsAndPetIds: { userId: number; petId: number | null }[] = await db.select({
38230
+ * userId: users.id,
38231
+ * petId: pets.id,
38232
+ * })
38233
+ * .from(users)
38234
+ * .leftJoin(pets, eq(users.id, pets.ownerId), {
38235
+ * useIndex: ['pets_owner_id_index']
38236
+ * })
37992
38237
  * ```
37993
38238
  */
37994
38239
  __publicField(this, "fullJoin", this.createJoin("full"));
@@ -38183,7 +38428,10 @@ var init_select4 = __esm({
38183
38428
  table: table5,
38184
38429
  fields: { ...fields },
38185
38430
  distinct,
38186
- setOperators: []
38431
+ setOperators: [],
38432
+ useIndex,
38433
+ forceIndex,
38434
+ ignoreIndex
38187
38435
  };
38188
38436
  this.isPartialSelect = isPartialSelect;
38189
38437
  this.session = session;
@@ -38195,7 +38443,7 @@ var init_select4 = __esm({
38195
38443
  this.joinsNotNullableMap = typeof this.tableName === "string" ? { [this.tableName]: true } : {};
38196
38444
  }
38197
38445
  createJoin(joinType) {
38198
- return (table5, on) => {
38446
+ return (table5, on, onIndex) => {
38199
38447
  const baseTableName = this.tableName;
38200
38448
  const tableName = getTableLikeName(table5);
38201
38449
  if (typeof tableName === "string" && this.config.joins?.some((join) => join.alias === tableName)) {
@@ -38223,7 +38471,21 @@ var init_select4 = __esm({
38223
38471
  if (!this.config.joins) {
38224
38472
  this.config.joins = [];
38225
38473
  }
38226
- this.config.joins.push({ on, table: table5, joinType, alias: tableName });
38474
+ let useIndex = [];
38475
+ let forceIndex = [];
38476
+ let ignoreIndex = [];
38477
+ if (is(table5, MySqlTable) && onIndex) {
38478
+ if (onIndex.useIndex) {
38479
+ useIndex = convertIndexToString({ table: table5, indexes: onIndex.useIndex });
38480
+ }
38481
+ if (onIndex.forceIndex) {
38482
+ forceIndex = convertIndexToString({ table: table5, indexes: onIndex.forceIndex });
38483
+ }
38484
+ if (onIndex.ignoreIndex) {
38485
+ ignoreIndex = convertIndexToString({ table: table5, indexes: onIndex.ignoreIndex });
38486
+ }
38487
+ }
38488
+ this.config.joins.push({ on, table: table5, joinType, alias: tableName, useIndex, forceIndex, ignoreIndex });
38227
38489
  if (typeof tableName === "string") {
38228
38490
  switch (joinType) {
38229
38491
  case "left": {
@@ -38470,8 +38732,8 @@ var init_select4 = __esm({
38470
38732
  return this;
38471
38733
  }
38472
38734
  };
38473
- __publicField(MySqlSelectQueryBuilderBase, _a303, "MySqlSelectQueryBuilder");
38474
- MySqlSelectBase = class extends (_b225 = MySqlSelectQueryBuilderBase, _a304 = entityKind, _b225) {
38735
+ __publicField(MySqlSelectQueryBuilderBase, _a308, "MySqlSelectQueryBuilder");
38736
+ MySqlSelectBase = class extends (_b225 = MySqlSelectQueryBuilderBase, _a309 = entityKind, _b225) {
38475
38737
  constructor() {
38476
38738
  super(...arguments);
38477
38739
  __publicField(this, "execute", (placeholderValues) => {
@@ -38495,7 +38757,7 @@ var init_select4 = __esm({
38495
38757
  return query;
38496
38758
  }
38497
38759
  };
38498
- __publicField(MySqlSelectBase, _a304, "MySqlSelect");
38760
+ __publicField(MySqlSelectBase, _a309, "MySqlSelect");
38499
38761
  applyMixins(MySqlSelectBase, [QueryPromise]);
38500
38762
  getMySqlSetOperators = () => ({
38501
38763
  union: union3,
@@ -38515,7 +38777,7 @@ var init_select4 = __esm({
38515
38777
  });
38516
38778
 
38517
38779
  // ../drizzle-orm/dist/mysql-core/query-builders/query-builder.js
38518
- var _a305, QueryBuilder3;
38780
+ var _a310, QueryBuilder3;
38519
38781
  var init_query_builder4 = __esm({
38520
38782
  "../drizzle-orm/dist/mysql-core/query-builders/query-builder.js"() {
38521
38783
  "use strict";
@@ -38524,7 +38786,7 @@ var init_query_builder4 = __esm({
38524
38786
  init_selection_proxy();
38525
38787
  init_subquery();
38526
38788
  init_select4();
38527
- _a305 = entityKind;
38789
+ _a310 = entityKind;
38528
38790
  QueryBuilder3 = class {
38529
38791
  constructor(dialect6) {
38530
38792
  __publicField(this, "dialect");
@@ -38586,12 +38848,12 @@ var init_query_builder4 = __esm({
38586
38848
  return this.dialect;
38587
38849
  }
38588
38850
  };
38589
- __publicField(QueryBuilder3, _a305, "MySqlQueryBuilder");
38851
+ __publicField(QueryBuilder3, _a310, "MySqlQueryBuilder");
38590
38852
  }
38591
38853
  });
38592
38854
 
38593
38855
  // ../drizzle-orm/dist/mysql-core/query-builders/insert.js
38594
- var _a306, MySqlInsertBuilder, _a307, _b226, MySqlInsertBase;
38856
+ var _a311, MySqlInsertBuilder, _a312, _b226, MySqlInsertBase;
38595
38857
  var init_insert3 = __esm({
38596
38858
  "../drizzle-orm/dist/mysql-core/query-builders/insert.js"() {
38597
38859
  "use strict";
@@ -38601,7 +38863,7 @@ var init_insert3 = __esm({
38601
38863
  init_table();
38602
38864
  init_utils2();
38603
38865
  init_query_builder4();
38604
- _a306 = entityKind;
38866
+ _a311 = entityKind;
38605
38867
  MySqlInsertBuilder = class {
38606
38868
  constructor(table5, session, dialect6) {
38607
38869
  __publicField(this, "shouldIgnore", false);
@@ -38639,8 +38901,8 @@ var init_insert3 = __esm({
38639
38901
  return new MySqlInsertBase(this.table, select, this.shouldIgnore, this.session, this.dialect, true);
38640
38902
  }
38641
38903
  };
38642
- __publicField(MySqlInsertBuilder, _a306, "MySqlInsertBuilder");
38643
- MySqlInsertBase = class extends (_b226 = QueryPromise, _a307 = entityKind, _b226) {
38904
+ __publicField(MySqlInsertBuilder, _a311, "MySqlInsertBuilder");
38905
+ MySqlInsertBase = class extends (_b226 = QueryPromise, _a312 = entityKind, _b226) {
38644
38906
  constructor(table5, values, ignore, session, dialect6, select) {
38645
38907
  super();
38646
38908
  __publicField(this, "config");
@@ -38721,7 +38983,7 @@ var init_insert3 = __esm({
38721
38983
  return this;
38722
38984
  }
38723
38985
  };
38724
- __publicField(MySqlInsertBase, _a307, "MySqlInsert");
38986
+ __publicField(MySqlInsertBase, _a312, "MySqlInsert");
38725
38987
  }
38726
38988
  });
38727
38989
 
@@ -38733,7 +38995,7 @@ var init_select_types3 = __esm({
38733
38995
  });
38734
38996
 
38735
38997
  // ../drizzle-orm/dist/mysql-core/query-builders/update.js
38736
- var _a308, MySqlUpdateBuilder, _a309, _b227, MySqlUpdateBase;
38998
+ var _a313, MySqlUpdateBuilder, _a314, _b227, MySqlUpdateBase;
38737
38999
  var init_update3 = __esm({
38738
39000
  "../drizzle-orm/dist/mysql-core/query-builders/update.js"() {
38739
39001
  "use strict";
@@ -38742,7 +39004,7 @@ var init_update3 = __esm({
38742
39004
  init_selection_proxy();
38743
39005
  init_table();
38744
39006
  init_utils2();
38745
- _a308 = entityKind;
39007
+ _a313 = entityKind;
38746
39008
  MySqlUpdateBuilder = class {
38747
39009
  constructor(table5, session, dialect6, withList) {
38748
39010
  this.table = table5;
@@ -38754,8 +39016,8 @@ var init_update3 = __esm({
38754
39016
  return new MySqlUpdateBase(this.table, mapUpdateSet(this.table, values), this.session, this.dialect, this.withList);
38755
39017
  }
38756
39018
  };
38757
- __publicField(MySqlUpdateBuilder, _a308, "MySqlUpdateBuilder");
38758
- MySqlUpdateBase = class extends (_b227 = QueryPromise, _a309 = entityKind, _b227) {
39019
+ __publicField(MySqlUpdateBuilder, _a313, "MySqlUpdateBuilder");
39020
+ MySqlUpdateBase = class extends (_b227 = QueryPromise, _a314 = entityKind, _b227) {
38759
39021
  constructor(table5, set, session, dialect6, withList) {
38760
39022
  super();
38761
39023
  __publicField(this, "config");
@@ -38848,7 +39110,7 @@ var init_update3 = __esm({
38848
39110
  return this;
38849
39111
  }
38850
39112
  };
38851
- __publicField(MySqlUpdateBase, _a309, "MySqlUpdate");
39113
+ __publicField(MySqlUpdateBase, _a314, "MySqlUpdate");
38852
39114
  }
38853
39115
  });
38854
39116
 
@@ -38866,14 +39128,14 @@ var init_query_builders3 = __esm({
38866
39128
  });
38867
39129
 
38868
39130
  // ../drizzle-orm/dist/mysql-core/query-builders/query.js
38869
- var _a310, RelationalQueryBuilder3, _a311, _b228, MySqlRelationalQuery;
39131
+ var _a315, RelationalQueryBuilder3, _a316, _b228, MySqlRelationalQuery;
38870
39132
  var init_query3 = __esm({
38871
39133
  "../drizzle-orm/dist/mysql-core/query-builders/query.js"() {
38872
39134
  "use strict";
38873
39135
  init_entity();
38874
39136
  init_query_promise();
38875
39137
  init_relations();
38876
- _a310 = entityKind;
39138
+ _a315 = entityKind;
38877
39139
  RelationalQueryBuilder3 = class {
38878
39140
  constructor(fullSchema, schema5, tableNamesMap, table5, tableConfig, dialect6, session, mode) {
38879
39141
  this.fullSchema = fullSchema;
@@ -38914,8 +39176,8 @@ var init_query3 = __esm({
38914
39176
  );
38915
39177
  }
38916
39178
  };
38917
- __publicField(RelationalQueryBuilder3, _a310, "MySqlRelationalQueryBuilder");
38918
- MySqlRelationalQuery = class extends (_b228 = QueryPromise, _a311 = entityKind, _b228) {
39179
+ __publicField(RelationalQueryBuilder3, _a315, "MySqlRelationalQueryBuilder");
39180
+ MySqlRelationalQuery = class extends (_b228 = QueryPromise, _a316 = entityKind, _b228) {
38919
39181
  constructor(fullSchema, schema5, tableNamesMap, table5, tableConfig, dialect6, session, config, queryMode, mode) {
38920
39182
  super();
38921
39183
  this.fullSchema = fullSchema;
@@ -38979,12 +39241,12 @@ var init_query3 = __esm({
38979
39241
  return this.prepare().execute();
38980
39242
  }
38981
39243
  };
38982
- __publicField(MySqlRelationalQuery, _a311, "MySqlRelationalQuery");
39244
+ __publicField(MySqlRelationalQuery, _a316, "MySqlRelationalQuery");
38983
39245
  }
38984
39246
  });
38985
39247
 
38986
39248
  // ../drizzle-orm/dist/mysql-core/db.js
38987
- var _a312, MySqlDatabase;
39249
+ var _a317, MySqlDatabase;
38988
39250
  var init_db3 = __esm({
38989
39251
  "../drizzle-orm/dist/mysql-core/db.js"() {
38990
39252
  "use strict";
@@ -38995,7 +39257,7 @@ var init_db3 = __esm({
38995
39257
  init_count3();
38996
39258
  init_query_builders3();
38997
39259
  init_query3();
38998
- _a312 = entityKind;
39260
+ _a317 = entityKind;
38999
39261
  MySqlDatabase = class {
39000
39262
  constructor(dialect6, session, schema5, mode) {
39001
39263
  __publicField(this, "query");
@@ -39208,113 +39470,7 @@ var init_db3 = __esm({
39208
39470
  return this.session.transaction(transaction, config);
39209
39471
  }
39210
39472
  };
39211
- __publicField(MySqlDatabase, _a312, "MySqlDatabase");
39212
- }
39213
- });
39214
-
39215
- // ../drizzle-orm/dist/mysql-core/indexes.js
39216
- var _a313, IndexBuilderOn3, _a314, IndexBuilder3, _a315, Index5;
39217
- var init_indexes3 = __esm({
39218
- "../drizzle-orm/dist/mysql-core/indexes.js"() {
39219
- "use strict";
39220
- init_entity();
39221
- _a313 = entityKind;
39222
- IndexBuilderOn3 = class {
39223
- constructor(name2, unique) {
39224
- this.name = name2;
39225
- this.unique = unique;
39226
- }
39227
- on(...columns) {
39228
- return new IndexBuilder3(this.name, columns, this.unique);
39229
- }
39230
- };
39231
- __publicField(IndexBuilderOn3, _a313, "MySqlIndexBuilderOn");
39232
- _a314 = entityKind;
39233
- IndexBuilder3 = class {
39234
- constructor(name2, columns, unique) {
39235
- /** @internal */
39236
- __publicField(this, "config");
39237
- this.config = {
39238
- name: name2,
39239
- columns,
39240
- unique
39241
- };
39242
- }
39243
- using(using) {
39244
- this.config.using = using;
39245
- return this;
39246
- }
39247
- algorythm(algorythm) {
39248
- this.config.algorythm = algorythm;
39249
- return this;
39250
- }
39251
- lock(lock) {
39252
- this.config.lock = lock;
39253
- return this;
39254
- }
39255
- /** @internal */
39256
- build(table5) {
39257
- return new Index5(this.config, table5);
39258
- }
39259
- };
39260
- __publicField(IndexBuilder3, _a314, "MySqlIndexBuilder");
39261
- _a315 = entityKind;
39262
- Index5 = class {
39263
- constructor(config, table5) {
39264
- __publicField(this, "config");
39265
- this.config = { ...config, table: table5 };
39266
- }
39267
- };
39268
- __publicField(Index5, _a315, "MySqlIndex");
39269
- }
39270
- });
39271
-
39272
- // ../drizzle-orm/dist/mysql-core/primary-keys.js
39273
- var _a316, PrimaryKeyBuilder3, _a317, PrimaryKey3;
39274
- var init_primary_keys3 = __esm({
39275
- "../drizzle-orm/dist/mysql-core/primary-keys.js"() {
39276
- "use strict";
39277
- init_entity();
39278
- init_table4();
39279
- _a316 = entityKind;
39280
- PrimaryKeyBuilder3 = class {
39281
- constructor(columns, name2) {
39282
- /** @internal */
39283
- __publicField(this, "columns");
39284
- /** @internal */
39285
- __publicField(this, "name");
39286
- this.columns = columns;
39287
- this.name = name2;
39288
- }
39289
- /** @internal */
39290
- build(table5) {
39291
- return new PrimaryKey3(table5, this.columns, this.name);
39292
- }
39293
- };
39294
- __publicField(PrimaryKeyBuilder3, _a316, "MySqlPrimaryKeyBuilder");
39295
- _a317 = entityKind;
39296
- PrimaryKey3 = class {
39297
- constructor(table5, columns, name2) {
39298
- __publicField(this, "columns");
39299
- __publicField(this, "name");
39300
- this.table = table5;
39301
- this.columns = columns;
39302
- this.name = name2;
39303
- }
39304
- getName() {
39305
- return this.name ?? `${this.table[MySqlTable.Symbol.Name]}_${this.columns.map((column5) => column5.name).join("_")}_pk`;
39306
- }
39307
- };
39308
- __publicField(PrimaryKey3, _a317, "MySqlPrimaryKey");
39309
- }
39310
- });
39311
-
39312
- // ../drizzle-orm/dist/mysql-core/view-common.js
39313
- var MySqlViewConfig;
39314
- var init_view_common3 = __esm({
39315
- "../drizzle-orm/dist/mysql-core/view-common.js"() {
39316
- "use strict";
39317
- MySqlViewConfig = Symbol.for("drizzle:MySqlViewConfig");
39473
+ __publicField(MySqlDatabase, _a317, "MySqlDatabase");
39318
39474
  }
39319
39475
  });
39320
39476
 
@@ -39539,68 +39695,6 @@ var init_subquery4 = __esm({
39539
39695
  }
39540
39696
  });
39541
39697
 
39542
- // ../drizzle-orm/dist/mysql-core/utils.js
39543
- function getTableConfig3(table5) {
39544
- const columns = Object.values(table5[MySqlTable.Symbol.Columns]);
39545
- const indexes = [];
39546
- const checks = [];
39547
- const primaryKeys = [];
39548
- const uniqueConstraints = [];
39549
- const foreignKeys = Object.values(table5[MySqlTable.Symbol.InlineForeignKeys]);
39550
- const name2 = table5[Table2.Symbol.Name];
39551
- const schema5 = table5[Table2.Symbol.Schema];
39552
- const baseName = table5[Table2.Symbol.BaseName];
39553
- const extraConfigBuilder = table5[MySqlTable.Symbol.ExtraConfigBuilder];
39554
- if (extraConfigBuilder !== void 0) {
39555
- const extraConfig = extraConfigBuilder(table5[MySqlTable.Symbol.Columns]);
39556
- for (const builder of Object.values(extraConfig)) {
39557
- if (is(builder, IndexBuilder3)) {
39558
- indexes.push(builder.build(table5));
39559
- } else if (is(builder, CheckBuilder3)) {
39560
- checks.push(builder.build(table5));
39561
- } else if (is(builder, UniqueConstraintBuilder3)) {
39562
- uniqueConstraints.push(builder.build(table5));
39563
- } else if (is(builder, PrimaryKeyBuilder3)) {
39564
- primaryKeys.push(builder.build(table5));
39565
- } else if (is(builder, ForeignKeyBuilder3)) {
39566
- foreignKeys.push(builder.build(table5));
39567
- }
39568
- }
39569
- }
39570
- return {
39571
- columns,
39572
- indexes,
39573
- foreignKeys,
39574
- checks,
39575
- primaryKeys,
39576
- uniqueConstraints,
39577
- name: name2,
39578
- schema: schema5,
39579
- baseName
39580
- };
39581
- }
39582
- function getViewConfig3(view4) {
39583
- return {
39584
- ...view4[ViewBaseConfig],
39585
- ...view4[MySqlViewConfig]
39586
- };
39587
- }
39588
- var init_utils8 = __esm({
39589
- "../drizzle-orm/dist/mysql-core/utils.js"() {
39590
- "use strict";
39591
- init_entity();
39592
- init_table();
39593
- init_view_common();
39594
- init_checks3();
39595
- init_foreign_keys3();
39596
- init_indexes3();
39597
- init_primary_keys3();
39598
- init_table4();
39599
- init_unique_constraint3();
39600
- init_view_common3();
39601
- }
39602
- });
39603
-
39604
39698
  // ../drizzle-orm/dist/mysql-core/index.js
39605
39699
  var init_mysql_core = __esm({
39606
39700
  "../drizzle-orm/dist/mysql-core/index.js"() {