drizzle-kit 0.20.2 → 0.20.4-38bea13

Sign up to get free protection for your applications and to get access to all the features.
package/bin.cjs CHANGED
@@ -6815,11 +6815,11 @@ var require_node2 = __commonJS({
6815
6815
  this._set = hasNativeMap ? /* @__PURE__ */ new Map() : /* @__PURE__ */ Object.create(null);
6816
6816
  }
6817
6817
  ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) {
6818
- var set = new ArraySet();
6818
+ var set2 = new ArraySet();
6819
6819
  for (var i = 0, len = aArray.length; i < len; i++) {
6820
- set.add(aArray[i], aAllowDuplicates);
6820
+ set2.add(aArray[i], aAllowDuplicates);
6821
6821
  }
6822
- return set;
6822
+ return set2;
6823
6823
  };
6824
6824
  ArraySet.prototype.size = function ArraySet_size() {
6825
6825
  return hasNativeMap ? this._set.size : Object.getOwnPropertyNames(this._set).length;
@@ -13295,6 +13295,14 @@ WHERE
13295
13295
  });
13296
13296
 
13297
13297
  // src/serializer/index.ts
13298
+ var serializer_exports = {};
13299
+ __export(serializer_exports, {
13300
+ prepareFilenames: () => prepareFilenames,
13301
+ serializeMySql: () => serializeMySql,
13302
+ serializePg: () => serializePg,
13303
+ serializeSQLite: () => serializeSQLite,
13304
+ sqlToStr: () => sqlToStr
13305
+ });
13298
13306
  var import_fs2, import_path2, glob, sqlToStr, serializeMySql, serializePg, serializeSQLite, prepareFilenames;
13299
13307
  var init_serializer = __esm({
13300
13308
  "src/serializer/index.ts"() {
@@ -18785,10 +18793,14 @@ var init_utils2 = __esm({
18785
18793
  }
18786
18794
  });
18787
18795
 
18788
- // src/introspect.ts
18796
+ // src/introspect-pg.ts
18797
+ var introspect_pg_exports = {};
18798
+ __export(introspect_pg_exports, {
18799
+ schemaToTypeScript: () => schemaToTypeScript
18800
+ });
18789
18801
  var pgImportsList, objToStatement2, timeConfig, possibleIntervals, intervalStrToObj, intervalConfig, importsPatch, relations, withCasing, schemaToTypeScript, isCyclic, isSelf, column4, dimensionsInArray, createTableColumns, createTableIndexes, createTablePKs, createTableUniques, createTableFKs;
18790
- var init_introspect = __esm({
18791
- "src/introspect.ts"() {
18802
+ var init_introspect_pg = __esm({
18803
+ "src/introspect-pg.ts"() {
18792
18804
  init_utils2();
18793
18805
  init_pgSerializer();
18794
18806
  pgImportsList = /* @__PURE__ */ new Set([
@@ -18946,7 +18958,7 @@ var init_introspect = __esm({
18946
18958
  res.pg.push("pgEnum");
18947
18959
  }
18948
18960
  const columnImports = Object.values(it.columns).map((col) => {
18949
- let patched = importsPatch[col.type] ?? col.type;
18961
+ let patched = importsPatch[col.type] || col.type;
18950
18962
  patched = patched.startsWith("varchar(") ? "varchar" : patched;
18951
18963
  patched = patched.startsWith("char(") ? "char" : patched;
18952
18964
  patched = patched.startsWith("numeric(") ? "numeric" : patched;
@@ -19015,18 +19027,23 @@ var init_introspect = __esm({
19015
19027
  return statement;
19016
19028
  });
19017
19029
  const uniquePgImports = ["pgTable", ...new Set(imports.pg)];
19018
- let result = `import { ${uniquePgImports.join(
19030
+ const importsTs = `import { ${uniquePgImports.join(
19019
19031
  ", "
19020
19032
  )} } from "drizzle-orm/pg-core"
19033
+ import { sql } from "drizzle-orm"
19021
19034
 
19022
19035
  `;
19023
- result += `import { sql } from "drizzle-orm"
19024
- `;
19025
- result += enumStatements;
19026
- result += schemaStatements;
19027
- result += "\n";
19028
- result += tableStatements.join("\n\n");
19029
- return result;
19036
+ let decalrations = enumStatements;
19037
+ decalrations += schemaStatements;
19038
+ decalrations += "\n";
19039
+ decalrations += tableStatements.join("\n\n");
19040
+ const file = importsTs + decalrations;
19041
+ const schemaEntry = `
19042
+ {
19043
+ ${Object.values(schema4.tables).map((it) => withCasing(it.name, casing)).join(",\n")}
19044
+ }
19045
+ `;
19046
+ return { file, imports: importsTs, decalrations, schemaEntry };
19030
19047
  };
19031
19048
  isCyclic = (fk4) => {
19032
19049
  const key = `${fk4.tableFrom}-${fk4.tableTo}`;
@@ -19803,9 +19820,9 @@ var init_mjs = __esm({
19803
19820
  star = qmark + "*?";
19804
19821
  twoStarDot = "(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?";
19805
19822
  twoStarNoDot = "(?:(?!(?:\\/|^)\\.).)*?";
19806
- charSet = (s) => s.split("").reduce((set, c) => {
19807
- set[c] = true;
19808
- return set;
19823
+ charSet = (s) => s.split("").reduce((set2, c) => {
19824
+ set2[c] = true;
19825
+ return set2;
19809
19826
  }, {});
19810
19827
  reSpecials = charSet("().*{}+?[]^$\\!");
19811
19828
  addPatternStartSet = charSet("[.(");
@@ -19947,7 +19964,7 @@ var init_mjs = __esm({
19947
19964
  const rawGlobParts = this.globSet.map((s) => this.slashSplit(s));
19948
19965
  this.globParts = this.preprocess(rawGlobParts);
19949
19966
  this.debug(this.pattern, this.globParts);
19950
- let set = this.globParts.map((s, _, __) => {
19967
+ let set2 = this.globParts.map((s, _, __) => {
19951
19968
  if (this.isWindows && this.windowsNoMagicRoot) {
19952
19969
  const isUNC = s[0] === "" && s[1] === "" && (s[2] === "?" || !globMagic.test(s[2])) && !globMagic.test(s[3]);
19953
19970
  const isDrive = /^[a-z]:/i.test(s[0]);
@@ -19959,8 +19976,8 @@ var init_mjs = __esm({
19959
19976
  }
19960
19977
  return s.map((ss) => this.parse(ss));
19961
19978
  });
19962
- this.debug(this.pattern, set);
19963
- this.set = set.filter((s) => s.indexOf(false) === -1);
19979
+ this.debug(this.pattern, set2);
19980
+ this.set = set2.filter((s) => s.indexOf(false) === -1);
19964
19981
  if (this.isWindows) {
19965
19982
  for (let i = 0; i < this.set.length; i++) {
19966
19983
  const p = this.set[i];
@@ -20016,19 +20033,19 @@ var init_mjs = __esm({
20016
20033
  // get rid of adjascent ** and resolve .. portions
20017
20034
  levelOneOptimize(globParts) {
20018
20035
  return globParts.map((parts) => {
20019
- parts = parts.reduce((set, part) => {
20020
- const prev = set[set.length - 1];
20036
+ parts = parts.reduce((set2, part) => {
20037
+ const prev = set2[set2.length - 1];
20021
20038
  if (part === "**" && prev === "**") {
20022
- return set;
20039
+ return set2;
20023
20040
  }
20024
20041
  if (part === "..") {
20025
20042
  if (prev && prev !== ".." && prev !== "." && prev !== "**") {
20026
- set.pop();
20027
- return set;
20043
+ set2.pop();
20044
+ return set2;
20028
20045
  }
20029
20046
  }
20030
- set.push(part);
20031
- return set;
20047
+ set2.push(part);
20048
+ return set2;
20032
20049
  }, []);
20033
20050
  return parts.length === 0 ? [""] : parts;
20034
20051
  });
@@ -20546,15 +20563,15 @@ var init_mjs = __esm({
20546
20563
  makeRe() {
20547
20564
  if (this.regexp || this.regexp === false)
20548
20565
  return this.regexp;
20549
- const set = this.set;
20550
- if (!set.length) {
20566
+ const set2 = this.set;
20567
+ if (!set2.length) {
20551
20568
  this.regexp = false;
20552
20569
  return this.regexp;
20553
20570
  }
20554
20571
  const options = this.options;
20555
20572
  const twoStar = options.noglobstar ? star : options.dot ? twoStarDot : twoStarNoDot;
20556
20573
  const flags = options.nocase ? "i" : "";
20557
- let re = set.map((pattern) => {
20574
+ let re = set2.map((pattern) => {
20558
20575
  const pp = pattern.map((p) => typeof p === "string" ? regExpEscape(p) : p === GLOBSTAR ? GLOBSTAR : p._src);
20559
20576
  pp.forEach((p, i) => {
20560
20577
  const next = pp[i + 1];
@@ -20613,16 +20630,16 @@ var init_mjs = __esm({
20613
20630
  }
20614
20631
  const ff = this.slashSplit(f);
20615
20632
  this.debug(this.pattern, "split", ff);
20616
- const set = this.set;
20617
- this.debug(this.pattern, "set", set);
20633
+ const set2 = this.set;
20634
+ this.debug(this.pattern, "set", set2);
20618
20635
  let filename = ff[ff.length - 1];
20619
20636
  if (!filename) {
20620
20637
  for (let i = ff.length - 2; !filename && i >= 0; i--) {
20621
20638
  filename = ff[i];
20622
20639
  }
20623
20640
  }
20624
- for (let i = 0; i < set.length; i++) {
20625
- const pattern = set[i];
20641
+ for (let i = 0; i < set2.length; i++) {
20642
+ const pattern = set2[i];
20626
20643
  let file = ff;
20627
20644
  if (options.matchBase && pattern.length === 1) {
20628
20645
  file = [filename];
@@ -25382,7 +25399,7 @@ var init_pgIntrospect = __esm({
25382
25399
  import_hanji4 = __toESM(require_hanji());
25383
25400
  init_views();
25384
25401
  init_pgSerializer();
25385
- init_introspect();
25402
+ init_introspect_pg();
25386
25403
  init_global();
25387
25404
  init_mjs();
25388
25405
  pgSchemas = async (client) => {
@@ -25709,10 +25726,15 @@ var init_pgPushUtils = __esm({
25709
25726
  }
25710
25727
  });
25711
25728
 
25712
- // src/sqlite-introspect.ts
25729
+ // src/introspect-sqlite.ts
25730
+ var introspect_sqlite_exports = {};
25731
+ __export(introspect_sqlite_exports, {
25732
+ indexName: () => indexName3,
25733
+ schemaToTypeScript: () => schemaToTypeScript2
25734
+ });
25713
25735
  var sqliteImportsList, indexName3, objToStatement22, relations2, withCasing2, schemaToTypeScript2, isCyclic2, isSelf2, mapColumnDefault, column5, createTableColumns2, createTableIndexes2, createTableUniques2, createTablePKs2, createTableFKs2;
25714
- var init_sqlite_introspect = __esm({
25715
- "src/sqlite-introspect.ts"() {
25736
+ var init_introspect_sqlite = __esm({
25737
+ "src/introspect-sqlite.ts"() {
25716
25738
  init_utils2();
25717
25739
  sqliteImportsList = /* @__PURE__ */ new Set([
25718
25740
  "sqliteTable",
@@ -25829,15 +25851,20 @@ var init_sqlite_introspect = __esm({
25829
25851
  "AnySQLiteColumn",
25830
25852
  ...new Set(imports.sqlite)
25831
25853
  ];
25832
- let result = `import { ${uniqueSqliteImports.join(
25854
+ const importsTs = `import { ${uniqueSqliteImports.join(
25833
25855
  ", "
25834
25856
  )} } from "drizzle-orm/sqlite-core"
25835
- import { sql } from "drizzle-orm"
25857
+ import { sql } from "drizzle-orm"
25836
25858
 
25837
25859
  `;
25838
- result += "\n";
25839
- result += tableStatements.join("\n\n");
25840
- return result;
25860
+ const decalrations = tableStatements.join("\n\n");
25861
+ const file = importsTs + decalrations;
25862
+ const schemaEntry = `
25863
+ {
25864
+ ${Object.values(schema4.tables).map((it) => withCasing2(it.name, casing)).join(",")}
25865
+ }
25866
+ `;
25867
+ return { file, imports: importsTs, decalrations, schemaEntry };
25841
25868
  };
25842
25869
  isCyclic2 = (fk4) => {
25843
25870
  const key = `${fk4.tableFrom}-${fk4.tableTo}`;
@@ -26011,7 +26038,7 @@ var init_sqliteIntrospect = __esm({
26011
26038
  init_views();
26012
26039
  init_global();
26013
26040
  init_sqliteSerializer();
26014
- init_sqlite_introspect();
26041
+ init_introspect_sqlite();
26015
26042
  init_mjs();
26016
26043
  import_hanji7 = __toESM(require_hanji());
26017
26044
  connectToSQLite = async (config) => {
@@ -53900,18 +53927,18 @@ var require_set = __commonJS({
53900
53927
  }
53901
53928
  static from(schema4, iterable, ctx) {
53902
53929
  const { replacer } = ctx;
53903
- const set2 = new this(schema4);
53930
+ const set3 = new this(schema4);
53904
53931
  if (iterable && Symbol.iterator in Object(iterable))
53905
53932
  for (let value of iterable) {
53906
53933
  if (typeof replacer === "function")
53907
53934
  value = replacer.call(iterable, value, value);
53908
- set2.items.push(Pair.createPair(value, null, ctx));
53935
+ set3.items.push(Pair.createPair(value, null, ctx));
53909
53936
  }
53910
- return set2;
53937
+ return set3;
53911
53938
  }
53912
53939
  };
53913
53940
  YAMLSet.tag = "tag:yaml.org,2002:set";
53914
- var set = {
53941
+ var set2 = {
53915
53942
  collection: "map",
53916
53943
  identify: (value) => value instanceof Set,
53917
53944
  nodeClass: YAMLSet,
@@ -53930,7 +53957,7 @@ var require_set = __commonJS({
53930
53957
  }
53931
53958
  };
53932
53959
  exports.YAMLSet = YAMLSet;
53933
- exports.set = set;
53960
+ exports.set = set2;
53934
53961
  }
53935
53962
  });
53936
53963
 
@@ -54036,7 +54063,7 @@ var require_schema3 = __commonJS({
54036
54063
  var int = require_int2();
54037
54064
  var omap = require_omap();
54038
54065
  var pairs = require_pairs();
54039
- var set = require_set();
54066
+ var set2 = require_set();
54040
54067
  var timestamp = require_timestamp();
54041
54068
  var schema4 = [
54042
54069
  map.map,
@@ -54055,7 +54082,7 @@ var require_schema3 = __commonJS({
54055
54082
  binary.binary,
54056
54083
  omap.omap,
54057
54084
  pairs.pairs,
54058
- set.set,
54085
+ set2.set,
54059
54086
  timestamp.intTime,
54060
54087
  timestamp.floatTime,
54061
54088
  timestamp.timestamp
@@ -54081,7 +54108,7 @@ var require_tags = __commonJS({
54081
54108
  var omap = require_omap();
54082
54109
  var pairs = require_pairs();
54083
54110
  var schema$2 = require_schema3();
54084
- var set = require_set();
54111
+ var set2 = require_set();
54085
54112
  var timestamp = require_timestamp();
54086
54113
  var schemas = /* @__PURE__ */ new Map([
54087
54114
  ["core", schema4.schema],
@@ -54106,14 +54133,14 @@ var require_tags = __commonJS({
54106
54133
  omap: omap.omap,
54107
54134
  pairs: pairs.pairs,
54108
54135
  seq: seq.seq,
54109
- set: set.set,
54136
+ set: set2.set,
54110
54137
  timestamp: timestamp.timestamp
54111
54138
  };
54112
54139
  var coreKnownTags = {
54113
54140
  "tag:yaml.org,2002:binary": binary.binary,
54114
54141
  "tag:yaml.org,2002:omap": omap.omap,
54115
54142
  "tag:yaml.org,2002:pairs": pairs.pairs,
54116
- "tag:yaml.org,2002:set": set.set,
54143
+ "tag:yaml.org,2002:set": set2.set,
54117
54144
  "tag:yaml.org,2002:timestamp": timestamp.timestamp
54118
54145
  };
54119
54146
  function getTags(customTags, schemaName) {
@@ -58233,7 +58260,9 @@ var init_studioUtils = __esm({
58233
58260
  };
58234
58261
  prepareMySqlSchema = async (path4) => {
58235
58262
  const imports = prepareFilenames(path4);
58236
- const mysqlSchema4 = { public: {} };
58263
+ const mysqlSchema4 = {
58264
+ public: {}
58265
+ };
58237
58266
  const relations4 = {};
58238
58267
  const { unregister } = await safeRegister();
58239
58268
  for (let i = 0; i < imports.length; i++) {
@@ -58255,7 +58284,9 @@ var init_studioUtils = __esm({
58255
58284
  };
58256
58285
  prepareSQLiteSchema = async (path4) => {
58257
58286
  const imports = prepareFilenames(path4);
58258
- const sqliteSchema2 = { public: {} };
58287
+ const sqliteSchema2 = {
58288
+ public: {}
58289
+ };
58259
58290
  const relations4 = {};
58260
58291
  const { unregister } = await safeRegister();
58261
58292
  for (let i = 0; i < imports.length; i++) {
@@ -58305,34 +58336,55 @@ var init_studioUtils = __esm({
58305
58336
  unregister();
58306
58337
  return { pgSchema: pgSchema4, mysqlSchema: mysqlSchema4, sqliteSchema: sqliteSchema2 };
58307
58338
  };
58308
- drizzleForPostgres = async (connectionConfig, pgSchema4, relations4, verbose) => {
58339
+ drizzleForPostgres = async (connectionConfig, pgSchema4, relations4, ts, verbose) => {
58309
58340
  assertPackages("pg");
58310
58341
  const { drizzle: drizzle2 } = await import("drizzle-orm/node-postgres");
58311
58342
  const pg = await Promise.resolve().then(() => __toESM(require_lib2()));
58312
- const db = drizzle2(new pg.default.Pool(connectionConfig.dbCredentials), {
58343
+ const client = new pg.default.Pool(connectionConfig.dbCredentials);
58344
+ const db = drizzle2(client, {
58313
58345
  logger: verbose
58314
58346
  });
58347
+ const proxy = async (params) => {
58348
+ const result = await client.query({
58349
+ text: params.sql,
58350
+ values: params.params,
58351
+ rowMode: "array"
58352
+ });
58353
+ return result.rows;
58354
+ };
58315
58355
  return {
58316
- type: "pg",
58356
+ dialect: "pg",
58317
58357
  db,
58358
+ proxy,
58318
58359
  schema: pgSchema4,
58319
- relations: relations4
58360
+ relations: relations4,
58361
+ ts
58320
58362
  };
58321
58363
  };
58322
- drizzleForMySQL = async (config, mysqlSchema4, relations4, verbose) => {
58364
+ drizzleForMySQL = async (config, mysqlSchema4, relations4, ts, verbose) => {
58323
58365
  assertPackages("mysql2");
58324
58366
  const { drizzle: drizzle2 } = await import("drizzle-orm/mysql2");
58325
58367
  const { createPool } = await Promise.resolve().then(() => __toESM(require_promise()));
58326
58368
  const client = createPool({ ...config.dbCredentials, connectionLimit: 1 });
58327
58369
  const db = drizzle2(client, { logger: verbose });
58370
+ const proxy = async (params) => {
58371
+ const result = await client.query({
58372
+ sql: params.sql,
58373
+ values: params.params,
58374
+ rowsAsArray: true
58375
+ });
58376
+ return result[0];
58377
+ };
58328
58378
  return {
58329
- type: "mysql",
58379
+ dialect: "mysql",
58330
58380
  db,
58381
+ proxy,
58331
58382
  schema: mysqlSchema4,
58332
- relations: relations4
58383
+ relations: relations4,
58384
+ ts
58333
58385
  };
58334
58386
  };
58335
- drizzleForSQLite = async (config, sqliteSchema2, relations4, verbose) => {
58387
+ drizzleForSQLite = async (config, sqliteSchema2, relations4, ts, verbose) => {
58336
58388
  const { driver, dbCredentials: creds } = config;
58337
58389
  if (driver === "d1") {
58338
58390
  const { drizzle: drizzle2 } = await Promise.resolve().then(() => (init_driver(), driver_exports));
@@ -58340,11 +58392,16 @@ var init_studioUtils = __esm({
58340
58392
  const db = drizzle2(execute2, creds.wranglerConfigPath, creds.dbName, {
58341
58393
  logger: verbose
58342
58394
  });
58395
+ const proxy = async (params) => {
58396
+ throw new Error("Proxy is not implemented for D1");
58397
+ };
58343
58398
  return {
58344
- type: "sqlite",
58399
+ dialect: "sqlite",
58345
58400
  db,
58401
+ proxy,
58346
58402
  schema: sqliteSchema2,
58347
- relations: relations4
58403
+ relations: relations4,
58404
+ ts
58348
58405
  };
58349
58406
  }
58350
58407
  if (driver === "better-sqlite") {
@@ -58353,11 +58410,17 @@ var init_studioUtils = __esm({
58353
58410
  const Database = await import("better-sqlite3");
58354
58411
  const client = new Database.default(creds.url);
58355
58412
  const db = drizzle2(client, { logger: verbose });
58413
+ const proxy = async (params) => {
58414
+ const sql2 = params.sql;
58415
+ return client.prepare(sql2).raw().all(params.params);
58416
+ };
58356
58417
  return {
58357
- type: "sqlite",
58418
+ dialect: "sqlite",
58358
58419
  db,
58420
+ proxy,
58359
58421
  schema: sqliteSchema2,
58360
- relations: relations4
58422
+ relations: relations4,
58423
+ ts
58361
58424
  };
58362
58425
  }
58363
58426
  if (driver === "libsql" || driver === "turso") {
@@ -58369,11 +58432,19 @@ var init_studioUtils = __esm({
58369
58432
  client,
58370
58433
  { logger: verbose }
58371
58434
  );
58435
+ const proxy = async (params) => {
58436
+ return client.execute({
58437
+ sql: params.sql,
58438
+ args: params.params
58439
+ }).then((it) => it.rows.map((row) => Object.values(row)));
58440
+ };
58372
58441
  return {
58373
- type: "sqlite",
58442
+ dialect: "sqlite",
58374
58443
  db,
58444
+ proxy,
58375
58445
  schema: sqliteSchema2,
58376
- relations: relations4
58446
+ relations: relations4,
58447
+ ts
58377
58448
  };
58378
58449
  }
58379
58450
  assertUnreachable(driver);
@@ -59379,10 +59450,14 @@ var require_cli_options = __commonJS({
59379
59450
  }
59380
59451
  });
59381
59452
 
59382
- // src/mysql-introspect.ts
59383
- var mysqlImportsList, objToStatement23, timeConfig2, binaryConfig, importsPatch2, relations3, withCasing3, schemaToTypeScript3, isCyclic3, isSelf3, mapColumnDefault2, mapColumnDefaultForJson, column6, createTableColumns3, createTableIndexes3, createTableUniques3, createTablePKs3, createTableFKs3;
59384
- var init_mysql_introspect = __esm({
59385
- "src/mysql-introspect.ts"() {
59453
+ // src/introspect-mysql.ts
59454
+ var introspect_mysql_exports = {};
59455
+ __export(introspect_mysql_exports, {
59456
+ schemaToTypeScript: () => schemaToTypeScript3
59457
+ });
59458
+ var mysqlImportsList, objToStatement23, timeConfig2, binaryConfig, importsPatch2, relations3, prepareCasing, schemaToTypeScript3, isCyclic3, isSelf3, mapColumnDefault2, mapColumnDefaultForJson, column6, createTableColumns3, createTableIndexes3, createTableUniques3, createTablePKs3, createTableFKs3;
59459
+ var init_introspect_mysql = __esm({
59460
+ "src/introspect-mysql.ts"() {
59386
59461
  init_utils2();
59387
59462
  init_mysqlSerializer();
59388
59463
  mysqlImportsList = /* @__PURE__ */ new Set([
@@ -59450,7 +59525,7 @@ var init_mysql_introspect = __esm({
59450
59525
  "timestamp without time zone": "timestamp"
59451
59526
  };
59452
59527
  relations3 = /* @__PURE__ */ new Set();
59453
- withCasing3 = (value, casing) => {
59528
+ prepareCasing = (casing) => (value) => {
59454
59529
  if (typeof casing === "undefined") {
59455
59530
  return value;
59456
59531
  }
@@ -59460,6 +59535,7 @@ var init_mysql_introspect = __esm({
59460
59535
  return value;
59461
59536
  };
59462
59537
  schemaToTypeScript3 = (schema4, casing) => {
59538
+ const withCasing3 = prepareCasing(casing);
59463
59539
  Object.values(schema4.tables).forEach((table4) => {
59464
59540
  Object.values(table4.foreignKeys).forEach((fk4) => {
59465
59541
  const relation = `${fk4.tableFrom}-${fk4.tableTo}`;
@@ -59468,7 +59544,7 @@ var init_mysql_introspect = __esm({
59468
59544
  });
59469
59545
  const schemas = Object.fromEntries(
59470
59546
  Object.entries(schema4.schemas).map((it) => {
59471
- return [it[0], withCasing3(it[1], casing)];
59547
+ return [it[0], withCasing3(it[1])];
59472
59548
  })
59473
59549
  );
59474
59550
  const imports = Object.values(schema4.tables).reduce(
@@ -59515,20 +59591,19 @@ var init_mysql_introspect = __esm({
59515
59591
  const tableSchema = schemas[table4.schema];
59516
59592
  const func = tableSchema ? tableSchema : "mysqlTable";
59517
59593
  let statement = "";
59518
- if (imports.mysql.includes(withCasing3(table4.name, casing))) {
59594
+ if (imports.mysql.includes(withCasing3(table4.name))) {
59519
59595
  statement = `// Table name is in conflict with ${withCasing3(
59520
- table4.name,
59521
- casing
59596
+ table4.name
59522
59597
  )} import.
59523
59598
  // Please change to any other name, that is not in imports list
59524
59599
  `;
59525
59600
  }
59526
- statement += `export const ${withCasing3(table4.name, casing)} = ${func}("${table4.name}", {
59601
+ statement += `export const ${withCasing3(table4.name)} = ${func}("${table4.name}", {
59527
59602
  `;
59528
59603
  statement += createTableColumns3(
59529
59604
  Object.values(table4.columns),
59530
59605
  Object.values(table4.foreignKeys),
59531
- casing,
59606
+ withCasing3,
59532
59607
  table4.name,
59533
59608
  schema4
59534
59609
  );
@@ -59543,16 +59618,16 @@ var init_mysql_introspect = __esm({
59543
59618
  statement += createTableIndexes3(
59544
59619
  table4.name,
59545
59620
  Object.values(table4.indexes),
59546
- casing
59621
+ withCasing3
59547
59622
  );
59548
- statement += createTableFKs3(Object.values(filteredFKs), casing);
59623
+ statement += createTableFKs3(Object.values(filteredFKs), withCasing3);
59549
59624
  statement += createTablePKs3(
59550
59625
  Object.values(table4.compositePrimaryKeys),
59551
- casing
59626
+ withCasing3
59552
59627
  );
59553
59628
  statement += createTableUniques3(
59554
59629
  Object.values(table4.uniqueConstraints),
59555
- casing
59630
+ withCasing3
59556
59631
  );
59557
59632
  statement += " }\n";
59558
59633
  statement += "}";
@@ -59566,16 +59641,28 @@ var init_mysql_introspect = __esm({
59566
59641
  "AnyMySqlColumn",
59567
59642
  ...new Set(imports.mysql)
59568
59643
  ];
59569
- let result = `import { ${uniqueMySqlImports.join(
59644
+ const importsTs = `import { ${uniqueMySqlImports.join(
59570
59645
  ", "
59571
59646
  )} } from "drizzle-orm/mysql-core"
59572
59647
  import { sql } from "drizzle-orm"
59573
59648
 
59574
59649
  `;
59575
- result += schemaStatements;
59576
- result += "\n";
59577
- result += tableStatements.join("\n\n");
59578
- return result;
59650
+ let decalrations = schemaStatements;
59651
+ decalrations += "\n";
59652
+ decalrations += tableStatements.join("\n\n");
59653
+ const file = importsTs + decalrations;
59654
+ const schemaEntry = `
59655
+ {
59656
+ ${Object.values(schema4.tables).map((it) => withCasing3(it.name)).join(",")}
59657
+ }
59658
+ `;
59659
+ return {
59660
+ file,
59661
+ // backward compatible, print to file
59662
+ imports: importsTs,
59663
+ decalrations,
59664
+ schemaEntry
59665
+ };
59579
59666
  };
59580
59667
  isCyclic3 = (fk4) => {
59581
59668
  const key = `${fk4.tableFrom}-${fk4.tableTo}`;
@@ -59597,51 +59684,51 @@ import { sql } from "drizzle-orm"
59597
59684
  }
59598
59685
  return defaultValue;
59599
59686
  };
59600
- column6 = (type, name, defaultValue, autoincrement, onUpdate, casing, isExpression) => {
59687
+ column6 = (type, name, casing, defaultValue, autoincrement, onUpdate, isExpression) => {
59601
59688
  let lowered = type;
59602
59689
  if (!type.startsWith("enum(")) {
59603
59690
  lowered = type.toLowerCase();
59604
59691
  }
59605
59692
  if (lowered === "serial") {
59606
- return `${withCasing3(name, casing)}: serial("${name}")`;
59693
+ return `${casing(name)}: serial("${name}")`;
59607
59694
  }
59608
59695
  if (lowered.startsWith("int")) {
59609
59696
  const isUnsigned = lowered.startsWith("int unsigned");
59610
- let out = `${withCasing3(name, casing)}: int("${name}"${isUnsigned ? ", { unsigned: true }" : ""})`;
59697
+ let out = `${casing(name)}: int("${name}"${isUnsigned ? ", { unsigned: true }" : ""})`;
59611
59698
  out += autoincrement ? `.autoincrement()` : "";
59612
59699
  out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
59613
59700
  return out;
59614
59701
  }
59615
59702
  if (lowered.startsWith("tinyint")) {
59616
59703
  const isUnsigned = lowered.startsWith("tinyint unsigned");
59617
- let out = `${withCasing3(name, casing)}: tinyint("${name}"${isUnsigned ? ", { unsigned: true }" : ""})`;
59704
+ let out = `${casing(name)}: tinyint("${name}"${isUnsigned ? ", { unsigned: true }" : ""})`;
59618
59705
  out += autoincrement ? `.autoincrement()` : "";
59619
59706
  out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
59620
59707
  return out;
59621
59708
  }
59622
59709
  if (lowered.startsWith("smallint")) {
59623
59710
  const isUnsigned = lowered.startsWith("smallint unsigned");
59624
- let out = `${withCasing3(name, casing)}: smallint("${name}"${isUnsigned ? ", { unsigned: true }" : ""})`;
59711
+ let out = `${casing(name)}: smallint("${name}"${isUnsigned ? ", { unsigned: true }" : ""})`;
59625
59712
  out += autoincrement ? `.autoincrement()` : "";
59626
59713
  out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
59627
59714
  return out;
59628
59715
  }
59629
59716
  if (lowered.startsWith("mediumint")) {
59630
59717
  const isUnsigned = lowered.startsWith("mediumint unsigned");
59631
- let out = `${withCasing3(name, casing)}: mediumint("${name}"${isUnsigned ? ", { unsigned: true }" : ""})`;
59718
+ let out = `${casing(name)}: mediumint("${name}"${isUnsigned ? ", { unsigned: true }" : ""})`;
59632
59719
  out += autoincrement ? `.autoincrement()` : "";
59633
59720
  out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
59634
59721
  return out;
59635
59722
  }
59636
59723
  if (lowered.startsWith("bigint")) {
59637
59724
  const isUnsigned = lowered.startsWith("bigint unsigned");
59638
- let out = `${withCasing3(name, casing)}: bigint("${name}", { mode: "number"${isUnsigned ? ", unsigned: true" : ""} })`;
59725
+ let out = `${casing(name)}: bigint("${name}", { mode: "number"${isUnsigned ? ", unsigned: true" : ""} })`;
59639
59726
  out += autoincrement ? `.autoincrement()` : "";
59640
59727
  out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
59641
59728
  return out;
59642
59729
  }
59643
59730
  if (lowered === "boolean") {
59644
- let out = `${withCasing3(name, casing)}: boolean("${name}")`;
59731
+ let out = `${casing(name)}: boolean("${name}")`;
59645
59732
  out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
59646
59733
  return out;
59647
59734
  }
@@ -59651,17 +59738,17 @@ import { sql } from "drizzle-orm"
59651
59738
  const [precision, scale] = lowered.slice(7, lowered.length - 1).split(",");
59652
59739
  params = { precision, scale };
59653
59740
  }
59654
- let out = params ? `${withCasing3(name, casing)}: double("${name}", ${timeConfig2(params)})` : `${withCasing3(name, casing)}: double("${name}")`;
59741
+ let out = params ? `${casing(name)}: double("${name}", ${timeConfig2(params)})` : `${casing(name)}: double("${name}")`;
59655
59742
  out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
59656
59743
  return out;
59657
59744
  }
59658
59745
  if (lowered === "float") {
59659
- let out = `${withCasing3(name, casing)}: float("${name}")`;
59746
+ let out = `${casing(name)}: float("${name}")`;
59660
59747
  out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
59661
59748
  return out;
59662
59749
  }
59663
59750
  if (lowered === "real") {
59664
- let out = `${withCasing3(name, casing)}: real("${name}")`;
59751
+ let out = `${casing(name)}: real("${name}")`;
59665
59752
  out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
59666
59753
  return out;
59667
59754
  }
@@ -59670,7 +59757,7 @@ import { sql } from "drizzle-orm"
59670
59757
  let fsp = lowered.length > keyLength ? Number(lowered.substring(keyLength, lowered.length - 1)) : null;
59671
59758
  fsp = fsp ? fsp : null;
59672
59759
  const params = timeConfig2({ fsp, mode: "'string'" });
59673
- let out = params ? `${withCasing3(name, casing)}: timestamp("${name}", ${params})` : `${withCasing3(name, casing)}: timestamp("${name}")`;
59760
+ let out = params ? `${casing(name)}: timestamp("${name}", ${params})` : `${casing(name)}: timestamp("${name}")`;
59674
59761
  defaultValue = defaultValue === "now()" || defaultValue === "(CURRENT_TIMESTAMP)" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
59675
59762
  out += defaultValue;
59676
59763
  let onUpdateNow = onUpdate ? ".onUpdateNow()" : "";
@@ -59682,55 +59769,53 @@ import { sql } from "drizzle-orm"
59682
59769
  let fsp = lowered.length > keyLength ? Number(lowered.substring(keyLength, lowered.length - 1)) : null;
59683
59770
  fsp = fsp ? fsp : null;
59684
59771
  const params = timeConfig2({ fsp });
59685
- let out = params ? `${withCasing3(name, casing)}: time("${name}", ${params})` : `${withCasing3(name, casing)}: time("${name}")`;
59772
+ let out = params ? `${casing(name)}: time("${name}", ${params})` : `${casing(name)}: time("${name}")`;
59686
59773
  defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
59687
59774
  out += defaultValue;
59688
59775
  return out;
59689
59776
  }
59690
59777
  if (lowered === "date") {
59691
59778
  let out = `// you can use { mode: 'date' }, if you want to have Date as type for this column
59692
- ${withCasing3(
59693
- name,
59694
- casing
59779
+ ${casing(
59780
+ name
59695
59781
  )}: date("${name}", { mode: 'string' })`;
59696
59782
  defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
59697
59783
  out += defaultValue;
59698
59784
  return out;
59699
59785
  }
59700
59786
  if (lowered === "text") {
59701
- let out = `${withCasing3(name, casing)}: text("${name}")`;
59787
+ let out = `${casing(name)}: text("${name}")`;
59702
59788
  out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
59703
59789
  return out;
59704
59790
  }
59705
59791
  if (lowered === "tinytext") {
59706
- let out = `${withCasing3(name, casing)}: tinytext("${name}")`;
59792
+ let out = `${casing(name)}: tinytext("${name}")`;
59707
59793
  out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
59708
59794
  return out;
59709
59795
  }
59710
59796
  if (lowered === "mediumtext") {
59711
- let out = `${withCasing3(name, casing)}: mediumtext("${name}")`;
59797
+ let out = `${casing(name)}: mediumtext("${name}")`;
59712
59798
  out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
59713
59799
  return out;
59714
59800
  }
59715
59801
  if (lowered === "longtext") {
59716
- let out = `${withCasing3(name, casing)}: longtext("${name}")`;
59802
+ let out = `${casing(name)}: longtext("${name}")`;
59717
59803
  out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
59718
59804
  return out;
59719
59805
  }
59720
59806
  if (lowered === "year") {
59721
- let out = `${withCasing3(name, casing)}: year("${name}")`;
59807
+ let out = `${casing(name)}: year("${name}")`;
59722
59808
  out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
59723
59809
  return out;
59724
59810
  }
59725
59811
  if (lowered === "json") {
59726
- let out = `${withCasing3(name, casing)}: json("${name}")`;
59812
+ let out = `${casing(name)}: json("${name}")`;
59727
59813
  out += defaultValue ? `.default(${mapColumnDefaultForJson(defaultValue)})` : "";
59728
59814
  return out;
59729
59815
  }
59730
59816
  if (lowered.startsWith("varchar")) {
59731
- let out = `${withCasing3(
59732
- name,
59733
- casing
59817
+ let out = `${casing(
59818
+ name
59734
59819
  )}: varchar("${name}", { length: ${lowered.substring(
59735
59820
  "varchar".length + 1,
59736
59821
  lowered.length - 1
@@ -59739,9 +59824,8 @@ import { sql } from "drizzle-orm"
59739
59824
  return out;
59740
59825
  }
59741
59826
  if (lowered.startsWith("char")) {
59742
- let out = `${withCasing3(
59743
- name,
59744
- casing
59827
+ let out = `${casing(
59828
+ name
59745
59829
  )}: char("${name}", { length: ${lowered.substring(
59746
59830
  "char".length + 1,
59747
59831
  lowered.length - 1
@@ -59753,13 +59837,12 @@ import { sql } from "drizzle-orm"
59753
59837
  let out = `// you can use { mode: 'date' }, if you want to have Date as type for this column
59754
59838
  `;
59755
59839
  const fsp = lowered.startsWith("datetime(") ? lowered.substring("datetime".length + 1, lowered.length - 1) : void 0;
59756
- out = fsp ? `${withCasing3(
59757
- name,
59758
- casing
59840
+ out = fsp ? `${casing(
59841
+ name
59759
59842
  )}: datetime("${name}", { mode: 'string', fsp: ${lowered.substring(
59760
59843
  "datetime".length + 1,
59761
59844
  lowered.length - 1
59762
- )} })` : `${withCasing3(name, casing)}: datetime("${name}", { mode: 'string'})`;
59845
+ )} })` : `${casing(name)}: datetime("${name}", { mode: 'string'})`;
59763
59846
  defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
59764
59847
  out += defaultValue;
59765
59848
  return out;
@@ -59770,7 +59853,7 @@ import { sql } from "drizzle-orm"
59770
59853
  const [precision, scale] = lowered.slice(8, lowered.length - 1).split(",");
59771
59854
  params = { precision, scale };
59772
59855
  }
59773
- let out = params ? `${withCasing3(name, casing)}: decimal("${name}", ${timeConfig2(params)})` : `${withCasing3(name, casing)}: decimal("${name}")`;
59856
+ let out = params ? `${casing(name)}: decimal("${name}", ${timeConfig2(params)})` : `${casing(name)}: decimal("${name}")`;
59774
59857
  defaultValue = typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
59775
59858
  out += defaultValue;
59776
59859
  return out;
@@ -59780,14 +59863,14 @@ import { sql } from "drizzle-orm"
59780
59863
  let length = lowered.length > keyLength ? Number(lowered.substring(keyLength, lowered.length - 1)) : null;
59781
59864
  length = length ? length : null;
59782
59865
  const params = binaryConfig({ length });
59783
- let out = params ? `${withCasing3(name, casing)}: binary("${name}", ${params})` : `${withCasing3(name, casing)}: binary("${name}")`;
59866
+ let out = params ? `${casing(name)}: binary("${name}", ${params})` : `${casing(name)}: binary("${name}")`;
59784
59867
  defaultValue = defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
59785
59868
  out += defaultValue;
59786
59869
  return out;
59787
59870
  }
59788
59871
  if (lowered.startsWith("enum")) {
59789
59872
  const values = lowered.substring("enum".length + 1, lowered.length - 1);
59790
- let out = `${withCasing3(name, casing)}: mysqlEnum("${name}", [${values}])`;
59873
+ let out = `${casing(name)}: mysqlEnum("${name}", [${values}])`;
59791
59874
  out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
59792
59875
  return out;
59793
59876
  }
@@ -59796,7 +59879,7 @@ import { sql } from "drizzle-orm"
59796
59879
  let length = lowered.length > keyLength ? Number(lowered.substring(keyLength, lowered.length - 1)) : null;
59797
59880
  length = length ? length : null;
59798
59881
  const params = binaryConfig({ length });
59799
- let out = params ? `${withCasing3(name, casing)}: varbinary("${name}", ${params})` : `${withCasing3(name, casing)}: varbinary("${name}")`;
59882
+ let out = params ? `${casing(name)}: varbinary("${name}", ${params})` : `${casing(name)}: varbinary("${name}")`;
59800
59883
  defaultValue = defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
59801
59884
  out += defaultValue;
59802
59885
  return out;
@@ -59822,10 +59905,10 @@ import { sql } from "drizzle-orm"
59822
59905
  statement += column6(
59823
59906
  it.type,
59824
59907
  it.name,
59908
+ casing,
59825
59909
  it.default,
59826
59910
  it.autoincrement,
59827
59911
  it.onUpdate,
59828
- casing,
59829
59912
  ((_c = (_b = (_a3 = schema4.internal) == null ? void 0 : _a3.tables[tableName]) == null ? void 0 : _b.columns[it.name]) == null ? void 0 : _c.isDefaultAnExpression) ?? false
59830
59913
  );
59831
59914
  statement += it.primaryKey ? ".primaryKey()" : "";
@@ -59839,15 +59922,13 @@ import { sql } from "drizzle-orm"
59839
59922
  const typeSuffix = isCyclic3(it2) ? ": AnyMySqlColumn" : "";
59840
59923
  const paramsStr = objToStatement23(params);
59841
59924
  if (paramsStr) {
59842
- return `.references(()${typeSuffix} => ${withCasing3(
59843
- it2.tableTo,
59844
- casing
59845
- )}.${withCasing3(it2.columnsTo[0], casing)}, ${paramsStr} )`;
59925
+ return `.references(()${typeSuffix} => ${casing(
59926
+ it2.tableTo
59927
+ )}.${casing(it2.columnsTo[0])}, ${paramsStr} )`;
59846
59928
  }
59847
- return `.references(()${typeSuffix} => ${withCasing3(
59848
- it2.tableTo,
59849
- casing
59850
- )}.${withCasing3(it2.columnsTo[0], casing)})`;
59929
+ return `.references(()${typeSuffix} => ${casing(it2.tableTo)}.${casing(
59930
+ it2.columnsTo[0]
59931
+ )})`;
59851
59932
  }).join("");
59852
59933
  statement += fksStatement;
59853
59934
  }
@@ -59860,13 +59941,13 @@ import { sql } from "drizzle-orm"
59860
59941
  idxs.forEach((it) => {
59861
59942
  let idxKey = it.name.startsWith(tableName) && it.name !== tableName ? it.name.slice(tableName.length + 1) : it.name;
59862
59943
  idxKey = idxKey.endsWith("_index") ? idxKey.slice(0, -"_index".length) + "_idx" : idxKey;
59863
- idxKey = withCasing3(idxKey, casing);
59944
+ idxKey = casing(idxKey);
59864
59945
  const indexGeneratedName = indexName(tableName, it.columns);
59865
59946
  const escapedIndexName = indexGeneratedName === it.name ? "" : `"${it.name}"`;
59866
59947
  statement += ` ${idxKey}: `;
59867
59948
  statement += it.isUnique ? "uniqueIndex(" : "index(";
59868
59949
  statement += `${escapedIndexName})`;
59869
- statement += `.on(${it.columns.map((it2) => `table.${withCasing3(it2, casing)}`).join(", ")}),`;
59950
+ statement += `.on(${it.columns.map((it2) => `table.${casing(it2)}`).join(", ")}),`;
59870
59951
  statement += `
59871
59952
  `;
59872
59953
  });
@@ -59875,11 +59956,11 @@ import { sql } from "drizzle-orm"
59875
59956
  createTableUniques3 = (unqs, casing) => {
59876
59957
  let statement = "";
59877
59958
  unqs.forEach((it) => {
59878
- const idxKey = withCasing3(it.name, casing);
59959
+ const idxKey = casing(it.name);
59879
59960
  statement += ` ${idxKey}: `;
59880
59961
  statement += "unique(";
59881
59962
  statement += `"${it.name}")`;
59882
- statement += `.on(${it.columns.map((it2) => `table.${withCasing3(it2, casing)}`).join(", ")}),`;
59963
+ statement += `.on(${it.columns.map((it2) => `table.${casing(it2)}`).join(", ")}),`;
59883
59964
  statement += `
59884
59965
  `;
59885
59966
  });
@@ -59888,11 +59969,11 @@ import { sql } from "drizzle-orm"
59888
59969
  createTablePKs3 = (pks, casing) => {
59889
59970
  let statement = "";
59890
59971
  pks.forEach((it) => {
59891
- let idxKey = withCasing3(it.name, casing);
59972
+ let idxKey = casing(it.name);
59892
59973
  statement += ` ${idxKey}: `;
59893
59974
  statement += "primaryKey({ columns: [";
59894
59975
  statement += `${it.columns.map((c) => {
59895
- return `table.${withCasing3(c, casing)}`;
59976
+ return `table.${casing(c)}`;
59896
59977
  }).join(", ")}]${it.name ? `, name: "${it.name}"` : ""}}`;
59897
59978
  statement += "),";
59898
59979
  statement += `
@@ -59904,12 +59985,12 @@ import { sql } from "drizzle-orm"
59904
59985
  let statement = "";
59905
59986
  fks.forEach((it) => {
59906
59987
  const isSelf4 = it.tableTo === it.tableFrom;
59907
- const tableTo = isSelf4 ? "table" : `${withCasing3(it.tableTo, casing)}`;
59908
- statement += ` ${withCasing3(it.name, casing)}: foreignKey({
59988
+ const tableTo = isSelf4 ? "table" : `${casing(it.tableTo)}`;
59989
+ statement += ` ${casing(it.name)}: foreignKey({
59909
59990
  `;
59910
- statement += ` columns: [${it.columnsFrom.map((i) => `table.${withCasing3(i, casing)}`).join(", ")}],
59991
+ statement += ` columns: [${it.columnsFrom.map((i) => `table.${casing(i)}`).join(", ")}],
59911
59992
  `;
59912
- statement += ` foreignColumns: [${it.columnsTo.map((i) => `${tableTo}.${withCasing3(i, casing)}`).join(", ")}],
59993
+ statement += ` foreignColumns: [${it.columnsTo.map((i) => `${tableTo}.${casing(i)}`).join(", ")}],
59913
59994
  `;
59914
59995
  statement += ` name: "${it.name}"
59915
59996
  `;
@@ -59938,7 +60019,7 @@ var init_mysqlIntrospect = __esm({
59938
60019
  init_views();
59939
60020
  import_promise = __toESM(require_promise());
59940
60021
  init_mysqlSerializer();
59941
- init_mysql_introspect();
60022
+ init_introspect_mysql();
59942
60023
  init_global();
59943
60024
  init_mjs();
59944
60025
  connectToMySQL = async (config) => {
@@ -60141,7 +60222,7 @@ init_source();
60141
60222
  // package.json
60142
60223
  var package_default = {
60143
60224
  name: "drizzle-kit",
60144
- version: "0.20.2",
60225
+ version: "0.20.4",
60145
60226
  repository: "https://github.com/drizzle-team/drizzle-kit-mirror",
60146
60227
  author: "Drizzle Team",
60147
60228
  license: "MIT",
@@ -60176,12 +60257,13 @@ var package_default = {
60176
60257
  sim: "node -r esbuild-register ./dev/simulate.ts",
60177
60258
  "sim:sqlite": "node -r esbuild-register ./dev/sqlite/index.ts",
60178
60259
  test: "ava test --timeout=60s",
60179
- build: "rm -rf ./dist && tsc -p tsconfig.cli-types.json && cp dist/index.d.ts dist/index.d.mts && tsx build.ts",
60260
+ build: "rm -rf ./dist && tsc -p tsconfig.cli-types.json && pnpm mts && tsx build.ts",
60261
+ mts: "cp dist/index.d.ts dist/index.d.mts && cp dist/utils-studio.d.ts dist/utils-studio.d.mts",
60180
60262
  "build:dev": "rm -rf ./dist && tsx build.dev.ts && tsc -p tsconfig.cli-types.json && chmod +x ./dist/index.cjs",
60181
60263
  packit: "pnpm build && cp package.json dist/ && cd dist && pnpm pack",
60182
60264
  tsc: "tsc -p tsconfig.build.json",
60183
60265
  pub: "cp package.json readme.md dist/ && cd dist && npm publish",
60184
- studio: "./dist/index.cjs studio --verbose",
60266
+ studio: "tsx ./src/cli/index.ts studio --verbose --port=3000",
60185
60267
  "studio:dev": "tsx ./src/cli/index.ts studio --verbose"
60186
60268
  },
60187
60269
  ava: {
@@ -60196,7 +60278,7 @@ var package_default = {
60196
60278
  ]
60197
60279
  },
60198
60280
  dependencies: {
60199
- "@drizzle-team/studio": "^0.0.27",
60281
+ "@drizzle-team/studio": "^0.0.33",
60200
60282
  "@esbuild-kit/esm-loader": "^2.5.5",
60201
60283
  camelcase: "^7.0.1",
60202
60284
  chalk: "^5.2.0",
@@ -60252,6 +60334,18 @@ var package_default = {
60252
60334
  },
60253
60335
  types: "./index.d.mts",
60254
60336
  default: "./index.mjs"
60337
+ },
60338
+ "./utils-studio": {
60339
+ import: {
60340
+ types: "./utils-studio.d.mts",
60341
+ default: "./utils-studio.mjs"
60342
+ },
60343
+ require: {
60344
+ types: "./utils-studio.d.ts",
60345
+ default: "./utils-studio.js"
60346
+ },
60347
+ types: "./utils-studio.d.mts",
60348
+ default: "./utils-studio.mjs"
60255
60349
  }
60256
60350
  }
60257
60351
  };
@@ -60874,6 +60968,7 @@ init_sqlgenerator();
60874
60968
 
60875
60969
  // src/cli/index.ts
60876
60970
  init_selector_ui();
60971
+ var import_studio = require("@drizzle-team/studio");
60877
60972
  init_global();
60878
60973
  var printVersions = async () => {
60879
60974
  const v = await versions();
@@ -61405,7 +61500,7 @@ var introspectPgCommand = new import_commander.Command("introspect:pg").option("
61405
61500
  schemasFilter
61406
61501
  );
61407
61502
  const schemaFile = import_path7.default.join(validatedConfig.out, "schema.ts");
61408
- (0, import_fs11.writeFileSync)(schemaFile, ts);
61503
+ (0, import_fs11.writeFileSync)(schemaFile, ts.file);
61409
61504
  console.log();
61410
61505
  if (snapshots.length === 0) {
61411
61506
  const { sqlStatements, _meta } = await prepareSQL(
@@ -61458,7 +61553,7 @@ var introspectMySqlCommand = new import_commander.Command("introspect:mysql").op
61458
61553
  const tablesFilter = filterConfig ? typeof filterConfig === "string" ? [filterConfig] : filterConfig : [];
61459
61554
  const { schema: schema4, ts } = await mysqlIntrospect2(res, tablesFilter);
61460
61555
  const schemaFile = import_path7.default.join(out, "schema.ts");
61461
- (0, import_fs11.writeFileSync)(schemaFile, ts);
61556
+ (0, import_fs11.writeFileSync)(schemaFile, ts.file);
61462
61557
  console.log();
61463
61558
  if (snapshots.length === 0) {
61464
61559
  const { sqlStatements, _meta } = await prepareSQL(
@@ -61511,7 +61606,7 @@ var introspectSQLiteCommand = new import_commander.Command("introspect:sqlite").
61511
61606
  const tablesFilter = filterConfig ? typeof filterConfig === "string" ? [filterConfig] : filterConfig : [];
61512
61607
  const { schema: schema4, ts } = await sqliteIntrospect2(res, tablesFilter);
61513
61608
  const schemaFile = import_path7.default.join(out, "schema.ts");
61514
- (0, import_fs11.writeFileSync)(schemaFile, ts);
61609
+ (0, import_fs11.writeFileSync)(schemaFile, ts.file);
61515
61610
  console.log();
61516
61611
  if (snapshots.length === 0) {
61517
61612
  const { sqlStatements, _meta } = await prepareSQL(
@@ -61578,33 +61673,63 @@ var studioCommand = new import_commander.Command("studio").option("--port <port>
61578
61673
  const { driver, schema: schemaPath } = drizzleConfig;
61579
61674
  let setup;
61580
61675
  if (driver === "pg") {
61676
+ const { schemaToTypeScript: schemaToTypeScript4 } = await Promise.resolve().then(() => (init_introspect_pg(), introspect_pg_exports));
61677
+ const { serializePg: serializePg2 } = await Promise.resolve().then(() => (init_serializer(), serializer_exports));
61581
61678
  const { schema: schema4, relations: relations4 } = await preparePgSchema2(schemaPath);
61679
+ const internalSchema = await serializePg2(schemaPath);
61680
+ const ts = schemaToTypeScript4(internalSchema, { casing: "camel" });
61582
61681
  setup = await drizzleForPostgres2(
61583
61682
  drizzleConfig,
61584
61683
  schema4,
61585
61684
  relations4,
61685
+ {
61686
+ imports: ts.imports,
61687
+ declarations: ts.decalrations,
61688
+ schemaEntry: ts.schemaEntry
61689
+ },
61586
61690
  Boolean(options.verbose)
61587
61691
  );
61588
61692
  } else if (driver === "mysql2") {
61693
+ const { schemaToTypeScript: schemaToTypeScript4 } = await Promise.resolve().then(() => (init_introspect_mysql(), introspect_mysql_exports));
61589
61694
  const { schema: schema4, relations: relations4 } = await prepareMySqlSchema2(schemaPath);
61695
+ const { serializeMySql: serializeMySql2 } = await Promise.resolve().then(() => (init_serializer(), serializer_exports));
61696
+ const internalSchema = await serializeMySql2(schemaPath);
61697
+ const ts = schemaToTypeScript4(internalSchema, "camel");
61590
61698
  setup = await drizzleForMySQL2(
61591
61699
  drizzleConfig,
61592
61700
  schema4,
61593
61701
  relations4,
61702
+ {
61703
+ imports: ts.imports,
61704
+ declarations: ts.decalrations,
61705
+ schemaEntry: ts.schemaEntry
61706
+ },
61594
61707
  Boolean(options.verbose)
61595
61708
  );
61596
61709
  } else if (driver === "better-sqlite" || driver === "d1" || driver === "libsql" || driver === "turso") {
61710
+ const { schemaToTypeScript: schemaToTypeScript4 } = await Promise.resolve().then(() => (init_introspect_sqlite(), introspect_sqlite_exports));
61597
61711
  const { schema: schema4, relations: relations4 } = await prepareSQLiteSchema2(schemaPath);
61712
+ const { serializeSQLite: serializeSQLite2 } = await Promise.resolve().then(() => (init_serializer(), serializer_exports));
61713
+ const internalSchema = await serializeSQLite2(schemaPath);
61714
+ const ts = schemaToTypeScript4(internalSchema, "camel");
61598
61715
  setup = await drizzleForSQLite2(
61599
61716
  drizzleConfig,
61600
61717
  schema4,
61601
61718
  relations4,
61719
+ {
61720
+ imports: ts.imports,
61721
+ declarations: ts.decalrations,
61722
+ schemaEntry: ts.schemaEntry
61723
+ },
61602
61724
  Boolean(options.verbose)
61603
61725
  );
61604
61726
  } else {
61605
61727
  assertUnreachable(driver);
61606
61728
  }
61607
- const server = await (0, import_server.prepareServer)(setup);
61729
+ const qeueryEngine = (0, import_studio.queryEngineForSetup)(setup);
61730
+ const server = await (0, import_server.prepareServer)((_) => {
61731
+ return qeueryEngine;
61732
+ });
61608
61733
  const port = options.port ?? 4983;
61609
61734
  const host = options.host ?? "127.0.0.1";
61610
61735
  console.log();