drizzle-kit 0.30.2-de3c537 → 0.30.2-efae52b

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 +34650 -47763
  4. package/package.json +1 -1
package/api.mjs CHANGED
@@ -3474,17 +3474,17 @@ function processCreateParams(params) {
3474
3474
  if (errorMap2)
3475
3475
  return { errorMap: errorMap2, description };
3476
3476
  const customMap = (iss, ctx) => {
3477
- var _a413, _b303;
3477
+ var _a415, _b305;
3478
3478
  const { message } = params;
3479
3479
  if (iss.code === "invalid_enum_value") {
3480
3480
  return { message: message !== null && message !== void 0 ? message : ctx.defaultError };
3481
3481
  }
3482
3482
  if (typeof ctx.data === "undefined") {
3483
- return { message: (_a413 = message !== null && message !== void 0 ? message : required_error) !== null && _a413 !== void 0 ? _a413 : ctx.defaultError };
3483
+ return { message: (_a415 = message !== null && message !== void 0 ? message : required_error) !== null && _a415 !== void 0 ? _a415 : ctx.defaultError };
3484
3484
  }
3485
3485
  if (iss.code !== "invalid_type")
3486
3486
  return { message: ctx.defaultError };
3487
- return { message: (_b303 = message !== null && message !== void 0 ? message : invalid_type_error) !== null && _b303 !== void 0 ? _b303 : ctx.defaultError };
3487
+ return { message: (_b305 = message !== null && message !== void 0 ? message : invalid_type_error) !== null && _b305 !== void 0 ? _b305 : ctx.defaultError };
3488
3488
  };
3489
3489
  return { errorMap: customMap, description };
3490
3490
  }
@@ -4146,11 +4146,11 @@ var init_lib = __esm({
4146
4146
  throw result.error;
4147
4147
  }
4148
4148
  safeParse(data, params) {
4149
- var _a413;
4149
+ var _a415;
4150
4150
  const ctx = {
4151
4151
  common: {
4152
4152
  issues: [],
4153
- async: (_a413 = params === null || params === void 0 ? void 0 : params.async) !== null && _a413 !== void 0 ? _a413 : false,
4153
+ async: (_a415 = params === null || params === void 0 ? void 0 : params.async) !== null && _a415 !== void 0 ? _a415 : false,
4154
4154
  contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap
4155
4155
  },
4156
4156
  path: (params === null || params === void 0 ? void 0 : params.path) || [],
@@ -4472,7 +4472,7 @@ var init_lib = __esm({
4472
4472
  } else if (check.kind === "url") {
4473
4473
  try {
4474
4474
  new URL(input.data);
4475
- } catch (_a413) {
4475
+ } catch (_a415) {
4476
4476
  ctx = this._getOrReturnCtx(input, ctx);
4477
4477
  addIssueToContext(ctx, {
4478
4478
  validation: "url",
@@ -4642,7 +4642,7 @@ var init_lib = __esm({
4642
4642
  return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
4643
4643
  }
4644
4644
  datetime(options) {
4645
- var _a413, _b303;
4645
+ var _a415, _b305;
4646
4646
  if (typeof options === "string") {
4647
4647
  return this._addCheck({
4648
4648
  kind: "datetime",
@@ -4655,8 +4655,8 @@ var init_lib = __esm({
4655
4655
  return this._addCheck({
4656
4656
  kind: "datetime",
4657
4657
  precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
4658
- offset: (_a413 = options === null || options === void 0 ? void 0 : options.offset) !== null && _a413 !== void 0 ? _a413 : false,
4659
- local: (_b303 = options === null || options === void 0 ? void 0 : options.local) !== null && _b303 !== void 0 ? _b303 : false,
4658
+ offset: (_a415 = options === null || options === void 0 ? void 0 : options.offset) !== null && _a415 !== void 0 ? _a415 : false,
4659
+ local: (_b305 = options === null || options === void 0 ? void 0 : options.local) !== null && _b305 !== void 0 ? _b305 : false,
4660
4660
  ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
4661
4661
  });
4662
4662
  }
@@ -4819,11 +4819,11 @@ var init_lib = __esm({
4819
4819
  }
4820
4820
  };
4821
4821
  ZodString.create = (params) => {
4822
- var _a413;
4822
+ var _a415;
4823
4823
  return new ZodString({
4824
4824
  checks: [],
4825
4825
  typeName: ZodFirstPartyTypeKind.ZodString,
4826
- coerce: (_a413 = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a413 !== void 0 ? _a413 : false,
4826
+ coerce: (_a415 = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a415 !== void 0 ? _a415 : false,
4827
4827
  ...processCreateParams(params)
4828
4828
  });
4829
4829
  };
@@ -5216,11 +5216,11 @@ var init_lib = __esm({
5216
5216
  }
5217
5217
  };
5218
5218
  ZodBigInt.create = (params) => {
5219
- var _a413;
5219
+ var _a415;
5220
5220
  return new ZodBigInt({
5221
5221
  checks: [],
5222
5222
  typeName: ZodFirstPartyTypeKind.ZodBigInt,
5223
- coerce: (_a413 = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a413 !== void 0 ? _a413 : false,
5223
+ coerce: (_a415 = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a415 !== void 0 ? _a415 : false,
5224
5224
  ...processCreateParams(params)
5225
5225
  });
5226
5226
  };
@@ -5700,8 +5700,8 @@ var init_lib = __esm({
5700
5700
  unknownKeys: "strict",
5701
5701
  ...message !== void 0 ? {
5702
5702
  errorMap: (issue, ctx) => {
5703
- var _a413, _b303, _c14, _d6;
5704
- 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;
5703
+ var _a415, _b305, _c14, _d6;
5704
+ 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;
5705
5705
  if (issue.code === "unrecognized_keys")
5706
5706
  return {
5707
5707
  message: (_d6 = errorUtil.errToObj(message).message) !== null && _d6 !== void 0 ? _d6 : defaultError
@@ -12126,7 +12126,7 @@ function fromJson(statements, dialect6, action, json22) {
12126
12126
  }).filter((it) => it !== "");
12127
12127
  return result;
12128
12128
  }
12129
- 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;
12129
+ 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;
12130
12130
  var init_sqlgenerator = __esm({
12131
12131
  "src/sqlgenerator.ts"() {
12132
12132
  "use strict";
@@ -12472,7 +12472,7 @@ var init_sqlgenerator = __esm({
12472
12472
  if (typeof compositePKs !== "undefined" && compositePKs.length > 0) {
12473
12473
  statement += ",\n";
12474
12474
  const compositePK5 = SingleStoreSquasher.unsquashPK(compositePKs[0]);
12475
- statement += ` CONSTRAINT \`${st.compositePkName}\` PRIMARY KEY(\`${compositePK5.columns.join(`\`,\``)}\`)`;
12475
+ statement += ` CONSTRAINT \`${compositePK5.name}\` PRIMARY KEY(\`${compositePK5.columns.join(`\`,\``)}\`)`;
12476
12476
  }
12477
12477
  if (typeof uniqueConstraints !== "undefined" && uniqueConstraints.length > 0) {
12478
12478
  for (const uniqueConstraint5 of uniqueConstraints) {
@@ -13127,7 +13127,7 @@ WITH ${withCheckOption} CHECK OPTION` : "";
13127
13127
  }
13128
13128
  convert(statement) {
13129
13129
  const { tableNameFrom, tableNameTo } = statement;
13130
- return `RENAME TABLE \`${tableNameFrom}\` TO \`${tableNameTo}\`;`;
13130
+ return `ALTER TABLE \`${tableNameFrom}\` RENAME TO \`${tableNameTo}\`;`;
13131
13131
  }
13132
13132
  };
13133
13133
  PgAlterTableRenameColumnConvertor = class extends Convertor {
@@ -13155,7 +13155,7 @@ WITH ${withCheckOption} CHECK OPTION` : "";
13155
13155
  }
13156
13156
  convert(statement) {
13157
13157
  const { tableName, oldColumnName, newColumnName } = statement;
13158
- return `ALTER TABLE \`${tableName}\` RENAME COLUMN \`${oldColumnName}\` TO \`${newColumnName}\`;`;
13158
+ return `ALTER TABLE \`${tableName}\` CHANGE \`${oldColumnName}\` \`${newColumnName}\`;`;
13159
13159
  }
13160
13160
  };
13161
13161
  SQLiteAlterTableRenameColumnConvertor = class extends Convertor {
@@ -14278,8 +14278,10 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${statement.newC
14278
14278
  return statement.type === "drop_index" && dialect6 === "postgresql";
14279
14279
  }
14280
14280
  convert(statement) {
14281
+ const { schema: schema5 } = statement;
14281
14282
  const { name: name2 } = PgSquasher.unsquashIdx(statement.data);
14282
- return `DROP INDEX "${name2}";`;
14283
+ const indexNameWithSchema = schema5 ? `"${schema5}"."${name2}"` : `"${name2}"`;
14284
+ return `DROP INDEX ${indexNameWithSchema};`;
14283
14285
  }
14284
14286
  };
14285
14287
  PgCreateSchemaConvertor = class extends Convertor {
@@ -14463,10 +14465,52 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${statement.newC
14463
14465
  return sqlStatements;
14464
14466
  }
14465
14467
  };
14468
+ SingleStoreRecreateTableConvertor = class extends Convertor {
14469
+ can(statement, dialect6) {
14470
+ return statement.type === "singlestore_recreate_table" && dialect6 === "singlestore";
14471
+ }
14472
+ convert(statement) {
14473
+ const { tableName, columns, compositePKs, uniqueConstraints } = statement;
14474
+ const columnNames = columns.map((it) => `\`${it.name}\``).join(", ");
14475
+ const newTableName = `__new_${tableName}`;
14476
+ const sqlStatements = [];
14477
+ sqlStatements.push(
14478
+ new SingleStoreCreateTableConvertor().convert({
14479
+ type: "create_table",
14480
+ tableName: newTableName,
14481
+ columns,
14482
+ compositePKs,
14483
+ uniqueConstraints,
14484
+ schema: ""
14485
+ })
14486
+ );
14487
+ sqlStatements.push(
14488
+ `INSERT INTO \`${newTableName}\`(${columnNames}) SELECT ${columnNames} FROM \`${tableName}\`;`
14489
+ );
14490
+ sqlStatements.push(
14491
+ new SingleStoreDropTableConvertor().convert({
14492
+ type: "drop_table",
14493
+ tableName,
14494
+ schema: ""
14495
+ })
14496
+ );
14497
+ sqlStatements.push(
14498
+ new SingleStoreRenameTableConvertor().convert({
14499
+ fromSchema: "",
14500
+ tableNameFrom: newTableName,
14501
+ tableNameTo: tableName,
14502
+ toSchema: "",
14503
+ type: "rename_table"
14504
+ })
14505
+ );
14506
+ return sqlStatements;
14507
+ }
14508
+ };
14466
14509
  convertors = [];
14467
14510
  convertors.push(new PgCreateTableConvertor());
14468
14511
  convertors.push(new MySqlCreateTableConvertor());
14469
14512
  convertors.push(new SingleStoreCreateTableConvertor());
14513
+ convertors.push(new SingleStoreRecreateTableConvertor());
14470
14514
  convertors.push(new SQLiteCreateTableConvertor());
14471
14515
  convertors.push(new SQLiteRecreateTableConvertor());
14472
14516
  convertors.push(new LibSQLRecreateTableConvertor());
@@ -16462,7 +16506,7 @@ var init_jsonStatements = __esm({
16462
16506
  });
16463
16507
 
16464
16508
  // src/statementCombiner.ts
16465
- var prepareLibSQLRecreateTable, prepareSQLiteRecreateTable, libSQLCombineStatements, sqliteCombineStatements;
16509
+ var prepareLibSQLRecreateTable, prepareSQLiteRecreateTable, libSQLCombineStatements, sqliteCombineStatements, prepareSingleStoreRecreateTable, singleStoreCombineStatements;
16466
16510
  var init_statementCombiner = __esm({
16467
16511
  "src/statementCombiner.ts"() {
16468
16512
  "use strict";
@@ -16741,6 +16785,101 @@ var init_statementCombiner = __esm({
16741
16785
  const rest = combinedStatements.filter((it) => it.type !== "rename_table" && it.type !== "alter_table_rename_column");
16742
16786
  return [...renamedTables, ...renamedColumns, ...rest];
16743
16787
  };
16788
+ prepareSingleStoreRecreateTable = (table5) => {
16789
+ const { name: name2, columns, uniqueConstraints, indexes, compositePrimaryKeys } = table5;
16790
+ const composites = Object.values(compositePrimaryKeys);
16791
+ const statements = [
16792
+ {
16793
+ type: "singlestore_recreate_table",
16794
+ tableName: name2,
16795
+ columns: Object.values(columns),
16796
+ compositePKs: composites,
16797
+ uniqueConstraints: Object.values(uniqueConstraints)
16798
+ }
16799
+ ];
16800
+ if (Object.keys(indexes).length) {
16801
+ statements.push(...prepareCreateIndexesJson(name2, "", indexes));
16802
+ }
16803
+ return statements;
16804
+ };
16805
+ singleStoreCombineStatements = (statements, json22) => {
16806
+ const newStatements = {};
16807
+ for (const statement of statements) {
16808
+ 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") {
16809
+ const tableName2 = statement.tableName;
16810
+ const statementsForTable2 = newStatements[tableName2];
16811
+ if (!statementsForTable2) {
16812
+ newStatements[tableName2] = prepareSingleStoreRecreateTable(json22.tables[tableName2]);
16813
+ continue;
16814
+ }
16815
+ if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
16816
+ const wasRename = statementsForTable2.some(
16817
+ ({ type }) => type === "rename_table" || type === "alter_table_rename_column"
16818
+ );
16819
+ const preparedStatements = prepareSingleStoreRecreateTable(json22.tables[tableName2]);
16820
+ if (wasRename) {
16821
+ newStatements[tableName2].push(...preparedStatements);
16822
+ } else {
16823
+ newStatements[tableName2] = preparedStatements;
16824
+ }
16825
+ continue;
16826
+ }
16827
+ continue;
16828
+ }
16829
+ if ((statement.type === "alter_table_alter_column_drop_default" || statement.type === "alter_table_alter_column_set_default") && statement.columnNotNull) {
16830
+ const tableName2 = statement.tableName;
16831
+ const statementsForTable2 = newStatements[tableName2];
16832
+ if (!statementsForTable2) {
16833
+ newStatements[tableName2] = prepareSingleStoreRecreateTable(json22.tables[tableName2]);
16834
+ continue;
16835
+ }
16836
+ if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
16837
+ const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
16838
+ const preparedStatements = prepareSingleStoreRecreateTable(json22.tables[tableName2]);
16839
+ if (wasRename) {
16840
+ newStatements[tableName2].push(...preparedStatements);
16841
+ } else {
16842
+ newStatements[tableName2] = preparedStatements;
16843
+ }
16844
+ continue;
16845
+ }
16846
+ continue;
16847
+ }
16848
+ if (statement.type === "alter_table_add_column" && statement.column.primaryKey) {
16849
+ const tableName2 = statement.tableName;
16850
+ const statementsForTable2 = newStatements[tableName2];
16851
+ if (!statementsForTable2) {
16852
+ newStatements[tableName2] = prepareSingleStoreRecreateTable(json22.tables[tableName2]);
16853
+ continue;
16854
+ }
16855
+ if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
16856
+ const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
16857
+ const preparedStatements = prepareSingleStoreRecreateTable(json22.tables[tableName2]);
16858
+ if (wasRename) {
16859
+ newStatements[tableName2].push(...preparedStatements);
16860
+ } else {
16861
+ newStatements[tableName2] = preparedStatements;
16862
+ }
16863
+ continue;
16864
+ }
16865
+ continue;
16866
+ }
16867
+ const tableName = statement.type === "rename_table" ? statement.tableNameTo : statement.tableName;
16868
+ const statementsForTable = newStatements[tableName];
16869
+ if (!statementsForTable) {
16870
+ newStatements[tableName] = [statement];
16871
+ continue;
16872
+ }
16873
+ if (!statementsForTable.some(({ type }) => type === "singlestore_recreate_table")) {
16874
+ newStatements[tableName].push(statement);
16875
+ }
16876
+ }
16877
+ const combinedStatements = Object.values(newStatements).flat();
16878
+ const renamedTables = combinedStatements.filter((it) => it.type === "rename_table");
16879
+ const renamedColumns = combinedStatements.filter((it) => it.type === "alter_table_rename_column");
16880
+ const rest = combinedStatements.filter((it) => it.type !== "rename_table" && it.type !== "alter_table_rename_column");
16881
+ return [...renamedTables, ...renamedColumns, ...rest];
16882
+ };
16744
16883
  }
16745
16884
  });
16746
16885
 
@@ -18686,7 +18825,7 @@ var init_snapshotsDiffer = __esm({
18686
18825
  return [tableKey2, tableValue];
18687
18826
  }
18688
18827
  );
18689
- const diffResult = applyJsonDiff(tablesPatchedSnap1, json22);
18828
+ const diffResult = applyJsonDiff(columnsPatchedSnap1, json22);
18690
18829
  const typedResult = diffResultSchemeSingleStore.parse(diffResult);
18691
18830
  const jsonStatements = [];
18692
18831
  const jsonCreateIndexesForCreatedTables = createdTables.map((it) => {
@@ -18850,7 +18989,8 @@ var init_snapshotsDiffer = __esm({
18850
18989
  jsonStatements.push(...jsonDropColumnsStatemets);
18851
18990
  jsonStatements.push(...jsonAddedCompositePKs);
18852
18991
  jsonStatements.push(...jsonAlteredUniqueConstraints);
18853
- const sqlStatements = fromJson(jsonStatements, "singlestore");
18992
+ const combinedJsonStatements = singleStoreCombineStatements(jsonStatements, json22);
18993
+ const sqlStatements = fromJson(combinedJsonStatements, "singlestore");
18854
18994
  const uniqueSqlStatements = [];
18855
18995
  sqlStatements.forEach((ss) => {
18856
18996
  if (!uniqueSqlStatements.includes(ss)) {
@@ -18862,7 +19002,7 @@ var init_snapshotsDiffer = __esm({
18862
19002
  });
18863
19003
  const _meta = prepareMigrationMeta([], rTables, rColumns);
18864
19004
  return {
18865
- statements: jsonStatements,
19005
+ statements: combinedJsonStatements,
18866
19006
  sqlStatements: uniqueSqlStatements,
18867
19007
  _meta
18868
19008
  };
@@ -21980,7 +22120,7 @@ var version;
21980
22120
  var init_version = __esm({
21981
22121
  "../drizzle-orm/dist/version.js"() {
21982
22122
  "use strict";
21983
- version = "0.38.3";
22123
+ version = "0.38.4";
21984
22124
  }
21985
22125
  });
21986
22126
 
@@ -22168,6 +22308,9 @@ function fillPlaceholders(params, values) {
22168
22308
  function isView(view4) {
22169
22309
  return typeof view4 === "object" && view4 !== null && IsDrizzleView in view4;
22170
22310
  }
22311
+ function getViewName(view4) {
22312
+ return view4[ViewBaseConfig].name;
22313
+ }
22171
22314
  var _a19, FakePrimitiveParam, _a20, StringChunk, _a21, _SQL, SQL, _a22, Name, noopDecoder, noopEncoder, noopMapper, _a23, Param, _a24, Placeholder, IsDrizzleView, _a25, _b10, _c2, View3;
22172
22315
  var init_sql = __esm({
22173
22316
  "../drizzle-orm/dist/sql/sql.js"() {
@@ -22462,8 +22605,8 @@ var init_sql = __esm({
22462
22605
  sql2.param = param2;
22463
22606
  })(sql || (sql = {}));
22464
22607
  ((SQL2) => {
22465
- var _a413;
22466
- _a413 = entityKind;
22608
+ var _a415;
22609
+ _a415 = entityKind;
22467
22610
  const _Aliased = class _Aliased {
22468
22611
  constructor(sql2, fieldAlias) {
22469
22612
  /** @internal */
@@ -22479,7 +22622,7 @@ var init_sql = __esm({
22479
22622
  return new _Aliased(this.sql, this.fieldAlias);
22480
22623
  }
22481
22624
  };
22482
- __publicField(_Aliased, _a413, "SQL.Aliased");
22625
+ __publicField(_Aliased, _a415, "SQL.Aliased");
22483
22626
  let Aliased = _Aliased;
22484
22627
  SQL2.Aliased = Aliased;
22485
22628
  })(SQL || (SQL = {}));
@@ -25294,6 +25437,7 @@ __export(dist_exports, {
25294
25437
  getTableLikeName: () => getTableLikeName,
25295
25438
  getTableName: () => getTableName,
25296
25439
  getTableUniqueName: () => getTableUniqueName,
25440
+ getViewName: () => getViewName,
25297
25441
  getViewSelectedFields: () => getViewSelectedFields,
25298
25442
  gt: () => gt,
25299
25443
  gte: () => gte,
@@ -25448,17 +25592,100 @@ var init_columns = __esm({
25448
25592
  }
25449
25593
  });
25450
25594
 
25595
+ // ../drizzle-orm/dist/selection-proxy.js
25596
+ var _a124, _SelectionProxyHandler, SelectionProxyHandler;
25597
+ var init_selection_proxy = __esm({
25598
+ "../drizzle-orm/dist/selection-proxy.js"() {
25599
+ "use strict";
25600
+ init_alias();
25601
+ init_column();
25602
+ init_entity();
25603
+ init_sql();
25604
+ init_subquery();
25605
+ init_view_common();
25606
+ _a124 = entityKind;
25607
+ _SelectionProxyHandler = class _SelectionProxyHandler {
25608
+ constructor(config) {
25609
+ __publicField(this, "config");
25610
+ this.config = { ...config };
25611
+ }
25612
+ get(subquery, prop) {
25613
+ if (prop === "_") {
25614
+ return {
25615
+ ...subquery["_"],
25616
+ selectedFields: new Proxy(
25617
+ subquery._.selectedFields,
25618
+ this
25619
+ )
25620
+ };
25621
+ }
25622
+ if (prop === ViewBaseConfig) {
25623
+ return {
25624
+ ...subquery[ViewBaseConfig],
25625
+ selectedFields: new Proxy(
25626
+ subquery[ViewBaseConfig].selectedFields,
25627
+ this
25628
+ )
25629
+ };
25630
+ }
25631
+ if (typeof prop === "symbol") {
25632
+ return subquery[prop];
25633
+ }
25634
+ const columns = is(subquery, Subquery) ? subquery._.selectedFields : is(subquery, View3) ? subquery[ViewBaseConfig].selectedFields : subquery;
25635
+ const value = columns[prop];
25636
+ if (is(value, SQL.Aliased)) {
25637
+ if (this.config.sqlAliasedBehavior === "sql" && !value.isSelectionField) {
25638
+ return value.sql;
25639
+ }
25640
+ const newValue = value.clone();
25641
+ newValue.isSelectionField = true;
25642
+ return newValue;
25643
+ }
25644
+ if (is(value, SQL)) {
25645
+ if (this.config.sqlBehavior === "sql") {
25646
+ return value;
25647
+ }
25648
+ throw new Error(
25649
+ `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.`
25650
+ );
25651
+ }
25652
+ if (is(value, Column2)) {
25653
+ if (this.config.alias) {
25654
+ return new Proxy(
25655
+ value,
25656
+ new ColumnAliasProxyHandler(
25657
+ new Proxy(
25658
+ value.table,
25659
+ new TableAliasProxyHandler(this.config.alias, this.config.replaceOriginalName ?? false)
25660
+ )
25661
+ )
25662
+ );
25663
+ }
25664
+ return value;
25665
+ }
25666
+ if (typeof value !== "object" || value === null) {
25667
+ return value;
25668
+ }
25669
+ return new Proxy(value, new _SelectionProxyHandler(this.config));
25670
+ }
25671
+ };
25672
+ __publicField(_SelectionProxyHandler, _a124, "SelectionProxyHandler");
25673
+ SelectionProxyHandler = _SelectionProxyHandler;
25674
+ }
25675
+ });
25676
+
25451
25677
  // ../drizzle-orm/dist/pg-core/query-builders/delete.js
25452
- var _a124, _b97, PgDeleteBase;
25678
+ var _a125, _b97, PgDeleteBase;
25453
25679
  var init_delete = __esm({
25454
25680
  "../drizzle-orm/dist/pg-core/query-builders/delete.js"() {
25455
25681
  "use strict";
25456
25682
  init_entity();
25457
25683
  init_query_promise();
25684
+ init_selection_proxy();
25458
25685
  init_table();
25459
25686
  init_tracing();
25460
25687
  init_utils2();
25461
- PgDeleteBase = class extends (_b97 = QueryPromise, _a124 = entityKind, _b97) {
25688
+ PgDeleteBase = class extends (_b97 = QueryPromise, _a125 = entityKind, _b97) {
25462
25689
  constructor(table5, session, dialect6, withList) {
25463
25690
  super();
25464
25691
  __publicField(this, "config");
@@ -25506,6 +25733,7 @@ var init_delete = __esm({
25506
25733
  return this;
25507
25734
  }
25508
25735
  returning(fields = this.config.table[Table2.Symbol.Columns]) {
25736
+ this.config.returningFields = fields;
25509
25737
  this.config.returning = orderSelectedFields(fields);
25510
25738
  return this;
25511
25739
  }
@@ -25531,11 +25759,22 @@ var init_delete = __esm({
25531
25759
  this.authToken = token;
25532
25760
  return this;
25533
25761
  }
25762
+ /** @internal */
25763
+ getSelectedFields() {
25764
+ return this.config.returningFields ? new Proxy(
25765
+ this.config.returningFields,
25766
+ new SelectionProxyHandler({
25767
+ alias: getTableName(this.config.table),
25768
+ sqlAliasedBehavior: "alias",
25769
+ sqlBehavior: "error"
25770
+ })
25771
+ ) : void 0;
25772
+ }
25534
25773
  $dynamic() {
25535
25774
  return this;
25536
25775
  }
25537
25776
  };
25538
- __publicField(PgDeleteBase, _a124, "PgDelete");
25777
+ __publicField(PgDeleteBase, _a125, "PgDelete");
25539
25778
  }
25540
25779
  });
25541
25780
 
@@ -25554,13 +25793,13 @@ function toCamelCase(input) {
25554
25793
  function noopCase(input) {
25555
25794
  return input;
25556
25795
  }
25557
- var _a125, CasingCache;
25796
+ var _a126, CasingCache;
25558
25797
  var init_casing = __esm({
25559
25798
  "../drizzle-orm/dist/casing.js"() {
25560
25799
  "use strict";
25561
25800
  init_entity();
25562
25801
  init_table();
25563
- _a125 = entityKind;
25802
+ _a126 = entityKind;
25564
25803
  CasingCache = class {
25565
25804
  constructor(casing2) {
25566
25805
  /** @internal */
@@ -25597,25 +25836,25 @@ var init_casing = __esm({
25597
25836
  this.cachedTables = {};
25598
25837
  }
25599
25838
  };
25600
- __publicField(CasingCache, _a125, "CasingCache");
25839
+ __publicField(CasingCache, _a126, "CasingCache");
25601
25840
  }
25602
25841
  });
25603
25842
 
25604
25843
  // ../drizzle-orm/dist/pg-core/view-base.js
25605
- var _a126, _b98, PgViewBase;
25844
+ var _a127, _b98, PgViewBase;
25606
25845
  var init_view_base = __esm({
25607
25846
  "../drizzle-orm/dist/pg-core/view-base.js"() {
25608
25847
  "use strict";
25609
25848
  init_entity();
25610
25849
  init_sql();
25611
- PgViewBase = class extends (_b98 = View3, _a126 = entityKind, _b98) {
25850
+ PgViewBase = class extends (_b98 = View3, _a127 = entityKind, _b98) {
25612
25851
  };
25613
- __publicField(PgViewBase, _a126, "PgViewBase");
25852
+ __publicField(PgViewBase, _a127, "PgViewBase");
25614
25853
  }
25615
25854
  });
25616
25855
 
25617
25856
  // ../drizzle-orm/dist/pg-core/dialect.js
25618
- var _a127, PgDialect;
25857
+ var _a128, PgDialect;
25619
25858
  var init_dialect = __esm({
25620
25859
  "../drizzle-orm/dist/pg-core/dialect.js"() {
25621
25860
  "use strict";
@@ -25634,7 +25873,7 @@ var init_dialect = __esm({
25634
25873
  init_utils2();
25635
25874
  init_view_common();
25636
25875
  init_view_base();
25637
- _a127 = entityKind;
25876
+ _a128 = entityKind;
25638
25877
  PgDialect = class {
25639
25878
  constructor(config) {
25640
25879
  /** @internal */
@@ -26726,89 +26965,7 @@ var init_dialect = __esm({
26726
26965
  };
26727
26966
  }
26728
26967
  };
26729
- __publicField(PgDialect, _a127, "PgDialect");
26730
- }
26731
- });
26732
-
26733
- // ../drizzle-orm/dist/selection-proxy.js
26734
- var _a128, _SelectionProxyHandler, SelectionProxyHandler;
26735
- var init_selection_proxy = __esm({
26736
- "../drizzle-orm/dist/selection-proxy.js"() {
26737
- "use strict";
26738
- init_alias();
26739
- init_column();
26740
- init_entity();
26741
- init_sql();
26742
- init_subquery();
26743
- init_view_common();
26744
- _a128 = entityKind;
26745
- _SelectionProxyHandler = class _SelectionProxyHandler {
26746
- constructor(config) {
26747
- __publicField(this, "config");
26748
- this.config = { ...config };
26749
- }
26750
- get(subquery, prop) {
26751
- if (prop === "_") {
26752
- return {
26753
- ...subquery["_"],
26754
- selectedFields: new Proxy(
26755
- subquery._.selectedFields,
26756
- this
26757
- )
26758
- };
26759
- }
26760
- if (prop === ViewBaseConfig) {
26761
- return {
26762
- ...subquery[ViewBaseConfig],
26763
- selectedFields: new Proxy(
26764
- subquery[ViewBaseConfig].selectedFields,
26765
- this
26766
- )
26767
- };
26768
- }
26769
- if (typeof prop === "symbol") {
26770
- return subquery[prop];
26771
- }
26772
- const columns = is(subquery, Subquery) ? subquery._.selectedFields : is(subquery, View3) ? subquery[ViewBaseConfig].selectedFields : subquery;
26773
- const value = columns[prop];
26774
- if (is(value, SQL.Aliased)) {
26775
- if (this.config.sqlAliasedBehavior === "sql" && !value.isSelectionField) {
26776
- return value.sql;
26777
- }
26778
- const newValue = value.clone();
26779
- newValue.isSelectionField = true;
26780
- return newValue;
26781
- }
26782
- if (is(value, SQL)) {
26783
- if (this.config.sqlBehavior === "sql") {
26784
- return value;
26785
- }
26786
- throw new Error(
26787
- `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.`
26788
- );
26789
- }
26790
- if (is(value, Column2)) {
26791
- if (this.config.alias) {
26792
- return new Proxy(
26793
- value,
26794
- new ColumnAliasProxyHandler(
26795
- new Proxy(
26796
- value.table,
26797
- new TableAliasProxyHandler(this.config.alias, this.config.replaceOriginalName ?? false)
26798
- )
26799
- )
26800
- );
26801
- }
26802
- return value;
26803
- }
26804
- if (typeof value !== "object" || value === null) {
26805
- return value;
26806
- }
26807
- return new Proxy(value, new _SelectionProxyHandler(this.config));
26808
- }
26809
- };
26810
- __publicField(_SelectionProxyHandler, _a128, "SelectionProxyHandler");
26811
- SelectionProxyHandler = _SelectionProxyHandler;
26968
+ __publicField(PgDialect, _a128, "PgDialect");
26812
26969
  }
26813
26970
  });
26814
26971
 
@@ -26893,22 +27050,23 @@ var init_select2 = __esm({
26893
27050
  */
26894
27051
  from(source) {
26895
27052
  const isPartialSelect = !!this.fields;
27053
+ const src = source;
26896
27054
  let fields;
26897
27055
  if (this.fields) {
26898
27056
  fields = this.fields;
26899
- } else if (is(source, Subquery)) {
27057
+ } else if (is(src, Subquery)) {
26900
27058
  fields = Object.fromEntries(
26901
- Object.keys(source._.selectedFields).map((key) => [key, source[key]])
27059
+ Object.keys(src._.selectedFields).map((key) => [key, src[key]])
26902
27060
  );
26903
- } else if (is(source, PgViewBase)) {
26904
- fields = source[ViewBaseConfig].selectedFields;
26905
- } else if (is(source, SQL)) {
27061
+ } else if (is(src, PgViewBase)) {
27062
+ fields = src[ViewBaseConfig].selectedFields;
27063
+ } else if (is(src, SQL)) {
26906
27064
  fields = {};
26907
27065
  } else {
26908
- fields = getTableColumns(source);
27066
+ fields = getTableColumns(src);
26909
27067
  }
26910
27068
  return new PgSelectBase({
26911
- table: source,
27069
+ table: src,
26912
27070
  fields,
26913
27071
  isPartialSelect,
26914
27072
  session: this.session,
@@ -27593,22 +27751,26 @@ var init_query_builder2 = __esm({
27593
27751
  constructor(dialect6) {
27594
27752
  __publicField(this, "dialect");
27595
27753
  __publicField(this, "dialectConfig");
27596
- this.dialect = is(dialect6, PgDialect) ? dialect6 : void 0;
27597
- this.dialectConfig = is(dialect6, PgDialect) ? void 0 : dialect6;
27598
- }
27599
- $with(alias) {
27600
- const queryBuilder = this;
27601
- return {
27602
- as(qb) {
27754
+ __publicField(this, "$with", (alias, selection) => {
27755
+ const queryBuilder = this;
27756
+ const as = (qb) => {
27603
27757
  if (typeof qb === "function") {
27604
27758
  qb = qb(queryBuilder);
27605
27759
  }
27606
27760
  return new Proxy(
27607
- new WithSubquery(qb.getSQL(), qb.getSelectedFields(), alias, true),
27761
+ new WithSubquery(
27762
+ qb.getSQL(),
27763
+ selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}),
27764
+ alias,
27765
+ true
27766
+ ),
27608
27767
  new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
27609
27768
  );
27610
- }
27611
- };
27769
+ };
27770
+ return { as };
27771
+ });
27772
+ this.dialect = is(dialect6, PgDialect) ? dialect6 : void 0;
27773
+ this.dialectConfig = is(dialect6, PgDialect) ? void 0 : dialect6;
27612
27774
  }
27613
27775
  with(...queries) {
27614
27776
  const self2 = this;
@@ -27680,6 +27842,7 @@ var init_insert = __esm({
27680
27842
  "use strict";
27681
27843
  init_entity();
27682
27844
  init_query_promise();
27845
+ init_selection_proxy();
27683
27846
  init_sql();
27684
27847
  init_table();
27685
27848
  init_tracing();
@@ -27754,6 +27917,7 @@ var init_insert = __esm({
27754
27917
  this.config = { table: table5, values, withList, select, overridingSystemValue_ };
27755
27918
  }
27756
27919
  returning(fields = this.config.table[Table2.Symbol.Columns]) {
27920
+ this.config.returningFields = fields;
27757
27921
  this.config.returning = orderSelectedFields(fields);
27758
27922
  return this;
27759
27923
  }
@@ -27856,6 +28020,17 @@ var init_insert = __esm({
27856
28020
  this.authToken = token;
27857
28021
  return this;
27858
28022
  }
28023
+ /** @internal */
28024
+ getSelectedFields() {
28025
+ return this.config.returningFields ? new Proxy(
28026
+ this.config.returningFields,
28027
+ new SelectionProxyHandler({
28028
+ alias: getTableName(this.config.table),
28029
+ sqlAliasedBehavior: "alias",
28030
+ sqlBehavior: "error"
28031
+ })
28032
+ ) : void 0;
28033
+ }
27859
28034
  $dynamic() {
27860
28035
  return this;
27861
28036
  }
@@ -27993,11 +28168,12 @@ var init_update = __esm({
27993
28168
  this.joinsNotNullableMap = typeof this.tableName === "string" ? { [this.tableName]: true } : {};
27994
28169
  }
27995
28170
  from(source) {
27996
- const tableName = getTableLikeName(source);
28171
+ const src = source;
28172
+ const tableName = getTableLikeName(src);
27997
28173
  if (typeof tableName === "string") {
27998
28174
  this.joinsNotNullableMap[tableName] = true;
27999
28175
  }
28000
- this.config.from = source;
28176
+ this.config.from = src;
28001
28177
  return this;
28002
28178
  }
28003
28179
  getTableLikeFields(table5) {
@@ -28112,6 +28288,7 @@ var init_update = __esm({
28112
28288
  }
28113
28289
  }
28114
28290
  }
28291
+ this.config.returningFields = fields;
28115
28292
  this.config.returning = orderSelectedFields(fields);
28116
28293
  return this;
28117
28294
  }
@@ -28137,6 +28314,17 @@ var init_update = __esm({
28137
28314
  this.authToken = token;
28138
28315
  return this;
28139
28316
  }
28317
+ /** @internal */
28318
+ getSelectedFields() {
28319
+ return this.config.returningFields ? new Proxy(
28320
+ this.config.returningFields,
28321
+ new SelectionProxyHandler({
28322
+ alias: getTableName(this.config.table),
28323
+ sqlAliasedBehavior: "alias",
28324
+ sqlBehavior: "error"
28325
+ })
28326
+ ) : void 0;
28327
+ }
28140
28328
  $dynamic() {
28141
28329
  return this;
28142
28330
  }
@@ -28398,6 +28586,56 @@ var init_db = __esm({
28398
28586
  PgDatabase = class {
28399
28587
  constructor(dialect6, session, schema5) {
28400
28588
  __publicField(this, "query");
28589
+ /**
28590
+ * Creates a subquery that defines a temporary named result set as a CTE.
28591
+ *
28592
+ * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.
28593
+ *
28594
+ * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
28595
+ *
28596
+ * @param alias The alias for the subquery.
28597
+ *
28598
+ * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.
28599
+ *
28600
+ * @example
28601
+ *
28602
+ * ```ts
28603
+ * // Create a subquery with alias 'sq' and use it in the select query
28604
+ * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
28605
+ *
28606
+ * const result = await db.with(sq).select().from(sq);
28607
+ * ```
28608
+ *
28609
+ * 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:
28610
+ *
28611
+ * ```ts
28612
+ * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query
28613
+ * const sq = db.$with('sq').as(db.select({
28614
+ * name: sql<string>`upper(${users.name})`.as('name'),
28615
+ * })
28616
+ * .from(users));
28617
+ *
28618
+ * const result = await db.with(sq).select({ name: sq.name }).from(sq);
28619
+ * ```
28620
+ */
28621
+ __publicField(this, "$with", (alias, selection) => {
28622
+ const self2 = this;
28623
+ const as = (qb) => {
28624
+ if (typeof qb === "function") {
28625
+ qb = qb(new QueryBuilder(self2.dialect));
28626
+ }
28627
+ return new Proxy(
28628
+ new WithSubquery(
28629
+ qb.getSQL(),
28630
+ selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}),
28631
+ alias,
28632
+ true
28633
+ ),
28634
+ new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
28635
+ );
28636
+ };
28637
+ return { as };
28638
+ });
28401
28639
  __publicField(this, "authToken");
28402
28640
  this.dialect = dialect6;
28403
28641
  this.session = session;
@@ -28427,52 +28665,6 @@ var init_db = __esm({
28427
28665
  }
28428
28666
  }
28429
28667
  }
28430
- /**
28431
- * Creates a subquery that defines a temporary named result set as a CTE.
28432
- *
28433
- * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.
28434
- *
28435
- * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
28436
- *
28437
- * @param alias The alias for the subquery.
28438
- *
28439
- * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.
28440
- *
28441
- * @example
28442
- *
28443
- * ```ts
28444
- * // Create a subquery with alias 'sq' and use it in the select query
28445
- * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
28446
- *
28447
- * const result = await db.with(sq).select().from(sq);
28448
- * ```
28449
- *
28450
- * 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:
28451
- *
28452
- * ```ts
28453
- * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query
28454
- * const sq = db.$with('sq').as(db.select({
28455
- * name: sql<string>`upper(${users.name})`.as('name'),
28456
- * })
28457
- * .from(users));
28458
- *
28459
- * const result = await db.with(sq).select({ name: sq.name }).from(sq);
28460
- * ```
28461
- */
28462
- $with(alias) {
28463
- const self2 = this;
28464
- return {
28465
- as(qb) {
28466
- if (typeof qb === "function") {
28467
- qb = qb(new QueryBuilder(self2.dialect));
28468
- }
28469
- return new Proxy(
28470
- new WithSubquery(qb.getSQL(), qb.getSelectedFields(), alias, true),
28471
- new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
28472
- );
28473
- }
28474
- };
28475
- }
28476
28668
  $count(source, filters) {
28477
28669
  return new PgCountBuilder({ source, filters, session: this.session });
28478
28670
  }
@@ -33223,22 +33415,26 @@ var init_query_builder3 = __esm({
33223
33415
  constructor(dialect6) {
33224
33416
  __publicField(this, "dialect");
33225
33417
  __publicField(this, "dialectConfig");
33226
- this.dialect = is(dialect6, SQLiteDialect) ? dialect6 : void 0;
33227
- this.dialectConfig = is(dialect6, SQLiteDialect) ? void 0 : dialect6;
33228
- }
33229
- $with(alias) {
33230
- const queryBuilder = this;
33231
- return {
33232
- as(qb) {
33418
+ __publicField(this, "$with", (alias, selection) => {
33419
+ const queryBuilder = this;
33420
+ const as = (qb) => {
33233
33421
  if (typeof qb === "function") {
33234
33422
  qb = qb(queryBuilder);
33235
33423
  }
33236
33424
  return new Proxy(
33237
- new WithSubquery(qb.getSQL(), qb.getSelectedFields(), alias, true),
33425
+ new WithSubquery(
33426
+ qb.getSQL(),
33427
+ selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}),
33428
+ alias,
33429
+ true
33430
+ ),
33238
33431
  new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
33239
33432
  );
33240
- }
33241
- };
33433
+ };
33434
+ return { as };
33435
+ });
33436
+ this.dialect = is(dialect6, SQLiteDialect) ? dialect6 : void 0;
33437
+ this.dialectConfig = is(dialect6, SQLiteDialect) ? void 0 : dialect6;
33242
33438
  }
33243
33439
  with(...queries) {
33244
33440
  const self2 = this;
@@ -33919,6 +34115,56 @@ var init_db2 = __esm({
33919
34115
  BaseSQLiteDatabase = class {
33920
34116
  constructor(resultKind, dialect6, session, schema5) {
33921
34117
  __publicField(this, "query");
34118
+ /**
34119
+ * Creates a subquery that defines a temporary named result set as a CTE.
34120
+ *
34121
+ * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.
34122
+ *
34123
+ * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
34124
+ *
34125
+ * @param alias The alias for the subquery.
34126
+ *
34127
+ * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.
34128
+ *
34129
+ * @example
34130
+ *
34131
+ * ```ts
34132
+ * // Create a subquery with alias 'sq' and use it in the select query
34133
+ * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
34134
+ *
34135
+ * const result = await db.with(sq).select().from(sq);
34136
+ * ```
34137
+ *
34138
+ * 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:
34139
+ *
34140
+ * ```ts
34141
+ * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query
34142
+ * const sq = db.$with('sq').as(db.select({
34143
+ * name: sql<string>`upper(${users.name})`.as('name'),
34144
+ * })
34145
+ * .from(users));
34146
+ *
34147
+ * const result = await db.with(sq).select({ name: sq.name }).from(sq);
34148
+ * ```
34149
+ */
34150
+ __publicField(this, "$with", (alias, selection) => {
34151
+ const self2 = this;
34152
+ const as = (qb) => {
34153
+ if (typeof qb === "function") {
34154
+ qb = qb(new QueryBuilder2(self2.dialect));
34155
+ }
34156
+ return new Proxy(
34157
+ new WithSubquery(
34158
+ qb.getSQL(),
34159
+ selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}),
34160
+ alias,
34161
+ true
34162
+ ),
34163
+ new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
34164
+ );
34165
+ };
34166
+ return { as };
34167
+ });
33922
34168
  this.resultKind = resultKind;
33923
34169
  this.dialect = dialect6;
33924
34170
  this.session = session;
@@ -33948,52 +34194,6 @@ var init_db2 = __esm({
33948
34194
  }
33949
34195
  }
33950
34196
  }
33951
- /**
33952
- * Creates a subquery that defines a temporary named result set as a CTE.
33953
- *
33954
- * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.
33955
- *
33956
- * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
33957
- *
33958
- * @param alias The alias for the subquery.
33959
- *
33960
- * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.
33961
- *
33962
- * @example
33963
- *
33964
- * ```ts
33965
- * // Create a subquery with alias 'sq' and use it in the select query
33966
- * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
33967
- *
33968
- * const result = await db.with(sq).select().from(sq);
33969
- * ```
33970
- *
33971
- * 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:
33972
- *
33973
- * ```ts
33974
- * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query
33975
- * const sq = db.$with('sq').as(db.select({
33976
- * name: sql<string>`upper(${users.name})`.as('name'),
33977
- * })
33978
- * .from(users));
33979
- *
33980
- * const result = await db.with(sq).select({ name: sq.name }).from(sq);
33981
- * ```
33982
- */
33983
- $with(alias) {
33984
- const self2 = this;
33985
- return {
33986
- as(qb) {
33987
- if (typeof qb === "function") {
33988
- qb = qb(new QueryBuilder2(self2.dialect));
33989
- }
33990
- return new Proxy(
33991
- new WithSubquery(qb.getSQL(), qb.getSelectedFields(), alias, true),
33992
- new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
33993
- );
33994
- }
33995
- };
33996
- }
33997
34197
  $count(source, filters) {
33998
34198
  return new SQLiteCountBuilder({ source, filters, session: this.session });
33999
34199
  }
@@ -38816,22 +39016,26 @@ var init_query_builder4 = __esm({
38816
39016
  constructor(dialect6) {
38817
39017
  __publicField(this, "dialect");
38818
39018
  __publicField(this, "dialectConfig");
38819
- this.dialect = is(dialect6, MySqlDialect) ? dialect6 : void 0;
38820
- this.dialectConfig = is(dialect6, MySqlDialect) ? void 0 : dialect6;
38821
- }
38822
- $with(alias) {
38823
- const queryBuilder = this;
38824
- return {
38825
- as(qb) {
39019
+ __publicField(this, "$with", (alias, selection) => {
39020
+ const queryBuilder = this;
39021
+ const as = (qb) => {
38826
39022
  if (typeof qb === "function") {
38827
39023
  qb = qb(queryBuilder);
38828
39024
  }
38829
39025
  return new Proxy(
38830
- new WithSubquery(qb.getSQL(), qb.getSelectedFields(), alias, true),
39026
+ new WithSubquery(
39027
+ qb.getSQL(),
39028
+ selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}),
39029
+ alias,
39030
+ true
39031
+ ),
38831
39032
  new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
38832
39033
  );
38833
- }
38834
- };
39034
+ };
39035
+ return { as };
39036
+ });
39037
+ this.dialect = is(dialect6, MySqlDialect) ? dialect6 : void 0;
39038
+ this.dialectConfig = is(dialect6, MySqlDialect) ? void 0 : dialect6;
38835
39039
  }
38836
39040
  with(...queries) {
38837
39041
  const self2 = this;
@@ -39286,6 +39490,56 @@ var init_db3 = __esm({
39286
39490
  MySqlDatabase = class {
39287
39491
  constructor(dialect6, session, schema5, mode) {
39288
39492
  __publicField(this, "query");
39493
+ /**
39494
+ * Creates a subquery that defines a temporary named result set as a CTE.
39495
+ *
39496
+ * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.
39497
+ *
39498
+ * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
39499
+ *
39500
+ * @param alias The alias for the subquery.
39501
+ *
39502
+ * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.
39503
+ *
39504
+ * @example
39505
+ *
39506
+ * ```ts
39507
+ * // Create a subquery with alias 'sq' and use it in the select query
39508
+ * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
39509
+ *
39510
+ * const result = await db.with(sq).select().from(sq);
39511
+ * ```
39512
+ *
39513
+ * 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:
39514
+ *
39515
+ * ```ts
39516
+ * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query
39517
+ * const sq = db.$with('sq').as(db.select({
39518
+ * name: sql<string>`upper(${users.name})`.as('name'),
39519
+ * })
39520
+ * .from(users));
39521
+ *
39522
+ * const result = await db.with(sq).select({ name: sq.name }).from(sq);
39523
+ * ```
39524
+ */
39525
+ __publicField(this, "$with", (alias, selection) => {
39526
+ const self2 = this;
39527
+ const as = (qb) => {
39528
+ if (typeof qb === "function") {
39529
+ qb = qb(new QueryBuilder3(self2.dialect));
39530
+ }
39531
+ return new Proxy(
39532
+ new WithSubquery(
39533
+ qb.getSQL(),
39534
+ selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}),
39535
+ alias,
39536
+ true
39537
+ ),
39538
+ new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
39539
+ );
39540
+ };
39541
+ return { as };
39542
+ });
39289
39543
  this.dialect = dialect6;
39290
39544
  this.session = session;
39291
39545
  this.mode = mode;
@@ -39314,52 +39568,6 @@ var init_db3 = __esm({
39314
39568
  }
39315
39569
  }
39316
39570
  }
39317
- /**
39318
- * Creates a subquery that defines a temporary named result set as a CTE.
39319
- *
39320
- * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.
39321
- *
39322
- * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
39323
- *
39324
- * @param alias The alias for the subquery.
39325
- *
39326
- * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.
39327
- *
39328
- * @example
39329
- *
39330
- * ```ts
39331
- * // Create a subquery with alias 'sq' and use it in the select query
39332
- * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
39333
- *
39334
- * const result = await db.with(sq).select().from(sq);
39335
- * ```
39336
- *
39337
- * 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:
39338
- *
39339
- * ```ts
39340
- * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query
39341
- * const sq = db.$with('sq').as(db.select({
39342
- * name: sql<string>`upper(${users.name})`.as('name'),
39343
- * })
39344
- * .from(users));
39345
- *
39346
- * const result = await db.with(sq).select({ name: sq.name }).from(sq);
39347
- * ```
39348
- */
39349
- $with(alias) {
39350
- const self2 = this;
39351
- return {
39352
- as(qb) {
39353
- if (typeof qb === "function") {
39354
- qb = qb(new QueryBuilder3(self2.dialect));
39355
- }
39356
- return new Proxy(
39357
- new WithSubquery(qb.getSQL(), qb.getSelectedFields(), alias, true),
39358
- new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
39359
- );
39360
- }
39361
- };
39362
- }
39363
39571
  $count(source, filters) {
39364
39572
  return new MySqlCountBuilder({ source, filters, session: this.session });
39365
39573
  }
@@ -42151,17 +42359,68 @@ var init_varchar3 = __esm({
42151
42359
  }
42152
42360
  });
42153
42361
 
42362
+ // ../drizzle-orm/dist/singlestore-core/columns/vector.js
42363
+ function vector2(a, b) {
42364
+ const { name: name2, config } = getColumnNameAndConfig(a, b);
42365
+ return new SingleStoreVectorBuilder(name2, config);
42366
+ }
42367
+ var _a389, _b293, SingleStoreVectorBuilder, _a390, _b294, SingleStoreVector;
42368
+ var init_vector4 = __esm({
42369
+ "../drizzle-orm/dist/singlestore-core/columns/vector.js"() {
42370
+ "use strict";
42371
+ init_entity();
42372
+ init_utils2();
42373
+ init_common5();
42374
+ SingleStoreVectorBuilder = class extends (_b293 = SingleStoreColumnBuilder, _a389 = entityKind, _b293) {
42375
+ constructor(name2, config) {
42376
+ super(name2, "array", "SingleStoreVector");
42377
+ this.config.dimensions = config.dimensions;
42378
+ this.config.elementType = config.elementType;
42379
+ }
42380
+ /** @internal */
42381
+ build(table5) {
42382
+ return new SingleStoreVector(
42383
+ table5,
42384
+ this.config
42385
+ );
42386
+ }
42387
+ /** @internal */
42388
+ generatedAlwaysAs(as, config) {
42389
+ throw new Error("not implemented");
42390
+ }
42391
+ };
42392
+ __publicField(SingleStoreVectorBuilder, _a389, "SingleStoreVectorBuilder");
42393
+ SingleStoreVector = class extends (_b294 = SingleStoreColumn, _a390 = entityKind, _b294) {
42394
+ constructor() {
42395
+ super(...arguments);
42396
+ __publicField(this, "dimensions", this.config.dimensions);
42397
+ __publicField(this, "elementType", this.config.elementType);
42398
+ }
42399
+ getSQLType() {
42400
+ return `vector(${this.dimensions}, ${this.elementType || "F32"})`;
42401
+ }
42402
+ mapToDriverValue(value) {
42403
+ return JSON.stringify(value);
42404
+ }
42405
+ mapFromDriverValue(value) {
42406
+ return JSON.parse(value);
42407
+ }
42408
+ };
42409
+ __publicField(SingleStoreVector, _a390, "SingleStoreVector");
42410
+ }
42411
+ });
42412
+
42154
42413
  // ../drizzle-orm/dist/singlestore-core/columns/year.js
42155
42414
  function year2(name2) {
42156
42415
  return new SingleStoreYearBuilder(name2 ?? "");
42157
42416
  }
42158
- var _a389, _b293, SingleStoreYearBuilder, _a390, _b294, SingleStoreYear;
42417
+ var _a391, _b295, SingleStoreYearBuilder, _a392, _b296, SingleStoreYear;
42159
42418
  var init_year2 = __esm({
42160
42419
  "../drizzle-orm/dist/singlestore-core/columns/year.js"() {
42161
42420
  "use strict";
42162
42421
  init_entity();
42163
42422
  init_common5();
42164
- SingleStoreYearBuilder = class extends (_b293 = SingleStoreColumnBuilder, _a389 = entityKind, _b293) {
42423
+ SingleStoreYearBuilder = class extends (_b295 = SingleStoreColumnBuilder, _a391 = entityKind, _b295) {
42165
42424
  constructor(name2) {
42166
42425
  super(name2, "number", "SingleStoreYear");
42167
42426
  }
@@ -42173,13 +42432,13 @@ var init_year2 = __esm({
42173
42432
  );
42174
42433
  }
42175
42434
  };
42176
- __publicField(SingleStoreYearBuilder, _a389, "SingleStoreYearBuilder");
42177
- SingleStoreYear = class extends (_b294 = SingleStoreColumn, _a390 = entityKind, _b294) {
42435
+ __publicField(SingleStoreYearBuilder, _a391, "SingleStoreYearBuilder");
42436
+ SingleStoreYear = class extends (_b296 = SingleStoreColumn, _a392 = entityKind, _b296) {
42178
42437
  getSQLType() {
42179
42438
  return `year`;
42180
42439
  }
42181
42440
  };
42182
- __publicField(SingleStoreYear, _a390, "SingleStoreYear");
42441
+ __publicField(SingleStoreYear, _a392, "SingleStoreYear");
42183
42442
  }
42184
42443
  });
42185
42444
 
@@ -42211,22 +42470,23 @@ var init_columns4 = __esm({
42211
42470
  init_tinyint2();
42212
42471
  init_varbinary2();
42213
42472
  init_varchar3();
42473
+ init_vector4();
42214
42474
  init_year2();
42215
42475
  }
42216
42476
  });
42217
42477
 
42218
42478
  // ../drizzle-orm/dist/singlestore-core/query-builders/count.js
42219
- var _a391, _b295, _c12, _SingleStoreCountBuilder, SingleStoreCountBuilder;
42479
+ var _a393, _b297, _c12, _SingleStoreCountBuilder, SingleStoreCountBuilder;
42220
42480
  var init_count4 = __esm({
42221
42481
  "../drizzle-orm/dist/singlestore-core/query-builders/count.js"() {
42222
42482
  "use strict";
42223
42483
  init_entity();
42224
42484
  init_sql();
42225
- _SingleStoreCountBuilder = class _SingleStoreCountBuilder extends (_c12 = SQL, _b295 = entityKind, _a391 = Symbol.toStringTag, _c12) {
42485
+ _SingleStoreCountBuilder = class _SingleStoreCountBuilder extends (_c12 = SQL, _b297 = entityKind, _a393 = Symbol.toStringTag, _c12) {
42226
42486
  constructor(params) {
42227
42487
  super(_SingleStoreCountBuilder.buildEmbeddedCount(params.source, params.filters).queryChunks);
42228
42488
  __publicField(this, "sql");
42229
- __publicField(this, _a391, "SingleStoreCountBuilder");
42489
+ __publicField(this, _a393, "SingleStoreCountBuilder");
42230
42490
  __publicField(this, "session");
42231
42491
  this.params = params;
42232
42492
  this.mapWith(Number);
@@ -42264,13 +42524,13 @@ var init_count4 = __esm({
42264
42524
  );
42265
42525
  }
42266
42526
  };
42267
- __publicField(_SingleStoreCountBuilder, _b295, "SingleStoreCountBuilder");
42527
+ __publicField(_SingleStoreCountBuilder, _b297, "SingleStoreCountBuilder");
42268
42528
  SingleStoreCountBuilder = _SingleStoreCountBuilder;
42269
42529
  }
42270
42530
  });
42271
42531
 
42272
42532
  // ../drizzle-orm/dist/singlestore-core/query-builders/delete.js
42273
- var _a392, _b296, SingleStoreDeleteBase;
42533
+ var _a394, _b298, SingleStoreDeleteBase;
42274
42534
  var init_delete4 = __esm({
42275
42535
  "../drizzle-orm/dist/singlestore-core/query-builders/delete.js"() {
42276
42536
  "use strict";
@@ -42278,7 +42538,7 @@ var init_delete4 = __esm({
42278
42538
  init_query_promise();
42279
42539
  init_selection_proxy();
42280
42540
  init_table();
42281
- SingleStoreDeleteBase = class extends (_b296 = QueryPromise, _a392 = entityKind, _b296) {
42541
+ SingleStoreDeleteBase = class extends (_b298 = QueryPromise, _a394 = entityKind, _b298) {
42282
42542
  constructor(table5, session, dialect6, withList) {
42283
42543
  super();
42284
42544
  __publicField(this, "config");
@@ -42368,12 +42628,12 @@ var init_delete4 = __esm({
42368
42628
  return this;
42369
42629
  }
42370
42630
  };
42371
- __publicField(SingleStoreDeleteBase, _a392, "SingleStoreDelete");
42631
+ __publicField(SingleStoreDeleteBase, _a394, "SingleStoreDelete");
42372
42632
  }
42373
42633
  });
42374
42634
 
42375
42635
  // ../drizzle-orm/dist/singlestore-core/query-builders/insert.js
42376
- var _a393, SingleStoreInsertBuilder, _a394, _b297, SingleStoreInsertBase;
42636
+ var _a395, SingleStoreInsertBuilder, _a396, _b299, SingleStoreInsertBase;
42377
42637
  var init_insert4 = __esm({
42378
42638
  "../drizzle-orm/dist/singlestore-core/query-builders/insert.js"() {
42379
42639
  "use strict";
@@ -42382,7 +42642,7 @@ var init_insert4 = __esm({
42382
42642
  init_sql();
42383
42643
  init_table();
42384
42644
  init_utils2();
42385
- _a393 = entityKind;
42645
+ _a395 = entityKind;
42386
42646
  SingleStoreInsertBuilder = class {
42387
42647
  constructor(table5, session, dialect6) {
42388
42648
  __publicField(this, "shouldIgnore", false);
@@ -42411,8 +42671,8 @@ var init_insert4 = __esm({
42411
42671
  return new SingleStoreInsertBase(this.table, mappedValues, this.shouldIgnore, this.session, this.dialect);
42412
42672
  }
42413
42673
  };
42414
- __publicField(SingleStoreInsertBuilder, _a393, "SingleStoreInsertBuilder");
42415
- SingleStoreInsertBase = class extends (_b297 = QueryPromise, _a394 = entityKind, _b297) {
42674
+ __publicField(SingleStoreInsertBuilder, _a395, "SingleStoreInsertBuilder");
42675
+ SingleStoreInsertBase = class extends (_b299 = QueryPromise, _a396 = entityKind, _b299) {
42416
42676
  constructor(table5, values, ignore, session, dialect6) {
42417
42677
  super();
42418
42678
  __publicField(this, "config");
@@ -42493,7 +42753,7 @@ var init_insert4 = __esm({
42493
42753
  return this;
42494
42754
  }
42495
42755
  };
42496
- __publicField(SingleStoreInsertBase, _a394, "SingleStoreInsert");
42756
+ __publicField(SingleStoreInsertBase, _a396, "SingleStoreInsert");
42497
42757
  }
42498
42758
  });
42499
42759
 
@@ -42526,6 +42786,7 @@ function getSingleStoreColumnBuilders() {
42526
42786
  tinyint: tinyint2,
42527
42787
  varbinary: varbinary2,
42528
42788
  varchar: varchar3,
42789
+ vector: vector2,
42529
42790
  year: year2
42530
42791
  };
42531
42792
  }
@@ -42555,6 +42816,7 @@ var init_all4 = __esm({
42555
42816
  init_tinyint2();
42556
42817
  init_varbinary2();
42557
42818
  init_varchar3();
42819
+ init_vector4();
42558
42820
  init_year2();
42559
42821
  }
42560
42822
  });
@@ -42579,20 +42841,20 @@ function singlestoreTableWithSchema(name2, columns, extraConfig, schema5, baseNa
42579
42841
  }
42580
42842
  return table5;
42581
42843
  }
42582
- var _a395, _b298, _c13, _d5, SingleStoreTable;
42844
+ var _a397, _b300, _c13, _d5, SingleStoreTable;
42583
42845
  var init_table5 = __esm({
42584
42846
  "../drizzle-orm/dist/singlestore-core/table.js"() {
42585
42847
  "use strict";
42586
42848
  init_entity();
42587
42849
  init_table();
42588
42850
  init_all4();
42589
- SingleStoreTable = class extends (_d5 = Table2, _c13 = entityKind, _b298 = Table2.Symbol.Columns, _a395 = Table2.Symbol.ExtraConfigBuilder, _d5) {
42851
+ SingleStoreTable = class extends (_d5 = Table2, _c13 = entityKind, _b300 = Table2.Symbol.Columns, _a397 = Table2.Symbol.ExtraConfigBuilder, _d5) {
42590
42852
  constructor() {
42591
42853
  super(...arguments);
42592
42854
  /** @internal */
42593
- __publicField(this, _b298);
42855
+ __publicField(this, _b300);
42594
42856
  /** @internal */
42595
- __publicField(this, _a395);
42857
+ __publicField(this, _a397);
42596
42858
  }
42597
42859
  };
42598
42860
  __publicField(SingleStoreTable, _c13, "SingleStoreTable");
@@ -42602,7 +42864,7 @@ var init_table5 = __esm({
42602
42864
  });
42603
42865
 
42604
42866
  // ../drizzle-orm/dist/singlestore-core/dialect.js
42605
- var _a396, SingleStoreDialect;
42867
+ var _a398, SingleStoreDialect;
42606
42868
  var init_dialect4 = __esm({
42607
42869
  "../drizzle-orm/dist/singlestore-core/dialect.js"() {
42608
42870
  "use strict";
@@ -42620,7 +42882,7 @@ var init_dialect4 = __esm({
42620
42882
  init_view_common();
42621
42883
  init_common5();
42622
42884
  init_table5();
42623
- _a396 = entityKind;
42885
+ _a398 = entityKind;
42624
42886
  SingleStoreDialect = class {
42625
42887
  constructor(config) {
42626
42888
  /** @internal */
@@ -43185,7 +43447,7 @@ var init_dialect4 = __esm({
43185
43447
  };
43186
43448
  }
43187
43449
  };
43188
- __publicField(SingleStoreDialect, _a396, "SingleStoreDialect");
43450
+ __publicField(SingleStoreDialect, _a398, "SingleStoreDialect");
43189
43451
  }
43190
43452
  });
43191
43453
 
@@ -43207,7 +43469,7 @@ function createSetOperator4(type, isAll) {
43207
43469
  return leftSelect.addSetOperators(setOperators);
43208
43470
  };
43209
43471
  }
43210
- var _a397, SingleStoreSelectBuilder, _a398, _b299, SingleStoreSelectQueryBuilderBase, _a399, _b300, SingleStoreSelectBase, getSingleStoreSetOperators, union4, unionAll4, intersect4, except4, minus;
43472
+ var _a399, SingleStoreSelectBuilder, _a400, _b301, SingleStoreSelectQueryBuilderBase, _a401, _b302, SingleStoreSelectBase, getSingleStoreSetOperators, union4, unionAll4, intersect4, except4, minus;
43211
43473
  var init_select5 = __esm({
43212
43474
  "../drizzle-orm/dist/singlestore-core/query-builders/select.js"() {
43213
43475
  "use strict";
@@ -43219,7 +43481,7 @@ var init_select5 = __esm({
43219
43481
  init_subquery();
43220
43482
  init_table();
43221
43483
  init_utils2();
43222
- _a397 = entityKind;
43484
+ _a399 = entityKind;
43223
43485
  SingleStoreSelectBuilder = class {
43224
43486
  constructor(config) {
43225
43487
  __publicField(this, "fields");
@@ -43262,8 +43524,8 @@ var init_select5 = __esm({
43262
43524
  );
43263
43525
  }
43264
43526
  };
43265
- __publicField(SingleStoreSelectBuilder, _a397, "SingleStoreSelectBuilder");
43266
- SingleStoreSelectQueryBuilderBase = class extends (_b299 = TypedQueryBuilder, _a398 = entityKind, _b299) {
43527
+ __publicField(SingleStoreSelectBuilder, _a399, "SingleStoreSelectBuilder");
43528
+ SingleStoreSelectQueryBuilderBase = class extends (_b301 = TypedQueryBuilder, _a400 = entityKind, _b301) {
43267
43529
  constructor({ table: table5, fields, isPartialSelect, session, dialect: dialect6, withList, distinct }) {
43268
43530
  super();
43269
43531
  __publicField(this, "_");
@@ -43804,8 +44066,8 @@ var init_select5 = __esm({
43804
44066
  return this;
43805
44067
  }
43806
44068
  };
43807
- __publicField(SingleStoreSelectQueryBuilderBase, _a398, "SingleStoreSelectQueryBuilder");
43808
- SingleStoreSelectBase = class extends (_b300 = SingleStoreSelectQueryBuilderBase, _a399 = entityKind, _b300) {
44069
+ __publicField(SingleStoreSelectQueryBuilderBase, _a400, "SingleStoreSelectQueryBuilder");
44070
+ SingleStoreSelectBase = class extends (_b302 = SingleStoreSelectQueryBuilderBase, _a401 = entityKind, _b302) {
43809
44071
  constructor() {
43810
44072
  super(...arguments);
43811
44073
  __publicField(this, "execute", (placeholderValues) => {
@@ -43829,7 +44091,7 @@ var init_select5 = __esm({
43829
44091
  return query;
43830
44092
  }
43831
44093
  };
43832
- __publicField(SingleStoreSelectBase, _a399, "SingleStoreSelect");
44094
+ __publicField(SingleStoreSelectBase, _a401, "SingleStoreSelect");
43833
44095
  applyMixins(SingleStoreSelectBase, [QueryPromise]);
43834
44096
  getSingleStoreSetOperators = () => ({
43835
44097
  union: union4,
@@ -43847,7 +44109,7 @@ var init_select5 = __esm({
43847
44109
  });
43848
44110
 
43849
44111
  // ../drizzle-orm/dist/singlestore-core/query-builders/query-builder.js
43850
- var _a400, QueryBuilder4;
44112
+ var _a402, QueryBuilder4;
43851
44113
  var init_query_builder5 = __esm({
43852
44114
  "../drizzle-orm/dist/singlestore-core/query-builders/query-builder.js"() {
43853
44115
  "use strict";
@@ -43856,27 +44118,31 @@ var init_query_builder5 = __esm({
43856
44118
  init_dialect4();
43857
44119
  init_subquery();
43858
44120
  init_select5();
43859
- _a400 = entityKind;
44121
+ _a402 = entityKind;
43860
44122
  QueryBuilder4 = class {
43861
44123
  constructor(dialect6) {
43862
44124
  __publicField(this, "dialect");
43863
44125
  __publicField(this, "dialectConfig");
43864
- this.dialect = is(dialect6, SingleStoreDialect) ? dialect6 : void 0;
43865
- this.dialectConfig = is(dialect6, SingleStoreDialect) ? void 0 : dialect6;
43866
- }
43867
- $with(alias) {
43868
- const queryBuilder = this;
43869
- return {
43870
- as(qb) {
44126
+ __publicField(this, "$with", (alias, selection) => {
44127
+ const queryBuilder = this;
44128
+ const as = (qb) => {
43871
44129
  if (typeof qb === "function") {
43872
44130
  qb = qb(queryBuilder);
43873
44131
  }
43874
44132
  return new Proxy(
43875
- new WithSubquery(qb.getSQL(), qb.getSelectedFields(), alias, true),
44133
+ new WithSubquery(
44134
+ qb.getSQL(),
44135
+ selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}),
44136
+ alias,
44137
+ true
44138
+ ),
43876
44139
  new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
43877
44140
  );
43878
- }
43879
- };
44141
+ };
44142
+ return { as };
44143
+ });
44144
+ this.dialect = is(dialect6, SingleStoreDialect) ? dialect6 : void 0;
44145
+ this.dialectConfig = is(dialect6, SingleStoreDialect) ? void 0 : dialect6;
43880
44146
  }
43881
44147
  with(...queries) {
43882
44148
  const self2 = this;
@@ -43922,7 +44188,7 @@ var init_query_builder5 = __esm({
43922
44188
  return this.dialect;
43923
44189
  }
43924
44190
  };
43925
- __publicField(QueryBuilder4, _a400, "SingleStoreQueryBuilder");
44191
+ __publicField(QueryBuilder4, _a402, "SingleStoreQueryBuilder");
43926
44192
  }
43927
44193
  });
43928
44194
 
@@ -43934,7 +44200,7 @@ var init_select_types4 = __esm({
43934
44200
  });
43935
44201
 
43936
44202
  // ../drizzle-orm/dist/singlestore-core/query-builders/update.js
43937
- var _a401, SingleStoreUpdateBuilder, _a402, _b301, SingleStoreUpdateBase;
44203
+ var _a403, SingleStoreUpdateBuilder, _a404, _b303, SingleStoreUpdateBase;
43938
44204
  var init_update4 = __esm({
43939
44205
  "../drizzle-orm/dist/singlestore-core/query-builders/update.js"() {
43940
44206
  "use strict";
@@ -43943,7 +44209,7 @@ var init_update4 = __esm({
43943
44209
  init_selection_proxy();
43944
44210
  init_table();
43945
44211
  init_utils2();
43946
- _a401 = entityKind;
44212
+ _a403 = entityKind;
43947
44213
  SingleStoreUpdateBuilder = class {
43948
44214
  constructor(table5, session, dialect6, withList) {
43949
44215
  this.table = table5;
@@ -43961,8 +44227,8 @@ var init_update4 = __esm({
43961
44227
  );
43962
44228
  }
43963
44229
  };
43964
- __publicField(SingleStoreUpdateBuilder, _a401, "SingleStoreUpdateBuilder");
43965
- SingleStoreUpdateBase = class extends (_b301 = QueryPromise, _a402 = entityKind, _b301) {
44230
+ __publicField(SingleStoreUpdateBuilder, _a403, "SingleStoreUpdateBuilder");
44231
+ SingleStoreUpdateBase = class extends (_b303 = QueryPromise, _a404 = entityKind, _b303) {
43966
44232
  constructor(table5, set, session, dialect6, withList) {
43967
44233
  super();
43968
44234
  __publicField(this, "config");
@@ -44055,7 +44321,7 @@ var init_update4 = __esm({
44055
44321
  return this;
44056
44322
  }
44057
44323
  };
44058
- __publicField(SingleStoreUpdateBase, _a402, "SingleStoreUpdate");
44324
+ __publicField(SingleStoreUpdateBase, _a404, "SingleStoreUpdate");
44059
44325
  }
44060
44326
  });
44061
44327
 
@@ -44073,7 +44339,7 @@ var init_query_builders4 = __esm({
44073
44339
  });
44074
44340
 
44075
44341
  // ../drizzle-orm/dist/singlestore-core/db.js
44076
- var _a403, SingleStoreDatabase;
44342
+ var _a405, SingleStoreDatabase;
44077
44343
  var init_db4 = __esm({
44078
44344
  "../drizzle-orm/dist/singlestore-core/db.js"() {
44079
44345
  "use strict";
@@ -44083,12 +44349,62 @@ var init_db4 = __esm({
44083
44349
  init_subquery();
44084
44350
  init_count4();
44085
44351
  init_query_builders4();
44086
- _a403 = entityKind;
44352
+ _a405 = entityKind;
44087
44353
  SingleStoreDatabase = class {
44088
44354
  constructor(dialect6, session, schema5) {
44089
44355
  // We are waiting for SingleStore support for `json_array` function
44090
44356
  /**@inrernal */
44091
44357
  __publicField(this, "query");
44358
+ /**
44359
+ * Creates a subquery that defines a temporary named result set as a CTE.
44360
+ *
44361
+ * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.
44362
+ *
44363
+ * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
44364
+ *
44365
+ * @param alias The alias for the subquery.
44366
+ *
44367
+ * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.
44368
+ *
44369
+ * @example
44370
+ *
44371
+ * ```ts
44372
+ * // Create a subquery with alias 'sq' and use it in the select query
44373
+ * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
44374
+ *
44375
+ * const result = await db.with(sq).select().from(sq);
44376
+ * ```
44377
+ *
44378
+ * 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:
44379
+ *
44380
+ * ```ts
44381
+ * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query
44382
+ * const sq = db.$with('sq').as(db.select({
44383
+ * name: sql<string>`upper(${users.name})`.as('name'),
44384
+ * })
44385
+ * .from(users));
44386
+ *
44387
+ * const result = await db.with(sq).select({ name: sq.name }).from(sq);
44388
+ * ```
44389
+ */
44390
+ __publicField(this, "$with", (alias, selection) => {
44391
+ const self2 = this;
44392
+ const as = (qb) => {
44393
+ if (typeof qb === "function") {
44394
+ qb = qb(new QueryBuilder4(self2.dialect));
44395
+ }
44396
+ return new Proxy(
44397
+ new WithSubquery(
44398
+ qb.getSQL(),
44399
+ selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}),
44400
+ alias,
44401
+ true
44402
+ ),
44403
+ new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
44404
+ );
44405
+ };
44406
+ return { as };
44407
+ });
44092
44408
  this.dialect = dialect6;
44093
44409
  this.session = session;
44094
44410
  this._ = schema5 ? {
@@ -44102,52 +44418,6 @@ var init_db4 = __esm({
44102
44418
  };
44103
44419
  this.query = {};
44104
44420
  }
44105
- /**
44106
- * Creates a subquery that defines a temporary named result set as a CTE.
44107
- *
44108
- * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.
44109
- *
44110
- * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
44111
- *
44112
- * @param alias The alias for the subquery.
44113
- *
44114
- * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.
44115
- *
44116
- * @example
44117
- *
44118
- * ```ts
44119
- * // Create a subquery with alias 'sq' and use it in the select query
44120
- * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
44121
- *
44122
- * const result = await db.with(sq).select().from(sq);
44123
- * ```
44124
- *
44125
- * 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:
44126
- *
44127
- * ```ts
44128
- * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query
44129
- * const sq = db.$with('sq').as(db.select({
44130
- * name: sql<string>`upper(${users.name})`.as('name'),
44131
- * })
44132
- * .from(users));
44133
- *
44134
- * const result = await db.with(sq).select({ name: sq.name }).from(sq);
44135
- * ```
44136
- */
44137
- $with(alias) {
44138
- const self2 = this;
44139
- return {
44140
- as(qb) {
44141
- if (typeof qb === "function") {
44142
- qb = qb(new QueryBuilder4(self2.dialect));
44143
- }
44144
- return new Proxy(
44145
- new WithSubquery(qb.getSQL(), qb.getSelectedFields(), alias, true),
44146
- new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
44147
- );
44148
- }
44149
- };
44150
- }
44151
44421
  $count(source, filters) {
44152
44422
  return new SingleStoreCountBuilder({ source, filters, session: this.session });
44153
44423
  }
@@ -44283,17 +44553,17 @@ var init_db4 = __esm({
44283
44553
  return this.session.transaction(transaction, config);
44284
44554
  }
44285
44555
  };
44286
- __publicField(SingleStoreDatabase, _a403, "SingleStoreDatabase");
44556
+ __publicField(SingleStoreDatabase, _a405, "SingleStoreDatabase");
44287
44557
  }
44288
44558
  });
44289
44559
 
44290
44560
  // ../drizzle-orm/dist/singlestore-core/indexes.js
44291
- var _a404, IndexBuilderOn4, _a405, IndexBuilder4, _a406, Index6;
44561
+ var _a406, IndexBuilderOn4, _a407, IndexBuilder4, _a408, Index6;
44292
44562
  var init_indexes4 = __esm({
44293
44563
  "../drizzle-orm/dist/singlestore-core/indexes.js"() {
44294
44564
  "use strict";
44295
44565
  init_entity();
44296
- _a404 = entityKind;
44566
+ _a406 = entityKind;
44297
44567
  IndexBuilderOn4 = class {
44298
44568
  constructor(name2, unique) {
44299
44569
  this.name = name2;
@@ -44303,8 +44573,8 @@ var init_indexes4 = __esm({
44303
44573
  return new IndexBuilder4(this.name, columns, this.unique);
44304
44574
  }
44305
44575
  };
44306
- __publicField(IndexBuilderOn4, _a404, "SingleStoreIndexBuilderOn");
44307
- _a405 = entityKind;
44576
+ __publicField(IndexBuilderOn4, _a406, "SingleStoreIndexBuilderOn");
44577
+ _a407 = entityKind;
44308
44578
  IndexBuilder4 = class {
44309
44579
  constructor(name2, columns, unique) {
44310
44580
  /** @internal */
@@ -44332,26 +44602,26 @@ var init_indexes4 = __esm({
44332
44602
  return new Index6(this.config, table5);
44333
44603
  }
44334
44604
  };
44335
- __publicField(IndexBuilder4, _a405, "SingleStoreIndexBuilder");
44336
- _a406 = entityKind;
44605
+ __publicField(IndexBuilder4, _a407, "SingleStoreIndexBuilder");
44606
+ _a408 = entityKind;
44337
44607
  Index6 = class {
44338
44608
  constructor(config, table5) {
44339
44609
  __publicField(this, "config");
44340
44610
  this.config = { ...config, table: table5 };
44341
44611
  }
44342
44612
  };
44343
- __publicField(Index6, _a406, "SingleStoreIndex");
44613
+ __publicField(Index6, _a408, "SingleStoreIndex");
44344
44614
  }
44345
44615
  });
44346
44616
 
44347
44617
  // ../drizzle-orm/dist/singlestore-core/primary-keys.js
44348
- var _a407, PrimaryKeyBuilder4, _a408, PrimaryKey4;
44618
+ var _a409, PrimaryKeyBuilder4, _a410, PrimaryKey4;
44349
44619
  var init_primary_keys4 = __esm({
44350
44620
  "../drizzle-orm/dist/singlestore-core/primary-keys.js"() {
44351
44621
  "use strict";
44352
44622
  init_entity();
44353
44623
  init_table5();
44354
- _a407 = entityKind;
44624
+ _a409 = entityKind;
44355
44625
  PrimaryKeyBuilder4 = class {
44356
44626
  constructor(columns, name2) {
44357
44627
  /** @internal */
@@ -44366,8 +44636,8 @@ var init_primary_keys4 = __esm({
44366
44636
  return new PrimaryKey4(table5, this.columns, this.name);
44367
44637
  }
44368
44638
  };
44369
- __publicField(PrimaryKeyBuilder4, _a407, "SingleStorePrimaryKeyBuilder");
44370
- _a408 = entityKind;
44639
+ __publicField(PrimaryKeyBuilder4, _a409, "SingleStorePrimaryKeyBuilder");
44640
+ _a410 = entityKind;
44371
44641
  PrimaryKey4 = class {
44372
44642
  constructor(table5, columns, name2) {
44373
44643
  __publicField(this, "columns");
@@ -44380,18 +44650,18 @@ var init_primary_keys4 = __esm({
44380
44650
  return this.name ?? `${this.table[SingleStoreTable.Symbol.Name]}_${this.columns.map((column5) => column5.name).join("_")}_pk`;
44381
44651
  }
44382
44652
  };
44383
- __publicField(PrimaryKey4, _a408, "SingleStorePrimaryKey");
44653
+ __publicField(PrimaryKey4, _a410, "SingleStorePrimaryKey");
44384
44654
  }
44385
44655
  });
44386
44656
 
44387
44657
  // ../drizzle-orm/dist/singlestore-core/schema.js
44388
- var _a409, SingleStoreSchema5;
44658
+ var _a411, SingleStoreSchema5;
44389
44659
  var init_schema3 = __esm({
44390
44660
  "../drizzle-orm/dist/singlestore-core/schema.js"() {
44391
44661
  "use strict";
44392
44662
  init_entity();
44393
44663
  init_table5();
44394
- _a409 = entityKind;
44664
+ _a411 = entityKind;
44395
44665
  SingleStoreSchema5 = class {
44396
44666
  constructor(schemaName) {
44397
44667
  __publicField(this, "table", (name2, columns, extraConfig) => {
@@ -44404,12 +44674,12 @@ var init_schema3 = __esm({
44404
44674
  return singlestoreViewWithSchema(name, columns, this.schemaName);
44405
44675
  }) as typeof singlestoreView; */
44406
44676
  };
44407
- __publicField(SingleStoreSchema5, _a409, "SingleStoreSchema");
44677
+ __publicField(SingleStoreSchema5, _a411, "SingleStoreSchema");
44408
44678
  }
44409
44679
  });
44410
44680
 
44411
44681
  // ../drizzle-orm/dist/singlestore-core/session.js
44412
- var _a410, SingleStorePreparedQuery, _a411, SingleStoreSession, _a412, _b302, SingleStoreTransaction;
44682
+ var _a412, SingleStorePreparedQuery, _a413, SingleStoreSession, _a414, _b304, SingleStoreTransaction;
44413
44683
  var init_session4 = __esm({
44414
44684
  "../drizzle-orm/dist/singlestore-core/session.js"() {
44415
44685
  "use strict";
@@ -44417,15 +44687,15 @@ var init_session4 = __esm({
44417
44687
  init_errors();
44418
44688
  init_sql();
44419
44689
  init_db4();
44420
- _a410 = entityKind;
44690
+ _a412 = entityKind;
44421
44691
  SingleStorePreparedQuery = class {
44422
44692
  constructor() {
44423
44693
  /** @internal */
44424
44694
  __publicField(this, "joinsNotNullableMap");
44425
44695
  }
44426
44696
  };
44427
- __publicField(SingleStorePreparedQuery, _a410, "SingleStorePreparedQuery");
44428
- _a411 = entityKind;
44697
+ __publicField(SingleStorePreparedQuery, _a412, "SingleStorePreparedQuery");
44698
+ _a413 = entityKind;
44429
44699
  SingleStoreSession = class {
44430
44700
  constructor(dialect6) {
44431
44701
  this.dialect = dialect6;
@@ -44460,8 +44730,8 @@ var init_session4 = __esm({
44460
44730
  return parts.length ? sql`start transaction ${sql.raw(parts.join(" "))}` : void 0;
44461
44731
  }
44462
44732
  };
44463
- __publicField(SingleStoreSession, _a411, "SingleStoreSession");
44464
- SingleStoreTransaction = class extends (_b302 = SingleStoreDatabase, _a412 = entityKind, _b302) {
44733
+ __publicField(SingleStoreSession, _a413, "SingleStoreSession");
44734
+ SingleStoreTransaction = class extends (_b304 = SingleStoreDatabase, _a414 = entityKind, _b304) {
44465
44735
  constructor(dialect6, session, schema5, nestedIndex) {
44466
44736
  super(dialect6, session, schema5);
44467
44737
  this.schema = schema5;
@@ -44471,7 +44741,7 @@ var init_session4 = __esm({
44471
44741
  throw new TransactionRollbackError();
44472
44742
  }
44473
44743
  };
44474
- __publicField(SingleStoreTransaction, _a412, "SingleStoreTransaction");
44744
+ __publicField(SingleStoreTransaction, _a414, "SingleStoreTransaction");
44475
44745
  }
44476
44746
  });
44477
44747
 
@@ -44648,7 +44918,7 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
44648
44918
  if (typeof column5.default === "string") {
44649
44919
  columnToSet.default = `'${column5.default}'`;
44650
44920
  } else {
44651
- if (sqlTypeLowered === "json") {
44921
+ if (sqlTypeLowered === "json" || Array.isArray(column5.default)) {
44652
44922
  columnToSet.default = `'${JSON.stringify(column5.default)}'`;
44653
44923
  } else if (column5.default instanceof Date) {
44654
44924
  if (sqlTypeLowered === "date") {
@@ -45418,15 +45688,31 @@ var init_singlestoreImports = __esm({
45418
45688
  var singlestorePushUtils_exports = {};
45419
45689
  __export(singlestorePushUtils_exports, {
45420
45690
  filterStatements: () => filterStatements2,
45691
+ findColumnTypeAlternations: () => findColumnTypeAlternations,
45421
45692
  logSuggestionsAndReturn: () => logSuggestionsAndReturn3
45422
45693
  });
45694
+ function findColumnTypeAlternations(columns1, columns2) {
45695
+ const changes = [];
45696
+ for (const key in columns1) {
45697
+ if (columns1.hasOwnProperty(key) && columns2.hasOwnProperty(key)) {
45698
+ const col1 = columns1[key];
45699
+ const col2 = columns2[key];
45700
+ if (col1.type !== col2.type) {
45701
+ changes.push(col2.name);
45702
+ }
45703
+ }
45704
+ }
45705
+ return changes;
45706
+ }
45423
45707
  var import_hanji10, filterStatements2, logSuggestionsAndReturn3;
45424
45708
  var init_singlestorePushUtils = __esm({
45425
45709
  "src/cli/commands/singlestorePushUtils.ts"() {
45426
45710
  "use strict";
45427
45711
  init_source();
45428
45712
  import_hanji10 = __toESM(require_hanji());
45713
+ init_sqlgenerator();
45429
45714
  init_singlestoreSchema();
45715
+ init_utils();
45430
45716
  init_selector_ui();
45431
45717
  init_outputs();
45432
45718
  filterStatements2 = (statements, currentSchema, prevSchema) => {
@@ -45470,7 +45756,7 @@ var init_singlestorePushUtils = __esm({
45470
45756
  return true;
45471
45757
  });
45472
45758
  };
45473
- logSuggestionsAndReturn3 = async (db, statements, json22) => {
45759
+ logSuggestionsAndReturn3 = async (db, statements, json22, json1) => {
45474
45760
  let shouldAskForApprove = false;
45475
45761
  const statementsToExecute = [];
45476
45762
  const infoToPrint = [];
@@ -45651,6 +45937,71 @@ var init_singlestorePushUtils = __esm({
45651
45937
  shouldAskForApprove = true;
45652
45938
  }
45653
45939
  }
45940
+ } else if (statement.type === "singlestore_recreate_table") {
45941
+ const tableName = statement.tableName;
45942
+ const prevColumns = json1.tables[tableName].columns;
45943
+ const currentColumns = json22.tables[tableName].columns;
45944
+ const { removedColumns, addedColumns } = findAddedAndRemoved(
45945
+ Object.keys(prevColumns),
45946
+ Object.keys(currentColumns)
45947
+ );
45948
+ if (removedColumns.length) {
45949
+ for (const removedColumn of removedColumns) {
45950
+ const res = await db.query(
45951
+ `select count(\`${tableName}\`.\`${removedColumn}\`) as count from \`${tableName}\``
45952
+ );
45953
+ const count2 = Number(res[0].count);
45954
+ if (count2 > 0) {
45955
+ infoToPrint.push(
45956
+ `\xB7 You're about to delete ${source_default.underline(
45957
+ removedColumn
45958
+ )} column in ${tableName} table with ${count2} items`
45959
+ );
45960
+ columnsToRemove.push(removedColumn);
45961
+ shouldAskForApprove = true;
45962
+ }
45963
+ }
45964
+ }
45965
+ if (addedColumns.length) {
45966
+ for (const addedColumn of addedColumns) {
45967
+ const [res] = await db.query(
45968
+ `select count(*) as count from \`${tableName}\``
45969
+ );
45970
+ const columnConf = json22.tables[tableName].columns[addedColumn];
45971
+ const count2 = Number(res.count);
45972
+ if (count2 > 0 && columnConf.notNull && !columnConf.default) {
45973
+ infoToPrint.push(
45974
+ `\xB7 You're about to add not-null ${source_default.underline(
45975
+ addedColumn
45976
+ )} column without default value to table, which contains ${count2} items`
45977
+ );
45978
+ shouldAskForApprove = true;
45979
+ tablesToTruncate.push(tableName);
45980
+ statementsToExecute.push(`TRUNCATE TABLE \`${tableName}\`;`);
45981
+ }
45982
+ }
45983
+ }
45984
+ const columnWithChangedType = findColumnTypeAlternations(prevColumns, currentColumns);
45985
+ for (const column5 of columnWithChangedType) {
45986
+ const [res] = await db.query(
45987
+ `select count(*) as count from \`${tableName}\` WHERE \`${tableName}\`.\`${column5}\` IS NOT NULL;`
45988
+ );
45989
+ const count2 = Number(res.count);
45990
+ if (count2 > 0) {
45991
+ infoToPrint.push(
45992
+ `\xB7 You're about recreate ${source_default.underline(tableName)} table with data type changing for ${source_default.underline(
45993
+ column5
45994
+ )} column, which contains ${count2} items`
45995
+ );
45996
+ shouldAskForApprove = true;
45997
+ tablesToTruncate.push(tableName);
45998
+ statementsToExecute.push(`TRUNCATE TABLE \`${tableName}\`;`);
45999
+ }
46000
+ }
46001
+ }
46002
+ const stmnt = fromJson([statement], "singlestore", "push");
46003
+ if (typeof stmnt !== "undefined") {
46004
+ statementsToExecute.push(...stmnt);
45654
46005
  }
45655
46006
  }
45656
46007
  return {
@@ -46479,7 +46830,8 @@ var pushSingleStoreSchema = async (imports, drizzleInstance, databaseName) => {
46479
46830
  const { shouldAskForApprove, statementsToExecute, infoToPrint } = await logSuggestionsAndReturn4(
46480
46831
  db,
46481
46832
  statements,
46482
- validatedCur
46833
+ validatedCur,
46834
+ validatedPrev
46483
46835
  );
46484
46836
  return {
46485
46837
  hasDataLoss: shouldAskForApprove,