drizzle-kit 0.30.2-44616e9 → 0.30.2-84987cd

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 +774 -422
  2. package/api.mjs +774 -422
  3. package/bin.cjs +34648 -47757
  4. package/package.json +1 -1
package/api.js CHANGED
@@ -3469,17 +3469,17 @@ function processCreateParams(params) {
3469
3469
  if (errorMap2)
3470
3470
  return { errorMap: errorMap2, description };
3471
3471
  const customMap = (iss, ctx) => {
3472
- var _a413, _b303;
3472
+ var _a415, _b305;
3473
3473
  const { message } = params;
3474
3474
  if (iss.code === "invalid_enum_value") {
3475
3475
  return { message: message !== null && message !== void 0 ? message : ctx.defaultError };
3476
3476
  }
3477
3477
  if (typeof ctx.data === "undefined") {
3478
- return { message: (_a413 = message !== null && message !== void 0 ? message : required_error) !== null && _a413 !== void 0 ? _a413 : ctx.defaultError };
3478
+ return { message: (_a415 = message !== null && message !== void 0 ? message : required_error) !== null && _a415 !== void 0 ? _a415 : ctx.defaultError };
3479
3479
  }
3480
3480
  if (iss.code !== "invalid_type")
3481
3481
  return { message: ctx.defaultError };
3482
- return { message: (_b303 = message !== null && message !== void 0 ? message : invalid_type_error) !== null && _b303 !== void 0 ? _b303 : ctx.defaultError };
3482
+ return { message: (_b305 = message !== null && message !== void 0 ? message : invalid_type_error) !== null && _b305 !== void 0 ? _b305 : ctx.defaultError };
3483
3483
  };
3484
3484
  return { errorMap: customMap, description };
3485
3485
  }
@@ -4141,11 +4141,11 @@ var init_lib = __esm({
4141
4141
  throw result.error;
4142
4142
  }
4143
4143
  safeParse(data, params) {
4144
- var _a413;
4144
+ var _a415;
4145
4145
  const ctx = {
4146
4146
  common: {
4147
4147
  issues: [],
4148
- async: (_a413 = params === null || params === void 0 ? void 0 : params.async) !== null && _a413 !== void 0 ? _a413 : false,
4148
+ async: (_a415 = params === null || params === void 0 ? void 0 : params.async) !== null && _a415 !== void 0 ? _a415 : false,
4149
4149
  contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap
4150
4150
  },
4151
4151
  path: (params === null || params === void 0 ? void 0 : params.path) || [],
@@ -4467,7 +4467,7 @@ var init_lib = __esm({
4467
4467
  } else if (check.kind === "url") {
4468
4468
  try {
4469
4469
  new URL(input.data);
4470
- } catch (_a413) {
4470
+ } catch (_a415) {
4471
4471
  ctx = this._getOrReturnCtx(input, ctx);
4472
4472
  addIssueToContext(ctx, {
4473
4473
  validation: "url",
@@ -4637,7 +4637,7 @@ var init_lib = __esm({
4637
4637
  return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
4638
4638
  }
4639
4639
  datetime(options) {
4640
- var _a413, _b303;
4640
+ var _a415, _b305;
4641
4641
  if (typeof options === "string") {
4642
4642
  return this._addCheck({
4643
4643
  kind: "datetime",
@@ -4650,8 +4650,8 @@ var init_lib = __esm({
4650
4650
  return this._addCheck({
4651
4651
  kind: "datetime",
4652
4652
  precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
4653
- offset: (_a413 = options === null || options === void 0 ? void 0 : options.offset) !== null && _a413 !== void 0 ? _a413 : false,
4654
- local: (_b303 = options === null || options === void 0 ? void 0 : options.local) !== null && _b303 !== void 0 ? _b303 : false,
4653
+ offset: (_a415 = options === null || options === void 0 ? void 0 : options.offset) !== null && _a415 !== void 0 ? _a415 : false,
4654
+ local: (_b305 = options === null || options === void 0 ? void 0 : options.local) !== null && _b305 !== void 0 ? _b305 : false,
4655
4655
  ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
4656
4656
  });
4657
4657
  }
@@ -4814,11 +4814,11 @@ var init_lib = __esm({
4814
4814
  }
4815
4815
  };
4816
4816
  ZodString.create = (params) => {
4817
- var _a413;
4817
+ var _a415;
4818
4818
  return new ZodString({
4819
4819
  checks: [],
4820
4820
  typeName: ZodFirstPartyTypeKind.ZodString,
4821
- coerce: (_a413 = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a413 !== void 0 ? _a413 : false,
4821
+ coerce: (_a415 = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a415 !== void 0 ? _a415 : false,
4822
4822
  ...processCreateParams(params)
4823
4823
  });
4824
4824
  };
@@ -5211,11 +5211,11 @@ var init_lib = __esm({
5211
5211
  }
5212
5212
  };
5213
5213
  ZodBigInt.create = (params) => {
5214
- var _a413;
5214
+ var _a415;
5215
5215
  return new ZodBigInt({
5216
5216
  checks: [],
5217
5217
  typeName: ZodFirstPartyTypeKind.ZodBigInt,
5218
- coerce: (_a413 = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a413 !== void 0 ? _a413 : false,
5218
+ coerce: (_a415 = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a415 !== void 0 ? _a415 : false,
5219
5219
  ...processCreateParams(params)
5220
5220
  });
5221
5221
  };
@@ -5695,8 +5695,8 @@ var init_lib = __esm({
5695
5695
  unknownKeys: "strict",
5696
5696
  ...message !== void 0 ? {
5697
5697
  errorMap: (issue, ctx) => {
5698
- var _a413, _b303, _c14, _d6;
5699
- const defaultError = (_c14 = (_b303 = (_a413 = this._def).errorMap) === null || _b303 === void 0 ? void 0 : _b303.call(_a413, issue, ctx).message) !== null && _c14 !== void 0 ? _c14 : ctx.defaultError;
5698
+ var _a415, _b305, _c14, _d6;
5699
+ const defaultError = (_c14 = (_b305 = (_a415 = this._def).errorMap) === null || _b305 === void 0 ? void 0 : _b305.call(_a415, issue, ctx).message) !== null && _c14 !== void 0 ? _c14 : ctx.defaultError;
5700
5700
  if (issue.code === "unrecognized_keys")
5701
5701
  return {
5702
5702
  message: (_d6 = errorUtil.errToObj(message).message) !== null && _d6 !== void 0 ? _d6 : defaultError
@@ -12121,7 +12121,7 @@ function fromJson(statements, dialect6, action, json22) {
12121
12121
  }).filter((it) => it !== "");
12122
12122
  return result;
12123
12123
  }
12124
- var parseType, Convertor, PgCreateRoleConvertor, PgDropRoleConvertor, PgRenameRoleConvertor, PgAlterRoleConvertor, PgCreatePolicyConvertor, PgDropPolicyConvertor, PgRenamePolicyConvertor, PgAlterPolicyConvertor, PgCreateIndPolicyConvertor, PgDropIndPolicyConvertor, PgRenameIndPolicyConvertor, PgAlterIndPolicyConvertor, PgEnableRlsConvertor, PgDisableRlsConvertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SingleStoreCreateTableConvertor, SQLiteCreateTableConvertor, PgCreateViewConvertor, MySqlCreateViewConvertor, SqliteCreateViewConvertor, PgDropViewConvertor, MySqlDropViewConvertor, SqliteDropViewConvertor, MySqlAlterViewConvertor, PgRenameViewConvertor, MySqlRenameViewConvertor, PgAlterViewSchemaConvertor, PgAlterViewAddWithOptionConvertor, PgAlterViewDropWithOptionConvertor, PgAlterViewAlterTablespaceConvertor, PgAlterViewAlterUsingConvertor, PgAlterTableAlterColumnSetGenerated, PgAlterTableAlterColumnDropGenerated, PgAlterTableAlterColumnAlterGenerated, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, PgAlterTableAddCheckConstraintConvertor, PgAlterTableDeleteCheckConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, MySqlAlterTableAddCheckConstraintConvertor, SingleStoreAlterTableAddUniqueConstraintConvertor, SingleStoreAlterTableDropUniqueConstraintConvertor, MySqlAlterTableDeleteCheckConstraintConvertor, CreatePgSequenceConvertor, DropPgSequenceConvertor, RenamePgSequenceConvertor, MovePgSequenceConvertor, AlterPgSequenceConvertor, CreateTypeEnumConvertor, DropTypeEnumConvertor, AlterTypeAddValueConvertor, AlterTypeSetSchemaConvertor, AlterRenameTypeConvertor, AlterTypeDropValueConvertor, PgDropTableConvertor, MySQLDropTableConvertor, SingleStoreDropTableConvertor, SQLiteDropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, SingleStoreRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SingleStoreAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SingleStoreAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SingleStoreAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, PgAlterTableAlterColumnDropGeneratedConvertor, PgAlterTableAlterColumnSetExpressionConvertor, PgAlterTableAlterColumnAlterrGeneratedConvertor, SqliteAlterTableAlterColumnDropGeneratedConvertor, SqliteAlterTableAlterColumnSetExpressionConvertor, SqliteAlterTableAlterColumnAlterGeneratedConvertor, MySqlAlterTableAlterColumnAlterrGeneratedConvertor, MySqlAlterTableAddPk, MySqlAlterTableDropPk, LibSQLModifyColumn, MySqlModifyColumn, SingleStoreAlterTableAlterColumnAlterrGeneratedConvertor, SingleStoreAlterTableAddPk, SingleStoreAlterTableDropPk, SingleStoreModifyColumn, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetPrimaryKeyConvertor, PgAlterTableAlterColumnDropPrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, PgAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, LibSQLCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSingleStoreIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MySqlDropIndexConvertor, SingleStoreDropIndexConvertor, SQLiteRecreateTableConvertor, LibSQLRecreateTableConvertor, convertors;
12124
+ var parseType, Convertor, PgCreateRoleConvertor, PgDropRoleConvertor, PgRenameRoleConvertor, PgAlterRoleConvertor, PgCreatePolicyConvertor, PgDropPolicyConvertor, PgRenamePolicyConvertor, PgAlterPolicyConvertor, PgCreateIndPolicyConvertor, PgDropIndPolicyConvertor, PgRenameIndPolicyConvertor, PgAlterIndPolicyConvertor, PgEnableRlsConvertor, PgDisableRlsConvertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SingleStoreCreateTableConvertor, SQLiteCreateTableConvertor, PgCreateViewConvertor, MySqlCreateViewConvertor, SqliteCreateViewConvertor, PgDropViewConvertor, MySqlDropViewConvertor, SqliteDropViewConvertor, MySqlAlterViewConvertor, PgRenameViewConvertor, MySqlRenameViewConvertor, PgAlterViewSchemaConvertor, PgAlterViewAddWithOptionConvertor, PgAlterViewDropWithOptionConvertor, PgAlterViewAlterTablespaceConvertor, PgAlterViewAlterUsingConvertor, PgAlterTableAlterColumnSetGenerated, PgAlterTableAlterColumnDropGenerated, PgAlterTableAlterColumnAlterGenerated, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, PgAlterTableAddCheckConstraintConvertor, PgAlterTableDeleteCheckConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, MySqlAlterTableAddCheckConstraintConvertor, SingleStoreAlterTableAddUniqueConstraintConvertor, SingleStoreAlterTableDropUniqueConstraintConvertor, MySqlAlterTableDeleteCheckConstraintConvertor, CreatePgSequenceConvertor, DropPgSequenceConvertor, RenamePgSequenceConvertor, MovePgSequenceConvertor, AlterPgSequenceConvertor, CreateTypeEnumConvertor, DropTypeEnumConvertor, AlterTypeAddValueConvertor, AlterTypeSetSchemaConvertor, AlterRenameTypeConvertor, AlterTypeDropValueConvertor, PgDropTableConvertor, MySQLDropTableConvertor, SingleStoreDropTableConvertor, SQLiteDropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, SingleStoreRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SingleStoreAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SingleStoreAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SingleStoreAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, PgAlterTableAlterColumnDropGeneratedConvertor, PgAlterTableAlterColumnSetExpressionConvertor, PgAlterTableAlterColumnAlterrGeneratedConvertor, SqliteAlterTableAlterColumnDropGeneratedConvertor, SqliteAlterTableAlterColumnSetExpressionConvertor, SqliteAlterTableAlterColumnAlterGeneratedConvertor, MySqlAlterTableAlterColumnAlterrGeneratedConvertor, MySqlAlterTableAddPk, MySqlAlterTableDropPk, LibSQLModifyColumn, MySqlModifyColumn, SingleStoreAlterTableAlterColumnAlterrGeneratedConvertor, SingleStoreAlterTableAddPk, SingleStoreAlterTableDropPk, SingleStoreModifyColumn, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetPrimaryKeyConvertor, PgAlterTableAlterColumnDropPrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, PgAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, LibSQLCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSingleStoreIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MySqlDropIndexConvertor, SingleStoreDropIndexConvertor, SQLiteRecreateTableConvertor, LibSQLRecreateTableConvertor, SingleStoreRecreateTableConvertor, convertors;
12125
12125
  var init_sqlgenerator = __esm({
12126
12126
  "src/sqlgenerator.ts"() {
12127
12127
  "use strict";
@@ -12467,7 +12467,7 @@ var init_sqlgenerator = __esm({
12467
12467
  if (typeof compositePKs !== "undefined" && compositePKs.length > 0) {
12468
12468
  statement += ",\n";
12469
12469
  const compositePK5 = SingleStoreSquasher.unsquashPK(compositePKs[0]);
12470
- statement += ` CONSTRAINT \`${st.compositePkName}\` PRIMARY KEY(\`${compositePK5.columns.join(`\`,\``)}\`)`;
12470
+ statement += ` CONSTRAINT \`${compositePK5.name}\` PRIMARY KEY(\`${compositePK5.columns.join(`\`,\``)}\`)`;
12471
12471
  }
12472
12472
  if (typeof uniqueConstraints !== "undefined" && uniqueConstraints.length > 0) {
12473
12473
  for (const uniqueConstraint5 of uniqueConstraints) {
@@ -13122,7 +13122,7 @@ WITH ${withCheckOption} CHECK OPTION` : "";
13122
13122
  }
13123
13123
  convert(statement) {
13124
13124
  const { tableNameFrom, tableNameTo } = statement;
13125
- return `RENAME TABLE \`${tableNameFrom}\` TO \`${tableNameTo}\`;`;
13125
+ return `ALTER TABLE \`${tableNameFrom}\` RENAME TO \`${tableNameTo}\`;`;
13126
13126
  }
13127
13127
  };
13128
13128
  PgAlterTableRenameColumnConvertor = class extends Convertor {
@@ -13150,7 +13150,7 @@ WITH ${withCheckOption} CHECK OPTION` : "";
13150
13150
  }
13151
13151
  convert(statement) {
13152
13152
  const { tableName, oldColumnName, newColumnName } = statement;
13153
- return `ALTER TABLE \`${tableName}\` RENAME COLUMN \`${oldColumnName}\` TO \`${newColumnName}\`;`;
13153
+ return `ALTER TABLE \`${tableName}\` CHANGE \`${oldColumnName}\` \`${newColumnName}\`;`;
13154
13154
  }
13155
13155
  };
13156
13156
  SQLiteAlterTableRenameColumnConvertor = class extends Convertor {
@@ -14273,8 +14273,10 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${statement.newC
14273
14273
  return statement.type === "drop_index" && dialect6 === "postgresql";
14274
14274
  }
14275
14275
  convert(statement) {
14276
+ const { schema: schema5 } = statement;
14276
14277
  const { name: name2 } = PgSquasher.unsquashIdx(statement.data);
14277
- return `DROP INDEX "${name2}";`;
14278
+ const indexNameWithSchema = schema5 ? `"${schema5}"."${name2}"` : `"${name2}"`;
14279
+ return `DROP INDEX ${indexNameWithSchema};`;
14278
14280
  }
14279
14281
  };
14280
14282
  PgCreateSchemaConvertor = class extends Convertor {
@@ -14458,10 +14460,52 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${statement.newC
14458
14460
  return sqlStatements;
14459
14461
  }
14460
14462
  };
14463
+ SingleStoreRecreateTableConvertor = class extends Convertor {
14464
+ can(statement, dialect6) {
14465
+ return statement.type === "singlestore_recreate_table" && dialect6 === "singlestore";
14466
+ }
14467
+ convert(statement) {
14468
+ const { tableName, columns, compositePKs, uniqueConstraints } = statement;
14469
+ const columnNames = columns.map((it) => `\`${it.name}\``).join(", ");
14470
+ const newTableName = `__new_${tableName}`;
14471
+ const sqlStatements = [];
14472
+ sqlStatements.push(
14473
+ new SingleStoreCreateTableConvertor().convert({
14474
+ type: "create_table",
14475
+ tableName: newTableName,
14476
+ columns,
14477
+ compositePKs,
14478
+ uniqueConstraints,
14479
+ schema: ""
14480
+ })
14481
+ );
14482
+ sqlStatements.push(
14483
+ `INSERT INTO \`${newTableName}\`(${columnNames}) SELECT ${columnNames} FROM \`${tableName}\`;`
14484
+ );
14485
+ sqlStatements.push(
14486
+ new SingleStoreDropTableConvertor().convert({
14487
+ type: "drop_table",
14488
+ tableName,
14489
+ schema: ""
14490
+ })
14491
+ );
14492
+ sqlStatements.push(
14493
+ new SingleStoreRenameTableConvertor().convert({
14494
+ fromSchema: "",
14495
+ tableNameFrom: newTableName,
14496
+ tableNameTo: tableName,
14497
+ toSchema: "",
14498
+ type: "rename_table"
14499
+ })
14500
+ );
14501
+ return sqlStatements;
14502
+ }
14503
+ };
14461
14504
  convertors = [];
14462
14505
  convertors.push(new PgCreateTableConvertor());
14463
14506
  convertors.push(new MySqlCreateTableConvertor());
14464
14507
  convertors.push(new SingleStoreCreateTableConvertor());
14508
+ convertors.push(new SingleStoreRecreateTableConvertor());
14465
14509
  convertors.push(new SQLiteCreateTableConvertor());
14466
14510
  convertors.push(new SQLiteRecreateTableConvertor());
14467
14511
  convertors.push(new LibSQLRecreateTableConvertor());
@@ -16457,7 +16501,7 @@ var init_jsonStatements = __esm({
16457
16501
  });
16458
16502
 
16459
16503
  // src/statementCombiner.ts
16460
- var prepareLibSQLRecreateTable, prepareSQLiteRecreateTable, libSQLCombineStatements, sqliteCombineStatements;
16504
+ var prepareLibSQLRecreateTable, prepareSQLiteRecreateTable, libSQLCombineStatements, sqliteCombineStatements, prepareSingleStoreRecreateTable, singleStoreCombineStatements;
16461
16505
  var init_statementCombiner = __esm({
16462
16506
  "src/statementCombiner.ts"() {
16463
16507
  "use strict";
@@ -16736,6 +16780,101 @@ var init_statementCombiner = __esm({
16736
16780
  const rest = combinedStatements.filter((it) => it.type !== "rename_table" && it.type !== "alter_table_rename_column");
16737
16781
  return [...renamedTables, ...renamedColumns, ...rest];
16738
16782
  };
16783
+ prepareSingleStoreRecreateTable = (table5) => {
16784
+ const { name: name2, columns, uniqueConstraints, indexes, compositePrimaryKeys } = table5;
16785
+ const composites = Object.values(compositePrimaryKeys);
16786
+ const statements = [
16787
+ {
16788
+ type: "singlestore_recreate_table",
16789
+ tableName: name2,
16790
+ columns: Object.values(columns),
16791
+ compositePKs: composites,
16792
+ uniqueConstraints: Object.values(uniqueConstraints)
16793
+ }
16794
+ ];
16795
+ if (Object.keys(indexes).length) {
16796
+ statements.push(...prepareCreateIndexesJson(name2, "", indexes));
16797
+ }
16798
+ return statements;
16799
+ };
16800
+ singleStoreCombineStatements = (statements, json22) => {
16801
+ const newStatements = {};
16802
+ for (const statement of statements) {
16803
+ if (statement.type === "alter_table_alter_column_set_type" || statement.type === "alter_table_alter_column_set_notnull" || statement.type === "alter_table_alter_column_drop_notnull" || statement.type === "alter_table_alter_column_drop_autoincrement" || statement.type === "alter_table_alter_column_set_autoincrement" || statement.type === "alter_table_alter_column_drop_pk" || statement.type === "alter_table_alter_column_set_pk" || statement.type === "create_composite_pk" || statement.type === "alter_composite_pk" || statement.type === "delete_composite_pk") {
16804
+ const tableName2 = statement.tableName;
16805
+ const statementsForTable2 = newStatements[tableName2];
16806
+ if (!statementsForTable2) {
16807
+ newStatements[tableName2] = prepareSingleStoreRecreateTable(json22.tables[tableName2]);
16808
+ continue;
16809
+ }
16810
+ if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
16811
+ const wasRename = statementsForTable2.some(
16812
+ ({ type }) => type === "rename_table" || type === "alter_table_rename_column"
16813
+ );
16814
+ const preparedStatements = prepareSingleStoreRecreateTable(json22.tables[tableName2]);
16815
+ if (wasRename) {
16816
+ newStatements[tableName2].push(...preparedStatements);
16817
+ } else {
16818
+ newStatements[tableName2] = preparedStatements;
16819
+ }
16820
+ continue;
16821
+ }
16822
+ continue;
16823
+ }
16824
+ if ((statement.type === "alter_table_alter_column_drop_default" || statement.type === "alter_table_alter_column_set_default") && statement.columnNotNull) {
16825
+ const tableName2 = statement.tableName;
16826
+ const statementsForTable2 = newStatements[tableName2];
16827
+ if (!statementsForTable2) {
16828
+ newStatements[tableName2] = prepareSingleStoreRecreateTable(json22.tables[tableName2]);
16829
+ continue;
16830
+ }
16831
+ if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
16832
+ const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
16833
+ const preparedStatements = prepareSingleStoreRecreateTable(json22.tables[tableName2]);
16834
+ if (wasRename) {
16835
+ newStatements[tableName2].push(...preparedStatements);
16836
+ } else {
16837
+ newStatements[tableName2] = preparedStatements;
16838
+ }
16839
+ continue;
16840
+ }
16841
+ continue;
16842
+ }
16843
+ if (statement.type === "alter_table_add_column" && statement.column.primaryKey) {
16844
+ const tableName2 = statement.tableName;
16845
+ const statementsForTable2 = newStatements[tableName2];
16846
+ if (!statementsForTable2) {
16847
+ newStatements[tableName2] = prepareSingleStoreRecreateTable(json22.tables[tableName2]);
16848
+ continue;
16849
+ }
16850
+ if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
16851
+ const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
16852
+ const preparedStatements = prepareSingleStoreRecreateTable(json22.tables[tableName2]);
16853
+ if (wasRename) {
16854
+ newStatements[tableName2].push(...preparedStatements);
16855
+ } else {
16856
+ newStatements[tableName2] = preparedStatements;
16857
+ }
16858
+ continue;
16859
+ }
16860
+ continue;
16861
+ }
16862
+ const tableName = statement.type === "rename_table" ? statement.tableNameTo : statement.tableName;
16863
+ const statementsForTable = newStatements[tableName];
16864
+ if (!statementsForTable) {
16865
+ newStatements[tableName] = [statement];
16866
+ continue;
16867
+ }
16868
+ if (!statementsForTable.some(({ type }) => type === "singlestore_recreate_table")) {
16869
+ newStatements[tableName].push(statement);
16870
+ }
16871
+ }
16872
+ const combinedStatements = Object.values(newStatements).flat();
16873
+ const renamedTables = combinedStatements.filter((it) => it.type === "rename_table");
16874
+ const renamedColumns = combinedStatements.filter((it) => it.type === "alter_table_rename_column");
16875
+ const rest = combinedStatements.filter((it) => it.type !== "rename_table" && it.type !== "alter_table_rename_column");
16876
+ return [...renamedTables, ...renamedColumns, ...rest];
16877
+ };
16739
16878
  }
16740
16879
  });
16741
16880
 
@@ -18681,7 +18820,7 @@ var init_snapshotsDiffer = __esm({
18681
18820
  return [tableKey2, tableValue];
18682
18821
  }
18683
18822
  );
18684
- const diffResult = applyJsonDiff(tablesPatchedSnap1, json22);
18823
+ const diffResult = applyJsonDiff(columnsPatchedSnap1, json22);
18685
18824
  const typedResult = diffResultSchemeSingleStore.parse(diffResult);
18686
18825
  const jsonStatements = [];
18687
18826
  const jsonCreateIndexesForCreatedTables = createdTables.map((it) => {
@@ -18845,7 +18984,8 @@ var init_snapshotsDiffer = __esm({
18845
18984
  jsonStatements.push(...jsonDropColumnsStatemets);
18846
18985
  jsonStatements.push(...jsonAddedCompositePKs);
18847
18986
  jsonStatements.push(...jsonAlteredUniqueConstraints);
18848
- const sqlStatements = fromJson(jsonStatements, "singlestore");
18987
+ const combinedJsonStatements = singleStoreCombineStatements(jsonStatements, json22);
18988
+ const sqlStatements = fromJson(combinedJsonStatements, "singlestore");
18849
18989
  const uniqueSqlStatements = [];
18850
18990
  sqlStatements.forEach((ss) => {
18851
18991
  if (!uniqueSqlStatements.includes(ss)) {
@@ -18857,7 +18997,7 @@ var init_snapshotsDiffer = __esm({
18857
18997
  });
18858
18998
  const _meta = prepareMigrationMeta([], rTables, rColumns);
18859
18999
  return {
18860
- statements: jsonStatements,
19000
+ statements: combinedJsonStatements,
18861
19001
  sqlStatements: uniqueSqlStatements,
18862
19002
  _meta
18863
19003
  };
@@ -21975,7 +22115,7 @@ var version;
21975
22115
  var init_version = __esm({
21976
22116
  "../drizzle-orm/dist/version.js"() {
21977
22117
  "use strict";
21978
- version = "0.38.3";
22118
+ version = "0.38.4";
21979
22119
  }
21980
22120
  });
21981
22121
 
@@ -22163,6 +22303,9 @@ function fillPlaceholders(params, values) {
22163
22303
  function isView(view4) {
22164
22304
  return typeof view4 === "object" && view4 !== null && IsDrizzleView in view4;
22165
22305
  }
22306
+ function getViewName(view4) {
22307
+ return view4[ViewBaseConfig].name;
22308
+ }
22166
22309
  var _a19, FakePrimitiveParam, _a20, StringChunk, _a21, _SQL, SQL, _a22, Name, noopDecoder, noopEncoder, noopMapper, _a23, Param, _a24, Placeholder, IsDrizzleView, _a25, _b10, _c2, View3;
22167
22310
  var init_sql = __esm({
22168
22311
  "../drizzle-orm/dist/sql/sql.js"() {
@@ -22457,8 +22600,8 @@ var init_sql = __esm({
22457
22600
  sql2.param = param2;
22458
22601
  })(sql || (sql = {}));
22459
22602
  ((SQL2) => {
22460
- var _a413;
22461
- _a413 = entityKind;
22603
+ var _a415;
22604
+ _a415 = entityKind;
22462
22605
  const _Aliased = class _Aliased {
22463
22606
  constructor(sql2, fieldAlias) {
22464
22607
  /** @internal */
@@ -22474,7 +22617,7 @@ var init_sql = __esm({
22474
22617
  return new _Aliased(this.sql, this.fieldAlias);
22475
22618
  }
22476
22619
  };
22477
- __publicField(_Aliased, _a413, "SQL.Aliased");
22620
+ __publicField(_Aliased, _a415, "SQL.Aliased");
22478
22621
  let Aliased = _Aliased;
22479
22622
  SQL2.Aliased = Aliased;
22480
22623
  })(SQL || (SQL = {}));
@@ -25289,6 +25432,7 @@ __export(dist_exports, {
25289
25432
  getTableLikeName: () => getTableLikeName,
25290
25433
  getTableName: () => getTableName,
25291
25434
  getTableUniqueName: () => getTableUniqueName,
25435
+ getViewName: () => getViewName,
25292
25436
  getViewSelectedFields: () => getViewSelectedFields,
25293
25437
  gt: () => gt,
25294
25438
  gte: () => gte,
@@ -25443,17 +25587,100 @@ var init_columns = __esm({
25443
25587
  }
25444
25588
  });
25445
25589
 
25590
+ // ../drizzle-orm/dist/selection-proxy.js
25591
+ var _a124, _SelectionProxyHandler, SelectionProxyHandler;
25592
+ var init_selection_proxy = __esm({
25593
+ "../drizzle-orm/dist/selection-proxy.js"() {
25594
+ "use strict";
25595
+ init_alias();
25596
+ init_column();
25597
+ init_entity();
25598
+ init_sql();
25599
+ init_subquery();
25600
+ init_view_common();
25601
+ _a124 = entityKind;
25602
+ _SelectionProxyHandler = class _SelectionProxyHandler {
25603
+ constructor(config) {
25604
+ __publicField(this, "config");
25605
+ this.config = { ...config };
25606
+ }
25607
+ get(subquery, prop) {
25608
+ if (prop === "_") {
25609
+ return {
25610
+ ...subquery["_"],
25611
+ selectedFields: new Proxy(
25612
+ subquery._.selectedFields,
25613
+ this
25614
+ )
25615
+ };
25616
+ }
25617
+ if (prop === ViewBaseConfig) {
25618
+ return {
25619
+ ...subquery[ViewBaseConfig],
25620
+ selectedFields: new Proxy(
25621
+ subquery[ViewBaseConfig].selectedFields,
25622
+ this
25623
+ )
25624
+ };
25625
+ }
25626
+ if (typeof prop === "symbol") {
25627
+ return subquery[prop];
25628
+ }
25629
+ const columns = is(subquery, Subquery) ? subquery._.selectedFields : is(subquery, View3) ? subquery[ViewBaseConfig].selectedFields : subquery;
25630
+ const value = columns[prop];
25631
+ if (is(value, SQL.Aliased)) {
25632
+ if (this.config.sqlAliasedBehavior === "sql" && !value.isSelectionField) {
25633
+ return value.sql;
25634
+ }
25635
+ const newValue = value.clone();
25636
+ newValue.isSelectionField = true;
25637
+ return newValue;
25638
+ }
25639
+ if (is(value, SQL)) {
25640
+ if (this.config.sqlBehavior === "sql") {
25641
+ return value;
25642
+ }
25643
+ throw new Error(
25644
+ `You tried to reference "${prop}" field from a subquery, which is a raw SQL field, but it doesn't have an alias declared. Please add an alias to the field using ".as('alias')" method.`
25645
+ );
25646
+ }
25647
+ if (is(value, Column2)) {
25648
+ if (this.config.alias) {
25649
+ return new Proxy(
25650
+ value,
25651
+ new ColumnAliasProxyHandler(
25652
+ new Proxy(
25653
+ value.table,
25654
+ new TableAliasProxyHandler(this.config.alias, this.config.replaceOriginalName ?? false)
25655
+ )
25656
+ )
25657
+ );
25658
+ }
25659
+ return value;
25660
+ }
25661
+ if (typeof value !== "object" || value === null) {
25662
+ return value;
25663
+ }
25664
+ return new Proxy(value, new _SelectionProxyHandler(this.config));
25665
+ }
25666
+ };
25667
+ __publicField(_SelectionProxyHandler, _a124, "SelectionProxyHandler");
25668
+ SelectionProxyHandler = _SelectionProxyHandler;
25669
+ }
25670
+ });
25671
+
25446
25672
  // ../drizzle-orm/dist/pg-core/query-builders/delete.js
25447
- var _a124, _b97, PgDeleteBase;
25673
+ var _a125, _b97, PgDeleteBase;
25448
25674
  var init_delete = __esm({
25449
25675
  "../drizzle-orm/dist/pg-core/query-builders/delete.js"() {
25450
25676
  "use strict";
25451
25677
  init_entity();
25452
25678
  init_query_promise();
25679
+ init_selection_proxy();
25453
25680
  init_table();
25454
25681
  init_tracing();
25455
25682
  init_utils2();
25456
- PgDeleteBase = class extends (_b97 = QueryPromise, _a124 = entityKind, _b97) {
25683
+ PgDeleteBase = class extends (_b97 = QueryPromise, _a125 = entityKind, _b97) {
25457
25684
  constructor(table5, session, dialect6, withList) {
25458
25685
  super();
25459
25686
  __publicField(this, "config");
@@ -25501,6 +25728,7 @@ var init_delete = __esm({
25501
25728
  return this;
25502
25729
  }
25503
25730
  returning(fields = this.config.table[Table2.Symbol.Columns]) {
25731
+ this.config.returningFields = fields;
25504
25732
  this.config.returning = orderSelectedFields(fields);
25505
25733
  return this;
25506
25734
  }
@@ -25526,11 +25754,22 @@ var init_delete = __esm({
25526
25754
  this.authToken = token;
25527
25755
  return this;
25528
25756
  }
25757
+ /** @internal */
25758
+ getSelectedFields() {
25759
+ return this.config.returningFields ? new Proxy(
25760
+ this.config.returningFields,
25761
+ new SelectionProxyHandler({
25762
+ alias: getTableName(this.config.table),
25763
+ sqlAliasedBehavior: "alias",
25764
+ sqlBehavior: "error"
25765
+ })
25766
+ ) : void 0;
25767
+ }
25529
25768
  $dynamic() {
25530
25769
  return this;
25531
25770
  }
25532
25771
  };
25533
- __publicField(PgDeleteBase, _a124, "PgDelete");
25772
+ __publicField(PgDeleteBase, _a125, "PgDelete");
25534
25773
  }
25535
25774
  });
25536
25775
 
@@ -25549,13 +25788,13 @@ function toCamelCase(input) {
25549
25788
  function noopCase(input) {
25550
25789
  return input;
25551
25790
  }
25552
- var _a125, CasingCache;
25791
+ var _a126, CasingCache;
25553
25792
  var init_casing = __esm({
25554
25793
  "../drizzle-orm/dist/casing.js"() {
25555
25794
  "use strict";
25556
25795
  init_entity();
25557
25796
  init_table();
25558
- _a125 = entityKind;
25797
+ _a126 = entityKind;
25559
25798
  CasingCache = class {
25560
25799
  constructor(casing2) {
25561
25800
  /** @internal */
@@ -25592,25 +25831,25 @@ var init_casing = __esm({
25592
25831
  this.cachedTables = {};
25593
25832
  }
25594
25833
  };
25595
- __publicField(CasingCache, _a125, "CasingCache");
25834
+ __publicField(CasingCache, _a126, "CasingCache");
25596
25835
  }
25597
25836
  });
25598
25837
 
25599
25838
  // ../drizzle-orm/dist/pg-core/view-base.js
25600
- var _a126, _b98, PgViewBase;
25839
+ var _a127, _b98, PgViewBase;
25601
25840
  var init_view_base = __esm({
25602
25841
  "../drizzle-orm/dist/pg-core/view-base.js"() {
25603
25842
  "use strict";
25604
25843
  init_entity();
25605
25844
  init_sql();
25606
- PgViewBase = class extends (_b98 = View3, _a126 = entityKind, _b98) {
25845
+ PgViewBase = class extends (_b98 = View3, _a127 = entityKind, _b98) {
25607
25846
  };
25608
- __publicField(PgViewBase, _a126, "PgViewBase");
25847
+ __publicField(PgViewBase, _a127, "PgViewBase");
25609
25848
  }
25610
25849
  });
25611
25850
 
25612
25851
  // ../drizzle-orm/dist/pg-core/dialect.js
25613
- var _a127, PgDialect;
25852
+ var _a128, PgDialect;
25614
25853
  var init_dialect = __esm({
25615
25854
  "../drizzle-orm/dist/pg-core/dialect.js"() {
25616
25855
  "use strict";
@@ -25629,7 +25868,7 @@ var init_dialect = __esm({
25629
25868
  init_utils2();
25630
25869
  init_view_common();
25631
25870
  init_view_base();
25632
- _a127 = entityKind;
25871
+ _a128 = entityKind;
25633
25872
  PgDialect = class {
25634
25873
  constructor(config) {
25635
25874
  /** @internal */
@@ -26721,89 +26960,7 @@ var init_dialect = __esm({
26721
26960
  };
26722
26961
  }
26723
26962
  };
26724
- __publicField(PgDialect, _a127, "PgDialect");
26725
- }
26726
- });
26727
-
26728
- // ../drizzle-orm/dist/selection-proxy.js
26729
- var _a128, _SelectionProxyHandler, SelectionProxyHandler;
26730
- var init_selection_proxy = __esm({
26731
- "../drizzle-orm/dist/selection-proxy.js"() {
26732
- "use strict";
26733
- init_alias();
26734
- init_column();
26735
- init_entity();
26736
- init_sql();
26737
- init_subquery();
26738
- init_view_common();
26739
- _a128 = entityKind;
26740
- _SelectionProxyHandler = class _SelectionProxyHandler {
26741
- constructor(config) {
26742
- __publicField(this, "config");
26743
- this.config = { ...config };
26744
- }
26745
- get(subquery, prop) {
26746
- if (prop === "_") {
26747
- return {
26748
- ...subquery["_"],
26749
- selectedFields: new Proxy(
26750
- subquery._.selectedFields,
26751
- this
26752
- )
26753
- };
26754
- }
26755
- if (prop === ViewBaseConfig) {
26756
- return {
26757
- ...subquery[ViewBaseConfig],
26758
- selectedFields: new Proxy(
26759
- subquery[ViewBaseConfig].selectedFields,
26760
- this
26761
- )
26762
- };
26763
- }
26764
- if (typeof prop === "symbol") {
26765
- return subquery[prop];
26766
- }
26767
- const columns = is(subquery, Subquery) ? subquery._.selectedFields : is(subquery, View3) ? subquery[ViewBaseConfig].selectedFields : subquery;
26768
- const value = columns[prop];
26769
- if (is(value, SQL.Aliased)) {
26770
- if (this.config.sqlAliasedBehavior === "sql" && !value.isSelectionField) {
26771
- return value.sql;
26772
- }
26773
- const newValue = value.clone();
26774
- newValue.isSelectionField = true;
26775
- return newValue;
26776
- }
26777
- if (is(value, SQL)) {
26778
- if (this.config.sqlBehavior === "sql") {
26779
- return value;
26780
- }
26781
- throw new Error(
26782
- `You tried to reference "${prop}" field from a subquery, which is a raw SQL field, but it doesn't have an alias declared. Please add an alias to the field using ".as('alias')" method.`
26783
- );
26784
- }
26785
- if (is(value, Column2)) {
26786
- if (this.config.alias) {
26787
- return new Proxy(
26788
- value,
26789
- new ColumnAliasProxyHandler(
26790
- new Proxy(
26791
- value.table,
26792
- new TableAliasProxyHandler(this.config.alias, this.config.replaceOriginalName ?? false)
26793
- )
26794
- )
26795
- );
26796
- }
26797
- return value;
26798
- }
26799
- if (typeof value !== "object" || value === null) {
26800
- return value;
26801
- }
26802
- return new Proxy(value, new _SelectionProxyHandler(this.config));
26803
- }
26804
- };
26805
- __publicField(_SelectionProxyHandler, _a128, "SelectionProxyHandler");
26806
- SelectionProxyHandler = _SelectionProxyHandler;
26963
+ __publicField(PgDialect, _a128, "PgDialect");
26807
26964
  }
26808
26965
  });
26809
26966
 
@@ -26888,22 +27045,23 @@ var init_select2 = __esm({
26888
27045
  */
26889
27046
  from(source) {
26890
27047
  const isPartialSelect = !!this.fields;
27048
+ const src = source;
26891
27049
  let fields;
26892
27050
  if (this.fields) {
26893
27051
  fields = this.fields;
26894
- } else if (is(source, Subquery)) {
27052
+ } else if (is(src, Subquery)) {
26895
27053
  fields = Object.fromEntries(
26896
- Object.keys(source._.selectedFields).map((key) => [key, source[key]])
27054
+ Object.keys(src._.selectedFields).map((key) => [key, src[key]])
26897
27055
  );
26898
- } else if (is(source, PgViewBase)) {
26899
- fields = source[ViewBaseConfig].selectedFields;
26900
- } else if (is(source, SQL)) {
27056
+ } else if (is(src, PgViewBase)) {
27057
+ fields = src[ViewBaseConfig].selectedFields;
27058
+ } else if (is(src, SQL)) {
26901
27059
  fields = {};
26902
27060
  } else {
26903
- fields = getTableColumns(source);
27061
+ fields = getTableColumns(src);
26904
27062
  }
26905
27063
  return new PgSelectBase({
26906
- table: source,
27064
+ table: src,
26907
27065
  fields,
26908
27066
  isPartialSelect,
26909
27067
  session: this.session,
@@ -27588,22 +27746,26 @@ var init_query_builder2 = __esm({
27588
27746
  constructor(dialect6) {
27589
27747
  __publicField(this, "dialect");
27590
27748
  __publicField(this, "dialectConfig");
27591
- this.dialect = is(dialect6, PgDialect) ? dialect6 : void 0;
27592
- this.dialectConfig = is(dialect6, PgDialect) ? void 0 : dialect6;
27593
- }
27594
- $with(alias) {
27595
- const queryBuilder = this;
27596
- return {
27597
- as(qb) {
27749
+ __publicField(this, "$with", (alias, selection) => {
27750
+ const queryBuilder = this;
27751
+ const as = (qb) => {
27598
27752
  if (typeof qb === "function") {
27599
27753
  qb = qb(queryBuilder);
27600
27754
  }
27601
27755
  return new Proxy(
27602
- new WithSubquery(qb.getSQL(), qb.getSelectedFields(), alias, true),
27756
+ new WithSubquery(
27757
+ qb.getSQL(),
27758
+ selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}),
27759
+ alias,
27760
+ true
27761
+ ),
27603
27762
  new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
27604
27763
  );
27605
- }
27606
- };
27764
+ };
27765
+ return { as };
27766
+ });
27767
+ this.dialect = is(dialect6, PgDialect) ? dialect6 : void 0;
27768
+ this.dialectConfig = is(dialect6, PgDialect) ? void 0 : dialect6;
27607
27769
  }
27608
27770
  with(...queries) {
27609
27771
  const self2 = this;
@@ -27675,6 +27837,7 @@ var init_insert = __esm({
27675
27837
  "use strict";
27676
27838
  init_entity();
27677
27839
  init_query_promise();
27840
+ init_selection_proxy();
27678
27841
  init_sql();
27679
27842
  init_table();
27680
27843
  init_tracing();
@@ -27749,6 +27912,7 @@ var init_insert = __esm({
27749
27912
  this.config = { table: table5, values, withList, select, overridingSystemValue_ };
27750
27913
  }
27751
27914
  returning(fields = this.config.table[Table2.Symbol.Columns]) {
27915
+ this.config.returningFields = fields;
27752
27916
  this.config.returning = orderSelectedFields(fields);
27753
27917
  return this;
27754
27918
  }
@@ -27851,6 +28015,17 @@ var init_insert = __esm({
27851
28015
  this.authToken = token;
27852
28016
  return this;
27853
28017
  }
28018
+ /** @internal */
28019
+ getSelectedFields() {
28020
+ return this.config.returningFields ? new Proxy(
28021
+ this.config.returningFields,
28022
+ new SelectionProxyHandler({
28023
+ alias: getTableName(this.config.table),
28024
+ sqlAliasedBehavior: "alias",
28025
+ sqlBehavior: "error"
28026
+ })
28027
+ ) : void 0;
28028
+ }
27854
28029
  $dynamic() {
27855
28030
  return this;
27856
28031
  }
@@ -27988,11 +28163,12 @@ var init_update = __esm({
27988
28163
  this.joinsNotNullableMap = typeof this.tableName === "string" ? { [this.tableName]: true } : {};
27989
28164
  }
27990
28165
  from(source) {
27991
- const tableName = getTableLikeName(source);
28166
+ const src = source;
28167
+ const tableName = getTableLikeName(src);
27992
28168
  if (typeof tableName === "string") {
27993
28169
  this.joinsNotNullableMap[tableName] = true;
27994
28170
  }
27995
- this.config.from = source;
28171
+ this.config.from = src;
27996
28172
  return this;
27997
28173
  }
27998
28174
  getTableLikeFields(table5) {
@@ -28107,6 +28283,7 @@ var init_update = __esm({
28107
28283
  }
28108
28284
  }
28109
28285
  }
28286
+ this.config.returningFields = fields;
28110
28287
  this.config.returning = orderSelectedFields(fields);
28111
28288
  return this;
28112
28289
  }
@@ -28132,6 +28309,17 @@ var init_update = __esm({
28132
28309
  this.authToken = token;
28133
28310
  return this;
28134
28311
  }
28312
+ /** @internal */
28313
+ getSelectedFields() {
28314
+ return this.config.returningFields ? new Proxy(
28315
+ this.config.returningFields,
28316
+ new SelectionProxyHandler({
28317
+ alias: getTableName(this.config.table),
28318
+ sqlAliasedBehavior: "alias",
28319
+ sqlBehavior: "error"
28320
+ })
28321
+ ) : void 0;
28322
+ }
28135
28323
  $dynamic() {
28136
28324
  return this;
28137
28325
  }
@@ -28393,6 +28581,56 @@ var init_db = __esm({
28393
28581
  PgDatabase = class {
28394
28582
  constructor(dialect6, session, schema5) {
28395
28583
  __publicField(this, "query");
28584
+ /**
28585
+ * Creates a subquery that defines a temporary named result set as a CTE.
28586
+ *
28587
+ * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.
28588
+ *
28589
+ * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
28590
+ *
28591
+ * @param alias The alias for the subquery.
28592
+ *
28593
+ * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.
28594
+ *
28595
+ * @example
28596
+ *
28597
+ * ```ts
28598
+ * // Create a subquery with alias 'sq' and use it in the select query
28599
+ * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
28600
+ *
28601
+ * const result = await db.with(sq).select().from(sq);
28602
+ * ```
28603
+ *
28604
+ * To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:
28605
+ *
28606
+ * ```ts
28607
+ * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query
28608
+ * const sq = db.$with('sq').as(db.select({
28609
+ * name: sql<string>`upper(${users.name})`.as('name'),
28610
+ * })
28611
+ * .from(users));
28612
+ *
28613
+ * const result = await db.with(sq).select({ name: sq.name }).from(sq);
28614
+ * ```
28615
+ */
28616
+ __publicField(this, "$with", (alias, selection) => {
28617
+ const self2 = this;
28618
+ const as = (qb) => {
28619
+ if (typeof qb === "function") {
28620
+ qb = qb(new QueryBuilder(self2.dialect));
28621
+ }
28622
+ return new Proxy(
28623
+ new WithSubquery(
28624
+ qb.getSQL(),
28625
+ selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}),
28626
+ alias,
28627
+ true
28628
+ ),
28629
+ new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
28630
+ );
28631
+ };
28632
+ return { as };
28633
+ });
28396
28634
  __publicField(this, "authToken");
28397
28635
  this.dialect = dialect6;
28398
28636
  this.session = session;
@@ -28422,52 +28660,6 @@ var init_db = __esm({
28422
28660
  }
28423
28661
  }
28424
28662
  }
28425
- /**
28426
- * Creates a subquery that defines a temporary named result set as a CTE.
28427
- *
28428
- * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.
28429
- *
28430
- * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
28431
- *
28432
- * @param alias The alias for the subquery.
28433
- *
28434
- * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.
28435
- *
28436
- * @example
28437
- *
28438
- * ```ts
28439
- * // Create a subquery with alias 'sq' and use it in the select query
28440
- * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
28441
- *
28442
- * const result = await db.with(sq).select().from(sq);
28443
- * ```
28444
- *
28445
- * To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:
28446
- *
28447
- * ```ts
28448
- * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query
28449
- * const sq = db.$with('sq').as(db.select({
28450
- * name: sql<string>`upper(${users.name})`.as('name'),
28451
- * })
28452
- * .from(users));
28453
- *
28454
- * const result = await db.with(sq).select({ name: sq.name }).from(sq);
28455
- * ```
28456
- */
28457
- $with(alias) {
28458
- const self2 = this;
28459
- return {
28460
- as(qb) {
28461
- if (typeof qb === "function") {
28462
- qb = qb(new QueryBuilder(self2.dialect));
28463
- }
28464
- return new Proxy(
28465
- new WithSubquery(qb.getSQL(), qb.getSelectedFields(), alias, true),
28466
- new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
28467
- );
28468
- }
28469
- };
28470
- }
28471
28663
  $count(source, filters) {
28472
28664
  return new PgCountBuilder({ source, filters, session: this.session });
28473
28665
  }
@@ -33218,22 +33410,26 @@ var init_query_builder3 = __esm({
33218
33410
  constructor(dialect6) {
33219
33411
  __publicField(this, "dialect");
33220
33412
  __publicField(this, "dialectConfig");
33221
- this.dialect = is(dialect6, SQLiteDialect) ? dialect6 : void 0;
33222
- this.dialectConfig = is(dialect6, SQLiteDialect) ? void 0 : dialect6;
33223
- }
33224
- $with(alias) {
33225
- const queryBuilder = this;
33226
- return {
33227
- as(qb) {
33413
+ __publicField(this, "$with", (alias, selection) => {
33414
+ const queryBuilder = this;
33415
+ const as = (qb) => {
33228
33416
  if (typeof qb === "function") {
33229
33417
  qb = qb(queryBuilder);
33230
33418
  }
33231
33419
  return new Proxy(
33232
- new WithSubquery(qb.getSQL(), qb.getSelectedFields(), alias, true),
33420
+ new WithSubquery(
33421
+ qb.getSQL(),
33422
+ selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}),
33423
+ alias,
33424
+ true
33425
+ ),
33233
33426
  new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
33234
33427
  );
33235
- }
33236
- };
33428
+ };
33429
+ return { as };
33430
+ });
33431
+ this.dialect = is(dialect6, SQLiteDialect) ? dialect6 : void 0;
33432
+ this.dialectConfig = is(dialect6, SQLiteDialect) ? void 0 : dialect6;
33237
33433
  }
33238
33434
  with(...queries) {
33239
33435
  const self2 = this;
@@ -33914,6 +34110,56 @@ var init_db2 = __esm({
33914
34110
  BaseSQLiteDatabase = class {
33915
34111
  constructor(resultKind, dialect6, session, schema5) {
33916
34112
  __publicField(this, "query");
34113
+ /**
34114
+ * Creates a subquery that defines a temporary named result set as a CTE.
34115
+ *
34116
+ * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.
34117
+ *
34118
+ * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
34119
+ *
34120
+ * @param alias The alias for the subquery.
34121
+ *
34122
+ * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.
34123
+ *
34124
+ * @example
34125
+ *
34126
+ * ```ts
34127
+ * // Create a subquery with alias 'sq' and use it in the select query
34128
+ * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
34129
+ *
34130
+ * const result = await db.with(sq).select().from(sq);
34131
+ * ```
34132
+ *
34133
+ * To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:
34134
+ *
34135
+ * ```ts
34136
+ * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query
34137
+ * const sq = db.$with('sq').as(db.select({
34138
+ * name: sql<string>`upper(${users.name})`.as('name'),
34139
+ * })
34140
+ * .from(users));
34141
+ *
34142
+ * const result = await db.with(sq).select({ name: sq.name }).from(sq);
34143
+ * ```
34144
+ */
34145
+ __publicField(this, "$with", (alias, selection) => {
34146
+ const self2 = this;
34147
+ const as = (qb) => {
34148
+ if (typeof qb === "function") {
34149
+ qb = qb(new QueryBuilder2(self2.dialect));
34150
+ }
34151
+ return new Proxy(
34152
+ new WithSubquery(
34153
+ qb.getSQL(),
34154
+ selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}),
34155
+ alias,
34156
+ true
34157
+ ),
34158
+ new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
34159
+ );
34160
+ };
34161
+ return { as };
34162
+ });
33917
34163
  this.resultKind = resultKind;
33918
34164
  this.dialect = dialect6;
33919
34165
  this.session = session;
@@ -33943,52 +34189,6 @@ var init_db2 = __esm({
33943
34189
  }
33944
34190
  }
33945
34191
  }
33946
- /**
33947
- * Creates a subquery that defines a temporary named result set as a CTE.
33948
- *
33949
- * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.
33950
- *
33951
- * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
33952
- *
33953
- * @param alias The alias for the subquery.
33954
- *
33955
- * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.
33956
- *
33957
- * @example
33958
- *
33959
- * ```ts
33960
- * // Create a subquery with alias 'sq' and use it in the select query
33961
- * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
33962
- *
33963
- * const result = await db.with(sq).select().from(sq);
33964
- * ```
33965
- *
33966
- * To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:
33967
- *
33968
- * ```ts
33969
- * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query
33970
- * const sq = db.$with('sq').as(db.select({
33971
- * name: sql<string>`upper(${users.name})`.as('name'),
33972
- * })
33973
- * .from(users));
33974
- *
33975
- * const result = await db.with(sq).select({ name: sq.name }).from(sq);
33976
- * ```
33977
- */
33978
- $with(alias) {
33979
- const self2 = this;
33980
- return {
33981
- as(qb) {
33982
- if (typeof qb === "function") {
33983
- qb = qb(new QueryBuilder2(self2.dialect));
33984
- }
33985
- return new Proxy(
33986
- new WithSubquery(qb.getSQL(), qb.getSelectedFields(), alias, true),
33987
- new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
33988
- );
33989
- }
33990
- };
33991
- }
33992
34192
  $count(source, filters) {
33993
34193
  return new SQLiteCountBuilder({ source, filters, session: this.session });
33994
34194
  }
@@ -38811,22 +39011,26 @@ var init_query_builder4 = __esm({
38811
39011
  constructor(dialect6) {
38812
39012
  __publicField(this, "dialect");
38813
39013
  __publicField(this, "dialectConfig");
38814
- this.dialect = is(dialect6, MySqlDialect) ? dialect6 : void 0;
38815
- this.dialectConfig = is(dialect6, MySqlDialect) ? void 0 : dialect6;
38816
- }
38817
- $with(alias) {
38818
- const queryBuilder = this;
38819
- return {
38820
- as(qb) {
39014
+ __publicField(this, "$with", (alias, selection) => {
39015
+ const queryBuilder = this;
39016
+ const as = (qb) => {
38821
39017
  if (typeof qb === "function") {
38822
39018
  qb = qb(queryBuilder);
38823
39019
  }
38824
39020
  return new Proxy(
38825
- new WithSubquery(qb.getSQL(), qb.getSelectedFields(), alias, true),
39021
+ new WithSubquery(
39022
+ qb.getSQL(),
39023
+ selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}),
39024
+ alias,
39025
+ true
39026
+ ),
38826
39027
  new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
38827
39028
  );
38828
- }
38829
- };
39029
+ };
39030
+ return { as };
39031
+ });
39032
+ this.dialect = is(dialect6, MySqlDialect) ? dialect6 : void 0;
39033
+ this.dialectConfig = is(dialect6, MySqlDialect) ? void 0 : dialect6;
38830
39034
  }
38831
39035
  with(...queries) {
38832
39036
  const self2 = this;
@@ -39281,6 +39485,56 @@ var init_db3 = __esm({
39281
39485
  MySqlDatabase = class {
39282
39486
  constructor(dialect6, session, schema5, mode) {
39283
39487
  __publicField(this, "query");
39488
+ /**
39489
+ * Creates a subquery that defines a temporary named result set as a CTE.
39490
+ *
39491
+ * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.
39492
+ *
39493
+ * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
39494
+ *
39495
+ * @param alias The alias for the subquery.
39496
+ *
39497
+ * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.
39498
+ *
39499
+ * @example
39500
+ *
39501
+ * ```ts
39502
+ * // Create a subquery with alias 'sq' and use it in the select query
39503
+ * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
39504
+ *
39505
+ * const result = await db.with(sq).select().from(sq);
39506
+ * ```
39507
+ *
39508
+ * To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:
39509
+ *
39510
+ * ```ts
39511
+ * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query
39512
+ * const sq = db.$with('sq').as(db.select({
39513
+ * name: sql<string>`upper(${users.name})`.as('name'),
39514
+ * })
39515
+ * .from(users));
39516
+ *
39517
+ * const result = await db.with(sq).select({ name: sq.name }).from(sq);
39518
+ * ```
39519
+ */
39520
+ __publicField(this, "$with", (alias, selection) => {
39521
+ const self2 = this;
39522
+ const as = (qb) => {
39523
+ if (typeof qb === "function") {
39524
+ qb = qb(new QueryBuilder3(self2.dialect));
39525
+ }
39526
+ return new Proxy(
39527
+ new WithSubquery(
39528
+ qb.getSQL(),
39529
+ selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}),
39530
+ alias,
39531
+ true
39532
+ ),
39533
+ new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
39534
+ );
39535
+ };
39536
+ return { as };
39537
+ });
39284
39538
  this.dialect = dialect6;
39285
39539
  this.session = session;
39286
39540
  this.mode = mode;
@@ -39309,52 +39563,6 @@ var init_db3 = __esm({
39309
39563
  }
39310
39564
  }
39311
39565
  }
39312
- /**
39313
- * Creates a subquery that defines a temporary named result set as a CTE.
39314
- *
39315
- * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.
39316
- *
39317
- * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
39318
- *
39319
- * @param alias The alias for the subquery.
39320
- *
39321
- * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.
39322
- *
39323
- * @example
39324
- *
39325
- * ```ts
39326
- * // Create a subquery with alias 'sq' and use it in the select query
39327
- * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
39328
- *
39329
- * const result = await db.with(sq).select().from(sq);
39330
- * ```
39331
- *
39332
- * To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:
39333
- *
39334
- * ```ts
39335
- * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query
39336
- * const sq = db.$with('sq').as(db.select({
39337
- * name: sql<string>`upper(${users.name})`.as('name'),
39338
- * })
39339
- * .from(users));
39340
- *
39341
- * const result = await db.with(sq).select({ name: sq.name }).from(sq);
39342
- * ```
39343
- */
39344
- $with(alias) {
39345
- const self2 = this;
39346
- return {
39347
- as(qb) {
39348
- if (typeof qb === "function") {
39349
- qb = qb(new QueryBuilder3(self2.dialect));
39350
- }
39351
- return new Proxy(
39352
- new WithSubquery(qb.getSQL(), qb.getSelectedFields(), alias, true),
39353
- new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
39354
- );
39355
- }
39356
- };
39357
- }
39358
39566
  $count(source, filters) {
39359
39567
  return new MySqlCountBuilder({ source, filters, session: this.session });
39360
39568
  }
@@ -42146,17 +42354,68 @@ var init_varchar3 = __esm({
42146
42354
  }
42147
42355
  });
42148
42356
 
42357
+ // ../drizzle-orm/dist/singlestore-core/columns/vector.js
42358
+ function vector2(a, b) {
42359
+ const { name: name2, config } = getColumnNameAndConfig(a, b);
42360
+ return new SingleStoreVectorBuilder(name2, config);
42361
+ }
42362
+ var _a389, _b293, SingleStoreVectorBuilder, _a390, _b294, SingleStoreVector;
42363
+ var init_vector4 = __esm({
42364
+ "../drizzle-orm/dist/singlestore-core/columns/vector.js"() {
42365
+ "use strict";
42366
+ init_entity();
42367
+ init_utils2();
42368
+ init_common5();
42369
+ SingleStoreVectorBuilder = class extends (_b293 = SingleStoreColumnBuilder, _a389 = entityKind, _b293) {
42370
+ constructor(name2, config) {
42371
+ super(name2, "array", "SingleStoreVector");
42372
+ this.config.dimensions = config.dimensions;
42373
+ this.config.elementType = config.elementType;
42374
+ }
42375
+ /** @internal */
42376
+ build(table5) {
42377
+ return new SingleStoreVector(
42378
+ table5,
42379
+ this.config
42380
+ );
42381
+ }
42382
+ /** @internal */
42383
+ generatedAlwaysAs(as, config) {
42384
+ throw new Error("not implemented");
42385
+ }
42386
+ };
42387
+ __publicField(SingleStoreVectorBuilder, _a389, "SingleStoreVectorBuilder");
42388
+ SingleStoreVector = class extends (_b294 = SingleStoreColumn, _a390 = entityKind, _b294) {
42389
+ constructor() {
42390
+ super(...arguments);
42391
+ __publicField(this, "dimensions", this.config.dimensions);
42392
+ __publicField(this, "elementType", this.config.elementType);
42393
+ }
42394
+ getSQLType() {
42395
+ return `vector(${this.dimensions}, ${this.elementType || "F32"})`;
42396
+ }
42397
+ mapToDriverValue(value) {
42398
+ return JSON.stringify(value);
42399
+ }
42400
+ mapFromDriverValue(value) {
42401
+ return JSON.parse(value);
42402
+ }
42403
+ };
42404
+ __publicField(SingleStoreVector, _a390, "SingleStoreVector");
42405
+ }
42406
+ });
42407
+
42149
42408
  // ../drizzle-orm/dist/singlestore-core/columns/year.js
42150
42409
  function year2(name2) {
42151
42410
  return new SingleStoreYearBuilder(name2 ?? "");
42152
42411
  }
42153
- var _a389, _b293, SingleStoreYearBuilder, _a390, _b294, SingleStoreYear;
42412
+ var _a391, _b295, SingleStoreYearBuilder, _a392, _b296, SingleStoreYear;
42154
42413
  var init_year2 = __esm({
42155
42414
  "../drizzle-orm/dist/singlestore-core/columns/year.js"() {
42156
42415
  "use strict";
42157
42416
  init_entity();
42158
42417
  init_common5();
42159
- SingleStoreYearBuilder = class extends (_b293 = SingleStoreColumnBuilder, _a389 = entityKind, _b293) {
42418
+ SingleStoreYearBuilder = class extends (_b295 = SingleStoreColumnBuilder, _a391 = entityKind, _b295) {
42160
42419
  constructor(name2) {
42161
42420
  super(name2, "number", "SingleStoreYear");
42162
42421
  }
@@ -42168,13 +42427,13 @@ var init_year2 = __esm({
42168
42427
  );
42169
42428
  }
42170
42429
  };
42171
- __publicField(SingleStoreYearBuilder, _a389, "SingleStoreYearBuilder");
42172
- SingleStoreYear = class extends (_b294 = SingleStoreColumn, _a390 = entityKind, _b294) {
42430
+ __publicField(SingleStoreYearBuilder, _a391, "SingleStoreYearBuilder");
42431
+ SingleStoreYear = class extends (_b296 = SingleStoreColumn, _a392 = entityKind, _b296) {
42173
42432
  getSQLType() {
42174
42433
  return `year`;
42175
42434
  }
42176
42435
  };
42177
- __publicField(SingleStoreYear, _a390, "SingleStoreYear");
42436
+ __publicField(SingleStoreYear, _a392, "SingleStoreYear");
42178
42437
  }
42179
42438
  });
42180
42439
 
@@ -42206,22 +42465,23 @@ var init_columns4 = __esm({
42206
42465
  init_tinyint2();
42207
42466
  init_varbinary2();
42208
42467
  init_varchar3();
42468
+ init_vector4();
42209
42469
  init_year2();
42210
42470
  }
42211
42471
  });
42212
42472
 
42213
42473
  // ../drizzle-orm/dist/singlestore-core/query-builders/count.js
42214
- var _a391, _b295, _c12, _SingleStoreCountBuilder, SingleStoreCountBuilder;
42474
+ var _a393, _b297, _c12, _SingleStoreCountBuilder, SingleStoreCountBuilder;
42215
42475
  var init_count4 = __esm({
42216
42476
  "../drizzle-orm/dist/singlestore-core/query-builders/count.js"() {
42217
42477
  "use strict";
42218
42478
  init_entity();
42219
42479
  init_sql();
42220
- _SingleStoreCountBuilder = class _SingleStoreCountBuilder extends (_c12 = SQL, _b295 = entityKind, _a391 = Symbol.toStringTag, _c12) {
42480
+ _SingleStoreCountBuilder = class _SingleStoreCountBuilder extends (_c12 = SQL, _b297 = entityKind, _a393 = Symbol.toStringTag, _c12) {
42221
42481
  constructor(params) {
42222
42482
  super(_SingleStoreCountBuilder.buildEmbeddedCount(params.source, params.filters).queryChunks);
42223
42483
  __publicField(this, "sql");
42224
- __publicField(this, _a391, "SingleStoreCountBuilder");
42484
+ __publicField(this, _a393, "SingleStoreCountBuilder");
42225
42485
  __publicField(this, "session");
42226
42486
  this.params = params;
42227
42487
  this.mapWith(Number);
@@ -42259,13 +42519,13 @@ var init_count4 = __esm({
42259
42519
  );
42260
42520
  }
42261
42521
  };
42262
- __publicField(_SingleStoreCountBuilder, _b295, "SingleStoreCountBuilder");
42522
+ __publicField(_SingleStoreCountBuilder, _b297, "SingleStoreCountBuilder");
42263
42523
  SingleStoreCountBuilder = _SingleStoreCountBuilder;
42264
42524
  }
42265
42525
  });
42266
42526
 
42267
42527
  // ../drizzle-orm/dist/singlestore-core/query-builders/delete.js
42268
- var _a392, _b296, SingleStoreDeleteBase;
42528
+ var _a394, _b298, SingleStoreDeleteBase;
42269
42529
  var init_delete4 = __esm({
42270
42530
  "../drizzle-orm/dist/singlestore-core/query-builders/delete.js"() {
42271
42531
  "use strict";
@@ -42273,7 +42533,7 @@ var init_delete4 = __esm({
42273
42533
  init_query_promise();
42274
42534
  init_selection_proxy();
42275
42535
  init_table();
42276
- SingleStoreDeleteBase = class extends (_b296 = QueryPromise, _a392 = entityKind, _b296) {
42536
+ SingleStoreDeleteBase = class extends (_b298 = QueryPromise, _a394 = entityKind, _b298) {
42277
42537
  constructor(table5, session, dialect6, withList) {
42278
42538
  super();
42279
42539
  __publicField(this, "config");
@@ -42363,12 +42623,12 @@ var init_delete4 = __esm({
42363
42623
  return this;
42364
42624
  }
42365
42625
  };
42366
- __publicField(SingleStoreDeleteBase, _a392, "SingleStoreDelete");
42626
+ __publicField(SingleStoreDeleteBase, _a394, "SingleStoreDelete");
42367
42627
  }
42368
42628
  });
42369
42629
 
42370
42630
  // ../drizzle-orm/dist/singlestore-core/query-builders/insert.js
42371
- var _a393, SingleStoreInsertBuilder, _a394, _b297, SingleStoreInsertBase;
42631
+ var _a395, SingleStoreInsertBuilder, _a396, _b299, SingleStoreInsertBase;
42372
42632
  var init_insert4 = __esm({
42373
42633
  "../drizzle-orm/dist/singlestore-core/query-builders/insert.js"() {
42374
42634
  "use strict";
@@ -42377,7 +42637,7 @@ var init_insert4 = __esm({
42377
42637
  init_sql();
42378
42638
  init_table();
42379
42639
  init_utils2();
42380
- _a393 = entityKind;
42640
+ _a395 = entityKind;
42381
42641
  SingleStoreInsertBuilder = class {
42382
42642
  constructor(table5, session, dialect6) {
42383
42643
  __publicField(this, "shouldIgnore", false);
@@ -42406,8 +42666,8 @@ var init_insert4 = __esm({
42406
42666
  return new SingleStoreInsertBase(this.table, mappedValues, this.shouldIgnore, this.session, this.dialect);
42407
42667
  }
42408
42668
  };
42409
- __publicField(SingleStoreInsertBuilder, _a393, "SingleStoreInsertBuilder");
42410
- SingleStoreInsertBase = class extends (_b297 = QueryPromise, _a394 = entityKind, _b297) {
42669
+ __publicField(SingleStoreInsertBuilder, _a395, "SingleStoreInsertBuilder");
42670
+ SingleStoreInsertBase = class extends (_b299 = QueryPromise, _a396 = entityKind, _b299) {
42411
42671
  constructor(table5, values, ignore, session, dialect6) {
42412
42672
  super();
42413
42673
  __publicField(this, "config");
@@ -42488,7 +42748,7 @@ var init_insert4 = __esm({
42488
42748
  return this;
42489
42749
  }
42490
42750
  };
42491
- __publicField(SingleStoreInsertBase, _a394, "SingleStoreInsert");
42751
+ __publicField(SingleStoreInsertBase, _a396, "SingleStoreInsert");
42492
42752
  }
42493
42753
  });
42494
42754
 
@@ -42521,6 +42781,7 @@ function getSingleStoreColumnBuilders() {
42521
42781
  tinyint: tinyint2,
42522
42782
  varbinary: varbinary2,
42523
42783
  varchar: varchar3,
42784
+ vector: vector2,
42524
42785
  year: year2
42525
42786
  };
42526
42787
  }
@@ -42550,6 +42811,7 @@ var init_all4 = __esm({
42550
42811
  init_tinyint2();
42551
42812
  init_varbinary2();
42552
42813
  init_varchar3();
42814
+ init_vector4();
42553
42815
  init_year2();
42554
42816
  }
42555
42817
  });
@@ -42574,20 +42836,20 @@ function singlestoreTableWithSchema(name2, columns, extraConfig, schema5, baseNa
42574
42836
  }
42575
42837
  return table5;
42576
42838
  }
42577
- var _a395, _b298, _c13, _d5, SingleStoreTable;
42839
+ var _a397, _b300, _c13, _d5, SingleStoreTable;
42578
42840
  var init_table5 = __esm({
42579
42841
  "../drizzle-orm/dist/singlestore-core/table.js"() {
42580
42842
  "use strict";
42581
42843
  init_entity();
42582
42844
  init_table();
42583
42845
  init_all4();
42584
- SingleStoreTable = class extends (_d5 = Table2, _c13 = entityKind, _b298 = Table2.Symbol.Columns, _a395 = Table2.Symbol.ExtraConfigBuilder, _d5) {
42846
+ SingleStoreTable = class extends (_d5 = Table2, _c13 = entityKind, _b300 = Table2.Symbol.Columns, _a397 = Table2.Symbol.ExtraConfigBuilder, _d5) {
42585
42847
  constructor() {
42586
42848
  super(...arguments);
42587
42849
  /** @internal */
42588
- __publicField(this, _b298);
42850
+ __publicField(this, _b300);
42589
42851
  /** @internal */
42590
- __publicField(this, _a395);
42852
+ __publicField(this, _a397);
42591
42853
  }
42592
42854
  };
42593
42855
  __publicField(SingleStoreTable, _c13, "SingleStoreTable");
@@ -42597,7 +42859,7 @@ var init_table5 = __esm({
42597
42859
  });
42598
42860
 
42599
42861
  // ../drizzle-orm/dist/singlestore-core/dialect.js
42600
- var _a396, SingleStoreDialect;
42862
+ var _a398, SingleStoreDialect;
42601
42863
  var init_dialect4 = __esm({
42602
42864
  "../drizzle-orm/dist/singlestore-core/dialect.js"() {
42603
42865
  "use strict";
@@ -42615,7 +42877,7 @@ var init_dialect4 = __esm({
42615
42877
  init_view_common();
42616
42878
  init_common5();
42617
42879
  init_table5();
42618
- _a396 = entityKind;
42880
+ _a398 = entityKind;
42619
42881
  SingleStoreDialect = class {
42620
42882
  constructor(config) {
42621
42883
  /** @internal */
@@ -43180,7 +43442,7 @@ var init_dialect4 = __esm({
43180
43442
  };
43181
43443
  }
43182
43444
  };
43183
- __publicField(SingleStoreDialect, _a396, "SingleStoreDialect");
43445
+ __publicField(SingleStoreDialect, _a398, "SingleStoreDialect");
43184
43446
  }
43185
43447
  });
43186
43448
 
@@ -43202,7 +43464,7 @@ function createSetOperator4(type, isAll) {
43202
43464
  return leftSelect.addSetOperators(setOperators);
43203
43465
  };
43204
43466
  }
43205
- var _a397, SingleStoreSelectBuilder, _a398, _b299, SingleStoreSelectQueryBuilderBase, _a399, _b300, SingleStoreSelectBase, getSingleStoreSetOperators, union4, unionAll4, intersect4, except4, minus;
43467
+ var _a399, SingleStoreSelectBuilder, _a400, _b301, SingleStoreSelectQueryBuilderBase, _a401, _b302, SingleStoreSelectBase, getSingleStoreSetOperators, union4, unionAll4, intersect4, except4, minus;
43206
43468
  var init_select5 = __esm({
43207
43469
  "../drizzle-orm/dist/singlestore-core/query-builders/select.js"() {
43208
43470
  "use strict";
@@ -43214,7 +43476,7 @@ var init_select5 = __esm({
43214
43476
  init_subquery();
43215
43477
  init_table();
43216
43478
  init_utils2();
43217
- _a397 = entityKind;
43479
+ _a399 = entityKind;
43218
43480
  SingleStoreSelectBuilder = class {
43219
43481
  constructor(config) {
43220
43482
  __publicField(this, "fields");
@@ -43257,8 +43519,8 @@ var init_select5 = __esm({
43257
43519
  );
43258
43520
  }
43259
43521
  };
43260
- __publicField(SingleStoreSelectBuilder, _a397, "SingleStoreSelectBuilder");
43261
- SingleStoreSelectQueryBuilderBase = class extends (_b299 = TypedQueryBuilder, _a398 = entityKind, _b299) {
43522
+ __publicField(SingleStoreSelectBuilder, _a399, "SingleStoreSelectBuilder");
43523
+ SingleStoreSelectQueryBuilderBase = class extends (_b301 = TypedQueryBuilder, _a400 = entityKind, _b301) {
43262
43524
  constructor({ table: table5, fields, isPartialSelect, session, dialect: dialect6, withList, distinct }) {
43263
43525
  super();
43264
43526
  __publicField(this, "_");
@@ -43799,8 +44061,8 @@ var init_select5 = __esm({
43799
44061
  return this;
43800
44062
  }
43801
44063
  };
43802
- __publicField(SingleStoreSelectQueryBuilderBase, _a398, "SingleStoreSelectQueryBuilder");
43803
- SingleStoreSelectBase = class extends (_b300 = SingleStoreSelectQueryBuilderBase, _a399 = entityKind, _b300) {
44064
+ __publicField(SingleStoreSelectQueryBuilderBase, _a400, "SingleStoreSelectQueryBuilder");
44065
+ SingleStoreSelectBase = class extends (_b302 = SingleStoreSelectQueryBuilderBase, _a401 = entityKind, _b302) {
43804
44066
  constructor() {
43805
44067
  super(...arguments);
43806
44068
  __publicField(this, "execute", (placeholderValues) => {
@@ -43824,7 +44086,7 @@ var init_select5 = __esm({
43824
44086
  return query;
43825
44087
  }
43826
44088
  };
43827
- __publicField(SingleStoreSelectBase, _a399, "SingleStoreSelect");
44089
+ __publicField(SingleStoreSelectBase, _a401, "SingleStoreSelect");
43828
44090
  applyMixins(SingleStoreSelectBase, [QueryPromise]);
43829
44091
  getSingleStoreSetOperators = () => ({
43830
44092
  union: union4,
@@ -43842,7 +44104,7 @@ var init_select5 = __esm({
43842
44104
  });
43843
44105
 
43844
44106
  // ../drizzle-orm/dist/singlestore-core/query-builders/query-builder.js
43845
- var _a400, QueryBuilder4;
44107
+ var _a402, QueryBuilder4;
43846
44108
  var init_query_builder5 = __esm({
43847
44109
  "../drizzle-orm/dist/singlestore-core/query-builders/query-builder.js"() {
43848
44110
  "use strict";
@@ -43851,27 +44113,31 @@ var init_query_builder5 = __esm({
43851
44113
  init_dialect4();
43852
44114
  init_subquery();
43853
44115
  init_select5();
43854
- _a400 = entityKind;
44116
+ _a402 = entityKind;
43855
44117
  QueryBuilder4 = class {
43856
44118
  constructor(dialect6) {
43857
44119
  __publicField(this, "dialect");
43858
44120
  __publicField(this, "dialectConfig");
43859
- this.dialect = is(dialect6, SingleStoreDialect) ? dialect6 : void 0;
43860
- this.dialectConfig = is(dialect6, SingleStoreDialect) ? void 0 : dialect6;
43861
- }
43862
- $with(alias) {
43863
- const queryBuilder = this;
43864
- return {
43865
- as(qb) {
44121
+ __publicField(this, "$with", (alias, selection) => {
44122
+ const queryBuilder = this;
44123
+ const as = (qb) => {
43866
44124
  if (typeof qb === "function") {
43867
44125
  qb = qb(queryBuilder);
43868
44126
  }
43869
44127
  return new Proxy(
43870
- new WithSubquery(qb.getSQL(), qb.getSelectedFields(), alias, true),
44128
+ new WithSubquery(
44129
+ qb.getSQL(),
44130
+ selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}),
44131
+ alias,
44132
+ true
44133
+ ),
43871
44134
  new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
43872
44135
  );
43873
- }
43874
- };
44136
+ };
44137
+ return { as };
44138
+ });
44139
+ this.dialect = is(dialect6, SingleStoreDialect) ? dialect6 : void 0;
44140
+ this.dialectConfig = is(dialect6, SingleStoreDialect) ? void 0 : dialect6;
43875
44141
  }
43876
44142
  with(...queries) {
43877
44143
  const self2 = this;
@@ -43917,7 +44183,7 @@ var init_query_builder5 = __esm({
43917
44183
  return this.dialect;
43918
44184
  }
43919
44185
  };
43920
- __publicField(QueryBuilder4, _a400, "SingleStoreQueryBuilder");
44186
+ __publicField(QueryBuilder4, _a402, "SingleStoreQueryBuilder");
43921
44187
  }
43922
44188
  });
43923
44189
 
@@ -43929,7 +44195,7 @@ var init_select_types4 = __esm({
43929
44195
  });
43930
44196
 
43931
44197
  // ../drizzle-orm/dist/singlestore-core/query-builders/update.js
43932
- var _a401, SingleStoreUpdateBuilder, _a402, _b301, SingleStoreUpdateBase;
44198
+ var _a403, SingleStoreUpdateBuilder, _a404, _b303, SingleStoreUpdateBase;
43933
44199
  var init_update4 = __esm({
43934
44200
  "../drizzle-orm/dist/singlestore-core/query-builders/update.js"() {
43935
44201
  "use strict";
@@ -43938,7 +44204,7 @@ var init_update4 = __esm({
43938
44204
  init_selection_proxy();
43939
44205
  init_table();
43940
44206
  init_utils2();
43941
- _a401 = entityKind;
44207
+ _a403 = entityKind;
43942
44208
  SingleStoreUpdateBuilder = class {
43943
44209
  constructor(table5, session, dialect6, withList) {
43944
44210
  this.table = table5;
@@ -43956,8 +44222,8 @@ var init_update4 = __esm({
43956
44222
  );
43957
44223
  }
43958
44224
  };
43959
- __publicField(SingleStoreUpdateBuilder, _a401, "SingleStoreUpdateBuilder");
43960
- SingleStoreUpdateBase = class extends (_b301 = QueryPromise, _a402 = entityKind, _b301) {
44225
+ __publicField(SingleStoreUpdateBuilder, _a403, "SingleStoreUpdateBuilder");
44226
+ SingleStoreUpdateBase = class extends (_b303 = QueryPromise, _a404 = entityKind, _b303) {
43961
44227
  constructor(table5, set, session, dialect6, withList) {
43962
44228
  super();
43963
44229
  __publicField(this, "config");
@@ -44050,7 +44316,7 @@ var init_update4 = __esm({
44050
44316
  return this;
44051
44317
  }
44052
44318
  };
44053
- __publicField(SingleStoreUpdateBase, _a402, "SingleStoreUpdate");
44319
+ __publicField(SingleStoreUpdateBase, _a404, "SingleStoreUpdate");
44054
44320
  }
44055
44321
  });
44056
44322
 
@@ -44068,7 +44334,7 @@ var init_query_builders4 = __esm({
44068
44334
  });
44069
44335
 
44070
44336
  // ../drizzle-orm/dist/singlestore-core/db.js
44071
- var _a403, SingleStoreDatabase;
44337
+ var _a405, SingleStoreDatabase;
44072
44338
  var init_db4 = __esm({
44073
44339
  "../drizzle-orm/dist/singlestore-core/db.js"() {
44074
44340
  "use strict";
@@ -44078,12 +44344,62 @@ var init_db4 = __esm({
44078
44344
  init_subquery();
44079
44345
  init_count4();
44080
44346
  init_query_builders4();
44081
- _a403 = entityKind;
44347
+ _a405 = entityKind;
44082
44348
  SingleStoreDatabase = class {
44083
44349
  constructor(dialect6, session, schema5) {
44084
44350
  // We are waiting for SingleStore support for `json_array` function
44085
44351
  /**@inrernal */
44086
44352
  __publicField(this, "query");
44353
+ /**
44354
+ * Creates a subquery that defines a temporary named result set as a CTE.
44355
+ *
44356
+ * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.
44357
+ *
44358
+ * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
44359
+ *
44360
+ * @param alias The alias for the subquery.
44361
+ *
44362
+ * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.
44363
+ *
44364
+ * @example
44365
+ *
44366
+ * ```ts
44367
+ * // Create a subquery with alias 'sq' and use it in the select query
44368
+ * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
44369
+ *
44370
+ * const result = await db.with(sq).select().from(sq);
44371
+ * ```
44372
+ *
44373
+ * To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:
44374
+ *
44375
+ * ```ts
44376
+ * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query
44377
+ * const sq = db.$with('sq').as(db.select({
44378
+ * name: sql<string>`upper(${users.name})`.as('name'),
44379
+ * })
44380
+ * .from(users));
44381
+ *
44382
+ * const result = await db.with(sq).select({ name: sq.name }).from(sq);
44383
+ * ```
44384
+ */
44385
+ __publicField(this, "$with", (alias, selection) => {
44386
+ const self2 = this;
44387
+ const as = (qb) => {
44388
+ if (typeof qb === "function") {
44389
+ qb = qb(new QueryBuilder4(self2.dialect));
44390
+ }
44391
+ return new Proxy(
44392
+ new WithSubquery(
44393
+ qb.getSQL(),
44394
+ selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}),
44395
+ alias,
44396
+ true
44397
+ ),
44398
+ new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
44399
+ );
44400
+ };
44401
+ return { as };
44402
+ });
44087
44403
  this.dialect = dialect6;
44088
44404
  this.session = session;
44089
44405
  this._ = schema5 ? {
@@ -44097,52 +44413,6 @@ var init_db4 = __esm({
44097
44413
  };
44098
44414
  this.query = {};
44099
44415
  }
44100
- /**
44101
- * Creates a subquery that defines a temporary named result set as a CTE.
44102
- *
44103
- * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.
44104
- *
44105
- * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
44106
- *
44107
- * @param alias The alias for the subquery.
44108
- *
44109
- * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.
44110
- *
44111
- * @example
44112
- *
44113
- * ```ts
44114
- * // Create a subquery with alias 'sq' and use it in the select query
44115
- * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
44116
- *
44117
- * const result = await db.with(sq).select().from(sq);
44118
- * ```
44119
- *
44120
- * To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:
44121
- *
44122
- * ```ts
44123
- * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query
44124
- * const sq = db.$with('sq').as(db.select({
44125
- * name: sql<string>`upper(${users.name})`.as('name'),
44126
- * })
44127
- * .from(users));
44128
- *
44129
- * const result = await db.with(sq).select({ name: sq.name }).from(sq);
44130
- * ```
44131
- */
44132
- $with(alias) {
44133
- const self2 = this;
44134
- return {
44135
- as(qb) {
44136
- if (typeof qb === "function") {
44137
- qb = qb(new QueryBuilder4(self2.dialect));
44138
- }
44139
- return new Proxy(
44140
- new WithSubquery(qb.getSQL(), qb.getSelectedFields(), alias, true),
44141
- new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
44142
- );
44143
- }
44144
- };
44145
- }
44146
44416
  $count(source, filters) {
44147
44417
  return new SingleStoreCountBuilder({ source, filters, session: this.session });
44148
44418
  }
@@ -44278,17 +44548,17 @@ var init_db4 = __esm({
44278
44548
  return this.session.transaction(transaction, config);
44279
44549
  }
44280
44550
  };
44281
- __publicField(SingleStoreDatabase, _a403, "SingleStoreDatabase");
44551
+ __publicField(SingleStoreDatabase, _a405, "SingleStoreDatabase");
44282
44552
  }
44283
44553
  });
44284
44554
 
44285
44555
  // ../drizzle-orm/dist/singlestore-core/indexes.js
44286
- var _a404, IndexBuilderOn4, _a405, IndexBuilder4, _a406, Index6;
44556
+ var _a406, IndexBuilderOn4, _a407, IndexBuilder4, _a408, Index6;
44287
44557
  var init_indexes4 = __esm({
44288
44558
  "../drizzle-orm/dist/singlestore-core/indexes.js"() {
44289
44559
  "use strict";
44290
44560
  init_entity();
44291
- _a404 = entityKind;
44561
+ _a406 = entityKind;
44292
44562
  IndexBuilderOn4 = class {
44293
44563
  constructor(name2, unique) {
44294
44564
  this.name = name2;
@@ -44298,8 +44568,8 @@ var init_indexes4 = __esm({
44298
44568
  return new IndexBuilder4(this.name, columns, this.unique);
44299
44569
  }
44300
44570
  };
44301
- __publicField(IndexBuilderOn4, _a404, "SingleStoreIndexBuilderOn");
44302
- _a405 = entityKind;
44571
+ __publicField(IndexBuilderOn4, _a406, "SingleStoreIndexBuilderOn");
44572
+ _a407 = entityKind;
44303
44573
  IndexBuilder4 = class {
44304
44574
  constructor(name2, columns, unique) {
44305
44575
  /** @internal */
@@ -44327,26 +44597,26 @@ var init_indexes4 = __esm({
44327
44597
  return new Index6(this.config, table5);
44328
44598
  }
44329
44599
  };
44330
- __publicField(IndexBuilder4, _a405, "SingleStoreIndexBuilder");
44331
- _a406 = entityKind;
44600
+ __publicField(IndexBuilder4, _a407, "SingleStoreIndexBuilder");
44601
+ _a408 = entityKind;
44332
44602
  Index6 = class {
44333
44603
  constructor(config, table5) {
44334
44604
  __publicField(this, "config");
44335
44605
  this.config = { ...config, table: table5 };
44336
44606
  }
44337
44607
  };
44338
- __publicField(Index6, _a406, "SingleStoreIndex");
44608
+ __publicField(Index6, _a408, "SingleStoreIndex");
44339
44609
  }
44340
44610
  });
44341
44611
 
44342
44612
  // ../drizzle-orm/dist/singlestore-core/primary-keys.js
44343
- var _a407, PrimaryKeyBuilder4, _a408, PrimaryKey4;
44613
+ var _a409, PrimaryKeyBuilder4, _a410, PrimaryKey4;
44344
44614
  var init_primary_keys4 = __esm({
44345
44615
  "../drizzle-orm/dist/singlestore-core/primary-keys.js"() {
44346
44616
  "use strict";
44347
44617
  init_entity();
44348
44618
  init_table5();
44349
- _a407 = entityKind;
44619
+ _a409 = entityKind;
44350
44620
  PrimaryKeyBuilder4 = class {
44351
44621
  constructor(columns, name2) {
44352
44622
  /** @internal */
@@ -44361,8 +44631,8 @@ var init_primary_keys4 = __esm({
44361
44631
  return new PrimaryKey4(table5, this.columns, this.name);
44362
44632
  }
44363
44633
  };
44364
- __publicField(PrimaryKeyBuilder4, _a407, "SingleStorePrimaryKeyBuilder");
44365
- _a408 = entityKind;
44634
+ __publicField(PrimaryKeyBuilder4, _a409, "SingleStorePrimaryKeyBuilder");
44635
+ _a410 = entityKind;
44366
44636
  PrimaryKey4 = class {
44367
44637
  constructor(table5, columns, name2) {
44368
44638
  __publicField(this, "columns");
@@ -44375,18 +44645,18 @@ var init_primary_keys4 = __esm({
44375
44645
  return this.name ?? `${this.table[SingleStoreTable.Symbol.Name]}_${this.columns.map((column5) => column5.name).join("_")}_pk`;
44376
44646
  }
44377
44647
  };
44378
- __publicField(PrimaryKey4, _a408, "SingleStorePrimaryKey");
44648
+ __publicField(PrimaryKey4, _a410, "SingleStorePrimaryKey");
44379
44649
  }
44380
44650
  });
44381
44651
 
44382
44652
  // ../drizzle-orm/dist/singlestore-core/schema.js
44383
- var _a409, SingleStoreSchema5;
44653
+ var _a411, SingleStoreSchema5;
44384
44654
  var init_schema3 = __esm({
44385
44655
  "../drizzle-orm/dist/singlestore-core/schema.js"() {
44386
44656
  "use strict";
44387
44657
  init_entity();
44388
44658
  init_table5();
44389
- _a409 = entityKind;
44659
+ _a411 = entityKind;
44390
44660
  SingleStoreSchema5 = class {
44391
44661
  constructor(schemaName) {
44392
44662
  __publicField(this, "table", (name2, columns, extraConfig) => {
@@ -44399,12 +44669,12 @@ var init_schema3 = __esm({
44399
44669
  return singlestoreViewWithSchema(name, columns, this.schemaName);
44400
44670
  }) as typeof singlestoreView; */
44401
44671
  };
44402
- __publicField(SingleStoreSchema5, _a409, "SingleStoreSchema");
44672
+ __publicField(SingleStoreSchema5, _a411, "SingleStoreSchema");
44403
44673
  }
44404
44674
  });
44405
44675
 
44406
44676
  // ../drizzle-orm/dist/singlestore-core/session.js
44407
- var _a410, SingleStorePreparedQuery, _a411, SingleStoreSession, _a412, _b302, SingleStoreTransaction;
44677
+ var _a412, SingleStorePreparedQuery, _a413, SingleStoreSession, _a414, _b304, SingleStoreTransaction;
44408
44678
  var init_session4 = __esm({
44409
44679
  "../drizzle-orm/dist/singlestore-core/session.js"() {
44410
44680
  "use strict";
@@ -44412,15 +44682,15 @@ var init_session4 = __esm({
44412
44682
  init_errors();
44413
44683
  init_sql();
44414
44684
  init_db4();
44415
- _a410 = entityKind;
44685
+ _a412 = entityKind;
44416
44686
  SingleStorePreparedQuery = class {
44417
44687
  constructor() {
44418
44688
  /** @internal */
44419
44689
  __publicField(this, "joinsNotNullableMap");
44420
44690
  }
44421
44691
  };
44422
- __publicField(SingleStorePreparedQuery, _a410, "SingleStorePreparedQuery");
44423
- _a411 = entityKind;
44692
+ __publicField(SingleStorePreparedQuery, _a412, "SingleStorePreparedQuery");
44693
+ _a413 = entityKind;
44424
44694
  SingleStoreSession = class {
44425
44695
  constructor(dialect6) {
44426
44696
  this.dialect = dialect6;
@@ -44455,8 +44725,8 @@ var init_session4 = __esm({
44455
44725
  return parts.length ? sql`start transaction ${sql.raw(parts.join(" "))}` : void 0;
44456
44726
  }
44457
44727
  };
44458
- __publicField(SingleStoreSession, _a411, "SingleStoreSession");
44459
- SingleStoreTransaction = class extends (_b302 = SingleStoreDatabase, _a412 = entityKind, _b302) {
44728
+ __publicField(SingleStoreSession, _a413, "SingleStoreSession");
44729
+ SingleStoreTransaction = class extends (_b304 = SingleStoreDatabase, _a414 = entityKind, _b304) {
44460
44730
  constructor(dialect6, session, schema5, nestedIndex) {
44461
44731
  super(dialect6, session, schema5);
44462
44732
  this.schema = schema5;
@@ -44466,7 +44736,7 @@ var init_session4 = __esm({
44466
44736
  throw new TransactionRollbackError();
44467
44737
  }
44468
44738
  };
44469
- __publicField(SingleStoreTransaction, _a412, "SingleStoreTransaction");
44739
+ __publicField(SingleStoreTransaction, _a414, "SingleStoreTransaction");
44470
44740
  }
44471
44741
  });
44472
44742
 
@@ -44643,7 +44913,7 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
44643
44913
  if (typeof column5.default === "string") {
44644
44914
  columnToSet.default = `'${column5.default}'`;
44645
44915
  } else {
44646
- if (sqlTypeLowered === "json") {
44916
+ if (sqlTypeLowered === "json" || Array.isArray(column5.default)) {
44647
44917
  columnToSet.default = `'${JSON.stringify(column5.default)}'`;
44648
44918
  } else if (column5.default instanceof Date) {
44649
44919
  if (sqlTypeLowered === "date") {
@@ -45413,15 +45683,31 @@ var init_singlestoreImports = __esm({
45413
45683
  var singlestorePushUtils_exports = {};
45414
45684
  __export(singlestorePushUtils_exports, {
45415
45685
  filterStatements: () => filterStatements2,
45686
+ findColumnTypeAlternations: () => findColumnTypeAlternations,
45416
45687
  logSuggestionsAndReturn: () => logSuggestionsAndReturn3
45417
45688
  });
45689
+ function findColumnTypeAlternations(columns1, columns2) {
45690
+ const changes = [];
45691
+ for (const key in columns1) {
45692
+ if (columns1.hasOwnProperty(key) && columns2.hasOwnProperty(key)) {
45693
+ const col1 = columns1[key];
45694
+ const col2 = columns2[key];
45695
+ if (col1.type !== col2.type) {
45696
+ changes.push(col2.name);
45697
+ }
45698
+ }
45699
+ }
45700
+ return changes;
45701
+ }
45418
45702
  var import_hanji10, filterStatements2, logSuggestionsAndReturn3;
45419
45703
  var init_singlestorePushUtils = __esm({
45420
45704
  "src/cli/commands/singlestorePushUtils.ts"() {
45421
45705
  "use strict";
45422
45706
  init_source();
45423
45707
  import_hanji10 = __toESM(require_hanji());
45708
+ init_sqlgenerator();
45424
45709
  init_singlestoreSchema();
45710
+ init_utils();
45425
45711
  init_selector_ui();
45426
45712
  init_outputs();
45427
45713
  filterStatements2 = (statements, currentSchema, prevSchema) => {
@@ -45465,7 +45751,7 @@ var init_singlestorePushUtils = __esm({
45465
45751
  return true;
45466
45752
  });
45467
45753
  };
45468
- logSuggestionsAndReturn3 = async (db, statements, json22) => {
45754
+ logSuggestionsAndReturn3 = async (db, statements, json22, json1) => {
45469
45755
  let shouldAskForApprove = false;
45470
45756
  const statementsToExecute = [];
45471
45757
  const infoToPrint = [];
@@ -45646,6 +45932,71 @@ var init_singlestorePushUtils = __esm({
45646
45932
  shouldAskForApprove = true;
45647
45933
  }
45648
45934
  }
45935
+ } else if (statement.type === "singlestore_recreate_table") {
45936
+ const tableName = statement.tableName;
45937
+ const prevColumns = json1.tables[tableName].columns;
45938
+ const currentColumns = json22.tables[tableName].columns;
45939
+ const { removedColumns, addedColumns } = findAddedAndRemoved(
45940
+ Object.keys(prevColumns),
45941
+ Object.keys(currentColumns)
45942
+ );
45943
+ if (removedColumns.length) {
45944
+ for (const removedColumn of removedColumns) {
45945
+ const res = await db.query(
45946
+ `select count(\`${tableName}\`.\`${removedColumn}\`) as count from \`${tableName}\``
45947
+ );
45948
+ const count2 = Number(res[0].count);
45949
+ if (count2 > 0) {
45950
+ infoToPrint.push(
45951
+ `\xB7 You're about to delete ${source_default.underline(
45952
+ removedColumn
45953
+ )} column in ${tableName} table with ${count2} items`
45954
+ );
45955
+ columnsToRemove.push(removedColumn);
45956
+ shouldAskForApprove = true;
45957
+ }
45958
+ }
45959
+ }
45960
+ if (addedColumns.length) {
45961
+ for (const addedColumn of addedColumns) {
45962
+ const [res] = await db.query(
45963
+ `select count(*) as count from \`${tableName}\``
45964
+ );
45965
+ const columnConf = json22.tables[tableName].columns[addedColumn];
45966
+ const count2 = Number(res.count);
45967
+ if (count2 > 0 && columnConf.notNull && !columnConf.default) {
45968
+ infoToPrint.push(
45969
+ `\xB7 You're about to add not-null ${source_default.underline(
45970
+ addedColumn
45971
+ )} column without default value to table, which contains ${count2} items`
45972
+ );
45973
+ shouldAskForApprove = true;
45974
+ tablesToTruncate.push(tableName);
45975
+ statementsToExecute.push(`TRUNCATE TABLE \`${tableName}\`;`);
45976
+ }
45977
+ }
45978
+ }
45979
+ const columnWithChangedType = findColumnTypeAlternations(prevColumns, currentColumns);
45980
+ for (const column5 of columnWithChangedType) {
45981
+ const [res] = await db.query(
45982
+ `select count(*) as count from \`${tableName}\` WHERE \`${tableName}\`.\`${column5}\` IS NOT NULL;`
45983
+ );
45984
+ const count2 = Number(res.count);
45985
+ if (count2 > 0) {
45986
+ infoToPrint.push(
45987
+ `\xB7 You're about recreate ${source_default.underline(tableName)} table with data type changing for ${source_default.underline(
45988
+ column5
45989
+ )} column, which contains ${count2} items`
45990
+ );
45991
+ shouldAskForApprove = true;
45992
+ tablesToTruncate.push(tableName);
45993
+ statementsToExecute.push(`TRUNCATE TABLE \`${tableName}\`;`);
45994
+ }
45995
+ }
45996
+ }
45997
+ const stmnt = fromJson([statement], "singlestore", "push");
45998
+ if (typeof stmnt !== "undefined") {
45999
+ statementsToExecute.push(...stmnt);
45649
46000
  }
45650
46001
  }
45651
46002
  return {
@@ -46491,7 +46842,8 @@ var pushSingleStoreSchema = async (imports, drizzleInstance, databaseName) => {
46491
46842
  const { shouldAskForApprove, statementsToExecute, infoToPrint } = await logSuggestionsAndReturn4(
46492
46843
  db,
46493
46844
  statements,
46494
- validatedCur
46845
+ validatedCur,
46846
+ validatedPrev
46495
46847
  );
46496
46848
  return {
46497
46849
  hasDataLoss: shouldAskForApprove,