drizzle-kit 0.20.2 → 0.20.4-d303ac3
Sign up to get free protection for your applications and to get access to all the features.
- package/bin.cjs +245 -155
- package/cli/commands/pgIntrospect.d.ts +6 -1
- package/cli/commands/sqliteIntrospect.d.ts +6 -1
- package/introspect-pg.d.ts +9 -0
- package/introspect-sqlite.d.ts +10 -0
- package/package.json +17 -4
- package/serializer/studioUtils.d.ts +15 -3
- package/utils-studio.d.mts +5 -0
- package/utils-studio.d.ts +1 -1
- package/utils-studio.js +13 -3
- package/utils-studio.mjs +3410 -0
- package/utils.js +22 -17
- package/introspect.d.ts +0 -4
- package/sqlite-introspect.d.ts +0 -5
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
|
6818
|
+
var set2 = new ArraySet();
|
6819
6819
|
for (var i = 0, len = aArray.length; i < len; i++) {
|
6820
|
-
|
6820
|
+
set2.add(aArray[i], aAllowDuplicates);
|
6821
6821
|
}
|
6822
|
-
return
|
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
|
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]
|
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
|
-
|
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
|
-
|
19024
|
-
|
19025
|
-
|
19026
|
-
|
19027
|
-
|
19028
|
-
|
19029
|
-
|
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)).join(",")}
|
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((
|
19807
|
-
|
19808
|
-
return
|
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
|
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,
|
19963
|
-
this.set =
|
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((
|
20020
|
-
const prev =
|
20036
|
+
parts = parts.reduce((set2, part) => {
|
20037
|
+
const prev = set2[set2.length - 1];
|
20021
20038
|
if (part === "**" && prev === "**") {
|
20022
|
-
return
|
20039
|
+
return set2;
|
20023
20040
|
}
|
20024
20041
|
if (part === "..") {
|
20025
20042
|
if (prev && prev !== ".." && prev !== "." && prev !== "**") {
|
20026
|
-
|
20027
|
-
return
|
20043
|
+
set2.pop();
|
20044
|
+
return set2;
|
20028
20045
|
}
|
20029
20046
|
}
|
20030
|
-
|
20031
|
-
return
|
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
|
20550
|
-
if (!
|
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 =
|
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
|
20617
|
-
this.debug(this.pattern, "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 <
|
20625
|
-
const pattern =
|
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
|
-
|
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
|
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
|
25715
|
-
"src/sqlite
|
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
|
-
|
25854
|
+
const importsTs = `import { ${uniqueSqliteImports.join(
|
25833
25855
|
", "
|
25834
|
-
)} } from "drizzle-orm/
|
25835
|
-
import { sql } from "drizzle-orm"
|
25856
|
+
)} } from "drizzle-orm/pg-core"
|
25857
|
+
import { sql } from "drizzle-orm"
|
25836
25858
|
|
25837
25859
|
`;
|
25838
|
-
|
25839
|
-
|
25840
|
-
|
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)).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
|
-
|
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
|
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
|
-
|
53935
|
+
set3.items.push(Pair.createPair(value, null, ctx));
|
53909
53936
|
}
|
53910
|
-
return
|
53937
|
+
return set3;
|
53911
53938
|
}
|
53912
53939
|
};
|
53913
53940
|
YAMLSet.tag = "tag:yaml.org,2002:set";
|
53914
|
-
var
|
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 =
|
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
|
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
|
-
|
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
|
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:
|
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":
|
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 = {
|
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 = {
|
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,7 +58336,7 @@ 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()));
|
@@ -58313,26 +58344,28 @@ var init_studioUtils = __esm({
|
|
58313
58344
|
logger: verbose
|
58314
58345
|
});
|
58315
58346
|
return {
|
58316
|
-
|
58347
|
+
dialect: "pg",
|
58317
58348
|
db,
|
58318
58349
|
schema: pgSchema4,
|
58319
|
-
relations: relations4
|
58350
|
+
relations: relations4,
|
58351
|
+
ts
|
58320
58352
|
};
|
58321
58353
|
};
|
58322
|
-
drizzleForMySQL = async (config, mysqlSchema4, relations4, verbose) => {
|
58354
|
+
drizzleForMySQL = async (config, mysqlSchema4, relations4, ts, verbose) => {
|
58323
58355
|
assertPackages("mysql2");
|
58324
58356
|
const { drizzle: drizzle2 } = await import("drizzle-orm/mysql2");
|
58325
58357
|
const { createPool } = await Promise.resolve().then(() => __toESM(require_promise()));
|
58326
58358
|
const client = createPool({ ...config.dbCredentials, connectionLimit: 1 });
|
58327
58359
|
const db = drizzle2(client, { logger: verbose });
|
58328
58360
|
return {
|
58329
|
-
|
58361
|
+
dialect: "mysql",
|
58330
58362
|
db,
|
58331
58363
|
schema: mysqlSchema4,
|
58332
|
-
relations: relations4
|
58364
|
+
relations: relations4,
|
58365
|
+
ts
|
58333
58366
|
};
|
58334
58367
|
};
|
58335
|
-
drizzleForSQLite = async (config, sqliteSchema2, relations4, verbose) => {
|
58368
|
+
drizzleForSQLite = async (config, sqliteSchema2, relations4, ts, verbose) => {
|
58336
58369
|
const { driver, dbCredentials: creds } = config;
|
58337
58370
|
if (driver === "d1") {
|
58338
58371
|
const { drizzle: drizzle2 } = await Promise.resolve().then(() => (init_driver(), driver_exports));
|
@@ -58341,10 +58374,11 @@ var init_studioUtils = __esm({
|
|
58341
58374
|
logger: verbose
|
58342
58375
|
});
|
58343
58376
|
return {
|
58344
|
-
|
58377
|
+
dialect: "sqlite",
|
58345
58378
|
db,
|
58346
58379
|
schema: sqliteSchema2,
|
58347
|
-
relations: relations4
|
58380
|
+
relations: relations4,
|
58381
|
+
ts
|
58348
58382
|
};
|
58349
58383
|
}
|
58350
58384
|
if (driver === "better-sqlite") {
|
@@ -58354,10 +58388,11 @@ var init_studioUtils = __esm({
|
|
58354
58388
|
const client = new Database.default(creds.url);
|
58355
58389
|
const db = drizzle2(client, { logger: verbose });
|
58356
58390
|
return {
|
58357
|
-
|
58391
|
+
dialect: "sqlite",
|
58358
58392
|
db,
|
58359
58393
|
schema: sqliteSchema2,
|
58360
|
-
relations: relations4
|
58394
|
+
relations: relations4,
|
58395
|
+
ts
|
58361
58396
|
};
|
58362
58397
|
}
|
58363
58398
|
if (driver === "libsql" || driver === "turso") {
|
@@ -58370,10 +58405,11 @@ var init_studioUtils = __esm({
|
|
58370
58405
|
{ logger: verbose }
|
58371
58406
|
);
|
58372
58407
|
return {
|
58373
|
-
|
58408
|
+
dialect: "sqlite",
|
58374
58409
|
db,
|
58375
58410
|
schema: sqliteSchema2,
|
58376
|
-
relations: relations4
|
58411
|
+
relations: relations4,
|
58412
|
+
ts
|
58377
58413
|
};
|
58378
58414
|
}
|
58379
58415
|
assertUnreachable(driver);
|
@@ -59379,10 +59415,14 @@ var require_cli_options = __commonJS({
|
|
59379
59415
|
}
|
59380
59416
|
});
|
59381
59417
|
|
59382
|
-
// src/mysql
|
59383
|
-
var
|
59384
|
-
|
59385
|
-
|
59418
|
+
// src/introspect-mysql.ts
|
59419
|
+
var introspect_mysql_exports = {};
|
59420
|
+
__export(introspect_mysql_exports, {
|
59421
|
+
schemaToTypeScript: () => schemaToTypeScript3
|
59422
|
+
});
|
59423
|
+
var mysqlImportsList, objToStatement23, timeConfig2, binaryConfig, importsPatch2, relations3, prepareCasing, schemaToTypeScript3, isCyclic3, isSelf3, mapColumnDefault2, mapColumnDefaultForJson, column6, createTableColumns3, createTableIndexes3, createTableUniques3, createTablePKs3, createTableFKs3;
|
59424
|
+
var init_introspect_mysql = __esm({
|
59425
|
+
"src/introspect-mysql.ts"() {
|
59386
59426
|
init_utils2();
|
59387
59427
|
init_mysqlSerializer();
|
59388
59428
|
mysqlImportsList = /* @__PURE__ */ new Set([
|
@@ -59450,7 +59490,7 @@ var init_mysql_introspect = __esm({
|
|
59450
59490
|
"timestamp without time zone": "timestamp"
|
59451
59491
|
};
|
59452
59492
|
relations3 = /* @__PURE__ */ new Set();
|
59453
|
-
|
59493
|
+
prepareCasing = (casing) => (value) => {
|
59454
59494
|
if (typeof casing === "undefined") {
|
59455
59495
|
return value;
|
59456
59496
|
}
|
@@ -59460,6 +59500,7 @@ var init_mysql_introspect = __esm({
|
|
59460
59500
|
return value;
|
59461
59501
|
};
|
59462
59502
|
schemaToTypeScript3 = (schema4, casing) => {
|
59503
|
+
const withCasing3 = prepareCasing(casing);
|
59463
59504
|
Object.values(schema4.tables).forEach((table4) => {
|
59464
59505
|
Object.values(table4.foreignKeys).forEach((fk4) => {
|
59465
59506
|
const relation = `${fk4.tableFrom}-${fk4.tableTo}`;
|
@@ -59468,7 +59509,7 @@ var init_mysql_introspect = __esm({
|
|
59468
59509
|
});
|
59469
59510
|
const schemas = Object.fromEntries(
|
59470
59511
|
Object.entries(schema4.schemas).map((it) => {
|
59471
|
-
return [it[0], withCasing3(it[1]
|
59512
|
+
return [it[0], withCasing3(it[1])];
|
59472
59513
|
})
|
59473
59514
|
);
|
59474
59515
|
const imports = Object.values(schema4.tables).reduce(
|
@@ -59515,20 +59556,19 @@ var init_mysql_introspect = __esm({
|
|
59515
59556
|
const tableSchema = schemas[table4.schema];
|
59516
59557
|
const func = tableSchema ? tableSchema : "mysqlTable";
|
59517
59558
|
let statement = "";
|
59518
|
-
if (imports.mysql.includes(withCasing3(table4.name
|
59559
|
+
if (imports.mysql.includes(withCasing3(table4.name))) {
|
59519
59560
|
statement = `// Table name is in conflict with ${withCasing3(
|
59520
|
-
table4.name
|
59521
|
-
casing
|
59561
|
+
table4.name
|
59522
59562
|
)} import.
|
59523
59563
|
// Please change to any other name, that is not in imports list
|
59524
59564
|
`;
|
59525
59565
|
}
|
59526
|
-
statement += `export const ${withCasing3(table4.name
|
59566
|
+
statement += `export const ${withCasing3(table4.name)} = ${func}("${table4.name}", {
|
59527
59567
|
`;
|
59528
59568
|
statement += createTableColumns3(
|
59529
59569
|
Object.values(table4.columns),
|
59530
59570
|
Object.values(table4.foreignKeys),
|
59531
|
-
|
59571
|
+
withCasing3,
|
59532
59572
|
table4.name,
|
59533
59573
|
schema4
|
59534
59574
|
);
|
@@ -59543,16 +59583,16 @@ var init_mysql_introspect = __esm({
|
|
59543
59583
|
statement += createTableIndexes3(
|
59544
59584
|
table4.name,
|
59545
59585
|
Object.values(table4.indexes),
|
59546
|
-
|
59586
|
+
withCasing3
|
59547
59587
|
);
|
59548
|
-
statement += createTableFKs3(Object.values(filteredFKs),
|
59588
|
+
statement += createTableFKs3(Object.values(filteredFKs), withCasing3);
|
59549
59589
|
statement += createTablePKs3(
|
59550
59590
|
Object.values(table4.compositePrimaryKeys),
|
59551
|
-
|
59591
|
+
withCasing3
|
59552
59592
|
);
|
59553
59593
|
statement += createTableUniques3(
|
59554
59594
|
Object.values(table4.uniqueConstraints),
|
59555
|
-
|
59595
|
+
withCasing3
|
59556
59596
|
);
|
59557
59597
|
statement += " }\n";
|
59558
59598
|
statement += "}";
|
@@ -59566,16 +59606,28 @@ var init_mysql_introspect = __esm({
|
|
59566
59606
|
"AnyMySqlColumn",
|
59567
59607
|
...new Set(imports.mysql)
|
59568
59608
|
];
|
59569
|
-
|
59609
|
+
const importsTs = `import { ${uniqueMySqlImports.join(
|
59570
59610
|
", "
|
59571
59611
|
)} } from "drizzle-orm/mysql-core"
|
59572
59612
|
import { sql } from "drizzle-orm"
|
59573
59613
|
|
59574
59614
|
`;
|
59575
|
-
|
59576
|
-
|
59577
|
-
|
59578
|
-
|
59615
|
+
let decalrations = schemaStatements;
|
59616
|
+
decalrations += "\n";
|
59617
|
+
decalrations += tableStatements.join("\n\n");
|
59618
|
+
const file = importsTs + decalrations;
|
59619
|
+
const schemaEntry = `
|
59620
|
+
{
|
59621
|
+
${Object.values(schema4.tables).map((it) => withCasing3(it.name)).join(",")}
|
59622
|
+
}
|
59623
|
+
`;
|
59624
|
+
return {
|
59625
|
+
file,
|
59626
|
+
// backward compatible, print to file
|
59627
|
+
imports: importsTs,
|
59628
|
+
decalrations,
|
59629
|
+
schemaEntry
|
59630
|
+
};
|
59579
59631
|
};
|
59580
59632
|
isCyclic3 = (fk4) => {
|
59581
59633
|
const key = `${fk4.tableFrom}-${fk4.tableTo}`;
|
@@ -59597,51 +59649,51 @@ import { sql } from "drizzle-orm"
|
|
59597
59649
|
}
|
59598
59650
|
return defaultValue;
|
59599
59651
|
};
|
59600
|
-
column6 = (type, name, defaultValue, autoincrement, onUpdate,
|
59652
|
+
column6 = (type, name, casing, defaultValue, autoincrement, onUpdate, isExpression) => {
|
59601
59653
|
let lowered = type;
|
59602
59654
|
if (!type.startsWith("enum(")) {
|
59603
59655
|
lowered = type.toLowerCase();
|
59604
59656
|
}
|
59605
59657
|
if (lowered === "serial") {
|
59606
|
-
return `${
|
59658
|
+
return `${casing(name)}: serial("${name}")`;
|
59607
59659
|
}
|
59608
59660
|
if (lowered.startsWith("int")) {
|
59609
59661
|
const isUnsigned = lowered.startsWith("int unsigned");
|
59610
|
-
let out = `${
|
59662
|
+
let out = `${casing(name)}: int("${name}"${isUnsigned ? ", { unsigned: true }" : ""})`;
|
59611
59663
|
out += autoincrement ? `.autoincrement()` : "";
|
59612
59664
|
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59613
59665
|
return out;
|
59614
59666
|
}
|
59615
59667
|
if (lowered.startsWith("tinyint")) {
|
59616
59668
|
const isUnsigned = lowered.startsWith("tinyint unsigned");
|
59617
|
-
let out = `${
|
59669
|
+
let out = `${casing(name)}: tinyint("${name}"${isUnsigned ? ", { unsigned: true }" : ""})`;
|
59618
59670
|
out += autoincrement ? `.autoincrement()` : "";
|
59619
59671
|
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59620
59672
|
return out;
|
59621
59673
|
}
|
59622
59674
|
if (lowered.startsWith("smallint")) {
|
59623
59675
|
const isUnsigned = lowered.startsWith("smallint unsigned");
|
59624
|
-
let out = `${
|
59676
|
+
let out = `${casing(name)}: smallint("${name}"${isUnsigned ? ", { unsigned: true }" : ""})`;
|
59625
59677
|
out += autoincrement ? `.autoincrement()` : "";
|
59626
59678
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59627
59679
|
return out;
|
59628
59680
|
}
|
59629
59681
|
if (lowered.startsWith("mediumint")) {
|
59630
59682
|
const isUnsigned = lowered.startsWith("mediumint unsigned");
|
59631
|
-
let out = `${
|
59683
|
+
let out = `${casing(name)}: mediumint("${name}"${isUnsigned ? ", { unsigned: true }" : ""})`;
|
59632
59684
|
out += autoincrement ? `.autoincrement()` : "";
|
59633
59685
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59634
59686
|
return out;
|
59635
59687
|
}
|
59636
59688
|
if (lowered.startsWith("bigint")) {
|
59637
59689
|
const isUnsigned = lowered.startsWith("bigint unsigned");
|
59638
|
-
let out = `${
|
59690
|
+
let out = `${casing(name)}: bigint("${name}", { mode: "number"${isUnsigned ? ", unsigned: true" : ""} })`;
|
59639
59691
|
out += autoincrement ? `.autoincrement()` : "";
|
59640
59692
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59641
59693
|
return out;
|
59642
59694
|
}
|
59643
59695
|
if (lowered === "boolean") {
|
59644
|
-
let out = `${
|
59696
|
+
let out = `${casing(name)}: boolean("${name}")`;
|
59645
59697
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59646
59698
|
return out;
|
59647
59699
|
}
|
@@ -59651,17 +59703,17 @@ import { sql } from "drizzle-orm"
|
|
59651
59703
|
const [precision, scale] = lowered.slice(7, lowered.length - 1).split(",");
|
59652
59704
|
params = { precision, scale };
|
59653
59705
|
}
|
59654
|
-
let out = params ? `${
|
59706
|
+
let out = params ? `${casing(name)}: double("${name}", ${timeConfig2(params)})` : `${casing(name)}: double("${name}")`;
|
59655
59707
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59656
59708
|
return out;
|
59657
59709
|
}
|
59658
59710
|
if (lowered === "float") {
|
59659
|
-
let out = `${
|
59711
|
+
let out = `${casing(name)}: float("${name}")`;
|
59660
59712
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59661
59713
|
return out;
|
59662
59714
|
}
|
59663
59715
|
if (lowered === "real") {
|
59664
|
-
let out = `${
|
59716
|
+
let out = `${casing(name)}: real("${name}")`;
|
59665
59717
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59666
59718
|
return out;
|
59667
59719
|
}
|
@@ -59670,7 +59722,7 @@ import { sql } from "drizzle-orm"
|
|
59670
59722
|
let fsp = lowered.length > keyLength ? Number(lowered.substring(keyLength, lowered.length - 1)) : null;
|
59671
59723
|
fsp = fsp ? fsp : null;
|
59672
59724
|
const params = timeConfig2({ fsp, mode: "'string'" });
|
59673
|
-
let out = params ? `${
|
59725
|
+
let out = params ? `${casing(name)}: timestamp("${name}", ${params})` : `${casing(name)}: timestamp("${name}")`;
|
59674
59726
|
defaultValue = defaultValue === "now()" || defaultValue === "(CURRENT_TIMESTAMP)" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59675
59727
|
out += defaultValue;
|
59676
59728
|
let onUpdateNow = onUpdate ? ".onUpdateNow()" : "";
|
@@ -59682,55 +59734,53 @@ import { sql } from "drizzle-orm"
|
|
59682
59734
|
let fsp = lowered.length > keyLength ? Number(lowered.substring(keyLength, lowered.length - 1)) : null;
|
59683
59735
|
fsp = fsp ? fsp : null;
|
59684
59736
|
const params = timeConfig2({ fsp });
|
59685
|
-
let out = params ? `${
|
59737
|
+
let out = params ? `${casing(name)}: time("${name}", ${params})` : `${casing(name)}: time("${name}")`;
|
59686
59738
|
defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59687
59739
|
out += defaultValue;
|
59688
59740
|
return out;
|
59689
59741
|
}
|
59690
59742
|
if (lowered === "date") {
|
59691
59743
|
let out = `// you can use { mode: 'date' }, if you want to have Date as type for this column
|
59692
|
-
${
|
59693
|
-
name
|
59694
|
-
casing
|
59744
|
+
${casing(
|
59745
|
+
name
|
59695
59746
|
)}: date("${name}", { mode: 'string' })`;
|
59696
59747
|
defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59697
59748
|
out += defaultValue;
|
59698
59749
|
return out;
|
59699
59750
|
}
|
59700
59751
|
if (lowered === "text") {
|
59701
|
-
let out = `${
|
59752
|
+
let out = `${casing(name)}: text("${name}")`;
|
59702
59753
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59703
59754
|
return out;
|
59704
59755
|
}
|
59705
59756
|
if (lowered === "tinytext") {
|
59706
|
-
let out = `${
|
59757
|
+
let out = `${casing(name)}: tinytext("${name}")`;
|
59707
59758
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59708
59759
|
return out;
|
59709
59760
|
}
|
59710
59761
|
if (lowered === "mediumtext") {
|
59711
|
-
let out = `${
|
59762
|
+
let out = `${casing(name)}: mediumtext("${name}")`;
|
59712
59763
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59713
59764
|
return out;
|
59714
59765
|
}
|
59715
59766
|
if (lowered === "longtext") {
|
59716
|
-
let out = `${
|
59767
|
+
let out = `${casing(name)}: longtext("${name}")`;
|
59717
59768
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59718
59769
|
return out;
|
59719
59770
|
}
|
59720
59771
|
if (lowered === "year") {
|
59721
|
-
let out = `${
|
59772
|
+
let out = `${casing(name)}: year("${name}")`;
|
59722
59773
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59723
59774
|
return out;
|
59724
59775
|
}
|
59725
59776
|
if (lowered === "json") {
|
59726
|
-
let out = `${
|
59777
|
+
let out = `${casing(name)}: json("${name}")`;
|
59727
59778
|
out += defaultValue ? `.default(${mapColumnDefaultForJson(defaultValue)})` : "";
|
59728
59779
|
return out;
|
59729
59780
|
}
|
59730
59781
|
if (lowered.startsWith("varchar")) {
|
59731
|
-
let out = `${
|
59732
|
-
name
|
59733
|
-
casing
|
59782
|
+
let out = `${casing(
|
59783
|
+
name
|
59734
59784
|
)}: varchar("${name}", { length: ${lowered.substring(
|
59735
59785
|
"varchar".length + 1,
|
59736
59786
|
lowered.length - 1
|
@@ -59739,9 +59789,8 @@ import { sql } from "drizzle-orm"
|
|
59739
59789
|
return out;
|
59740
59790
|
}
|
59741
59791
|
if (lowered.startsWith("char")) {
|
59742
|
-
let out = `${
|
59743
|
-
name
|
59744
|
-
casing
|
59792
|
+
let out = `${casing(
|
59793
|
+
name
|
59745
59794
|
)}: char("${name}", { length: ${lowered.substring(
|
59746
59795
|
"char".length + 1,
|
59747
59796
|
lowered.length - 1
|
@@ -59753,13 +59802,12 @@ import { sql } from "drizzle-orm"
|
|
59753
59802
|
let out = `// you can use { mode: 'date' }, if you want to have Date as type for this column
|
59754
59803
|
`;
|
59755
59804
|
const fsp = lowered.startsWith("datetime(") ? lowered.substring("datetime".length + 1, lowered.length - 1) : void 0;
|
59756
|
-
out = fsp ? `${
|
59757
|
-
name
|
59758
|
-
casing
|
59805
|
+
out = fsp ? `${casing(
|
59806
|
+
name
|
59759
59807
|
)}: datetime("${name}", { mode: 'string', fsp: ${lowered.substring(
|
59760
59808
|
"datetime".length + 1,
|
59761
59809
|
lowered.length - 1
|
59762
|
-
)} })` : `${
|
59810
|
+
)} })` : `${casing(name)}: datetime("${name}", { mode: 'string'})`;
|
59763
59811
|
defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59764
59812
|
out += defaultValue;
|
59765
59813
|
return out;
|
@@ -59770,7 +59818,7 @@ import { sql } from "drizzle-orm"
|
|
59770
59818
|
const [precision, scale] = lowered.slice(8, lowered.length - 1).split(",");
|
59771
59819
|
params = { precision, scale };
|
59772
59820
|
}
|
59773
|
-
let out = params ? `${
|
59821
|
+
let out = params ? `${casing(name)}: decimal("${name}", ${timeConfig2(params)})` : `${casing(name)}: decimal("${name}")`;
|
59774
59822
|
defaultValue = typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59775
59823
|
out += defaultValue;
|
59776
59824
|
return out;
|
@@ -59780,14 +59828,14 @@ import { sql } from "drizzle-orm"
|
|
59780
59828
|
let length = lowered.length > keyLength ? Number(lowered.substring(keyLength, lowered.length - 1)) : null;
|
59781
59829
|
length = length ? length : null;
|
59782
59830
|
const params = binaryConfig({ length });
|
59783
|
-
let out = params ? `${
|
59831
|
+
let out = params ? `${casing(name)}: binary("${name}", ${params})` : `${casing(name)}: binary("${name}")`;
|
59784
59832
|
defaultValue = defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59785
59833
|
out += defaultValue;
|
59786
59834
|
return out;
|
59787
59835
|
}
|
59788
59836
|
if (lowered.startsWith("enum")) {
|
59789
59837
|
const values = lowered.substring("enum".length + 1, lowered.length - 1);
|
59790
|
-
let out = `${
|
59838
|
+
let out = `${casing(name)}: mysqlEnum("${name}", [${values}])`;
|
59791
59839
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59792
59840
|
return out;
|
59793
59841
|
}
|
@@ -59796,7 +59844,7 @@ import { sql } from "drizzle-orm"
|
|
59796
59844
|
let length = lowered.length > keyLength ? Number(lowered.substring(keyLength, lowered.length - 1)) : null;
|
59797
59845
|
length = length ? length : null;
|
59798
59846
|
const params = binaryConfig({ length });
|
59799
|
-
let out = params ? `${
|
59847
|
+
let out = params ? `${casing(name)}: varbinary("${name}", ${params})` : `${casing(name)}: varbinary("${name}")`;
|
59800
59848
|
defaultValue = defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59801
59849
|
out += defaultValue;
|
59802
59850
|
return out;
|
@@ -59822,10 +59870,10 @@ import { sql } from "drizzle-orm"
|
|
59822
59870
|
statement += column6(
|
59823
59871
|
it.type,
|
59824
59872
|
it.name,
|
59873
|
+
casing,
|
59825
59874
|
it.default,
|
59826
59875
|
it.autoincrement,
|
59827
59876
|
it.onUpdate,
|
59828
|
-
casing,
|
59829
59877
|
((_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
59878
|
);
|
59831
59879
|
statement += it.primaryKey ? ".primaryKey()" : "";
|
@@ -59839,15 +59887,13 @@ import { sql } from "drizzle-orm"
|
|
59839
59887
|
const typeSuffix = isCyclic3(it2) ? ": AnyMySqlColumn" : "";
|
59840
59888
|
const paramsStr = objToStatement23(params);
|
59841
59889
|
if (paramsStr) {
|
59842
|
-
return `.references(()${typeSuffix} => ${
|
59843
|
-
it2.tableTo
|
59844
|
-
|
59845
|
-
)}.${withCasing3(it2.columnsTo[0], casing)}, ${paramsStr} )`;
|
59890
|
+
return `.references(()${typeSuffix} => ${casing(
|
59891
|
+
it2.tableTo
|
59892
|
+
)}.${casing(it2.columnsTo[0])}, ${paramsStr} )`;
|
59846
59893
|
}
|
59847
|
-
return `.references(()${typeSuffix} => ${
|
59848
|
-
it2.
|
59849
|
-
|
59850
|
-
)}.${withCasing3(it2.columnsTo[0], casing)})`;
|
59894
|
+
return `.references(()${typeSuffix} => ${casing(it2.tableTo)}.${casing(
|
59895
|
+
it2.columnsTo[0]
|
59896
|
+
)})`;
|
59851
59897
|
}).join("");
|
59852
59898
|
statement += fksStatement;
|
59853
59899
|
}
|
@@ -59860,13 +59906,13 @@ import { sql } from "drizzle-orm"
|
|
59860
59906
|
idxs.forEach((it) => {
|
59861
59907
|
let idxKey = it.name.startsWith(tableName) && it.name !== tableName ? it.name.slice(tableName.length + 1) : it.name;
|
59862
59908
|
idxKey = idxKey.endsWith("_index") ? idxKey.slice(0, -"_index".length) + "_idx" : idxKey;
|
59863
|
-
idxKey =
|
59909
|
+
idxKey = casing(idxKey);
|
59864
59910
|
const indexGeneratedName = indexName(tableName, it.columns);
|
59865
59911
|
const escapedIndexName = indexGeneratedName === it.name ? "" : `"${it.name}"`;
|
59866
59912
|
statement += ` ${idxKey}: `;
|
59867
59913
|
statement += it.isUnique ? "uniqueIndex(" : "index(";
|
59868
59914
|
statement += `${escapedIndexName})`;
|
59869
|
-
statement += `.on(${it.columns.map((it2) => `table.${
|
59915
|
+
statement += `.on(${it.columns.map((it2) => `table.${casing(it2)}`).join(", ")}),`;
|
59870
59916
|
statement += `
|
59871
59917
|
`;
|
59872
59918
|
});
|
@@ -59875,11 +59921,11 @@ import { sql } from "drizzle-orm"
|
|
59875
59921
|
createTableUniques3 = (unqs, casing) => {
|
59876
59922
|
let statement = "";
|
59877
59923
|
unqs.forEach((it) => {
|
59878
|
-
const idxKey =
|
59924
|
+
const idxKey = casing(it.name);
|
59879
59925
|
statement += ` ${idxKey}: `;
|
59880
59926
|
statement += "unique(";
|
59881
59927
|
statement += `"${it.name}")`;
|
59882
|
-
statement += `.on(${it.columns.map((it2) => `table.${
|
59928
|
+
statement += `.on(${it.columns.map((it2) => `table.${casing(it2)}`).join(", ")}),`;
|
59883
59929
|
statement += `
|
59884
59930
|
`;
|
59885
59931
|
});
|
@@ -59888,11 +59934,11 @@ import { sql } from "drizzle-orm"
|
|
59888
59934
|
createTablePKs3 = (pks, casing) => {
|
59889
59935
|
let statement = "";
|
59890
59936
|
pks.forEach((it) => {
|
59891
|
-
let idxKey =
|
59937
|
+
let idxKey = casing(it.name);
|
59892
59938
|
statement += ` ${idxKey}: `;
|
59893
59939
|
statement += "primaryKey({ columns: [";
|
59894
59940
|
statement += `${it.columns.map((c) => {
|
59895
|
-
return `table.${
|
59941
|
+
return `table.${casing(c)}`;
|
59896
59942
|
}).join(", ")}]${it.name ? `, name: "${it.name}"` : ""}}`;
|
59897
59943
|
statement += "),";
|
59898
59944
|
statement += `
|
@@ -59904,12 +59950,12 @@ import { sql } from "drizzle-orm"
|
|
59904
59950
|
let statement = "";
|
59905
59951
|
fks.forEach((it) => {
|
59906
59952
|
const isSelf4 = it.tableTo === it.tableFrom;
|
59907
|
-
const tableTo = isSelf4 ? "table" : `${
|
59908
|
-
statement += ` ${
|
59953
|
+
const tableTo = isSelf4 ? "table" : `${casing(it.tableTo)}`;
|
59954
|
+
statement += ` ${casing(it.name)}: foreignKey({
|
59909
59955
|
`;
|
59910
|
-
statement += ` columns: [${it.columnsFrom.map((i) => `table.${
|
59956
|
+
statement += ` columns: [${it.columnsFrom.map((i) => `table.${casing(i)}`).join(", ")}],
|
59911
59957
|
`;
|
59912
|
-
statement += ` foreignColumns: [${it.columnsTo.map((i) => `${tableTo}.${
|
59958
|
+
statement += ` foreignColumns: [${it.columnsTo.map((i) => `${tableTo}.${casing(i)}`).join(", ")}],
|
59913
59959
|
`;
|
59914
59960
|
statement += ` name: "${it.name}"
|
59915
59961
|
`;
|
@@ -59938,7 +59984,7 @@ var init_mysqlIntrospect = __esm({
|
|
59938
59984
|
init_views();
|
59939
59985
|
import_promise = __toESM(require_promise());
|
59940
59986
|
init_mysqlSerializer();
|
59941
|
-
|
59987
|
+
init_introspect_mysql();
|
59942
59988
|
init_global();
|
59943
59989
|
init_mjs();
|
59944
59990
|
connectToMySQL = async (config) => {
|
@@ -60141,7 +60187,7 @@ init_source();
|
|
60141
60187
|
// package.json
|
60142
60188
|
var package_default = {
|
60143
60189
|
name: "drizzle-kit",
|
60144
|
-
version: "0.20.
|
60190
|
+
version: "0.20.4",
|
60145
60191
|
repository: "https://github.com/drizzle-team/drizzle-kit-mirror",
|
60146
60192
|
author: "Drizzle Team",
|
60147
60193
|
license: "MIT",
|
@@ -60176,12 +60222,13 @@ var package_default = {
|
|
60176
60222
|
sim: "node -r esbuild-register ./dev/simulate.ts",
|
60177
60223
|
"sim:sqlite": "node -r esbuild-register ./dev/sqlite/index.ts",
|
60178
60224
|
test: "ava test --timeout=60s",
|
60179
|
-
build: "rm -rf ./dist && tsc -p tsconfig.cli-types.json &&
|
60225
|
+
build: "rm -rf ./dist && tsc -p tsconfig.cli-types.json && pnpm mts && tsx build.ts",
|
60226
|
+
mts: "cp dist/index.d.ts dist/index.d.mts && cp dist/utils-studio.d.ts dist/utils-studio.d.mts",
|
60180
60227
|
"build:dev": "rm -rf ./dist && tsx build.dev.ts && tsc -p tsconfig.cli-types.json && chmod +x ./dist/index.cjs",
|
60181
60228
|
packit: "pnpm build && cp package.json dist/ && cd dist && pnpm pack",
|
60182
60229
|
tsc: "tsc -p tsconfig.build.json",
|
60183
60230
|
pub: "cp package.json readme.md dist/ && cd dist && npm publish",
|
60184
|
-
studio: "./
|
60231
|
+
studio: "tsx ./src/cli/index.ts studio --verbose --port=3000",
|
60185
60232
|
"studio:dev": "tsx ./src/cli/index.ts studio --verbose"
|
60186
60233
|
},
|
60187
60234
|
ava: {
|
@@ -60196,7 +60243,7 @@ var package_default = {
|
|
60196
60243
|
]
|
60197
60244
|
},
|
60198
60245
|
dependencies: {
|
60199
|
-
"@drizzle-team/studio": "^0.0.
|
60246
|
+
"@drizzle-team/studio": "^0.0.30",
|
60200
60247
|
"@esbuild-kit/esm-loader": "^2.5.5",
|
60201
60248
|
camelcase: "^7.0.1",
|
60202
60249
|
chalk: "^5.2.0",
|
@@ -60252,6 +60299,18 @@ var package_default = {
|
|
60252
60299
|
},
|
60253
60300
|
types: "./index.d.mts",
|
60254
60301
|
default: "./index.mjs"
|
60302
|
+
},
|
60303
|
+
"./utils-studio": {
|
60304
|
+
import: {
|
60305
|
+
types: "./utils-studio.d.mts",
|
60306
|
+
default: "./utils-studio.mjs"
|
60307
|
+
},
|
60308
|
+
require: {
|
60309
|
+
types: "./utils-studio.d.ts",
|
60310
|
+
default: "./utils-studio.js"
|
60311
|
+
},
|
60312
|
+
types: "./utils-studio.d.mts",
|
60313
|
+
default: "./utils-studio.mjs"
|
60255
60314
|
}
|
60256
60315
|
}
|
60257
60316
|
};
|
@@ -60874,6 +60933,7 @@ init_sqlgenerator();
|
|
60874
60933
|
|
60875
60934
|
// src/cli/index.ts
|
60876
60935
|
init_selector_ui();
|
60936
|
+
var import_studio = require("@drizzle-team/studio");
|
60877
60937
|
init_global();
|
60878
60938
|
var printVersions = async () => {
|
60879
60939
|
const v = await versions();
|
@@ -61405,7 +61465,7 @@ var introspectPgCommand = new import_commander.Command("introspect:pg").option("
|
|
61405
61465
|
schemasFilter
|
61406
61466
|
);
|
61407
61467
|
const schemaFile = import_path7.default.join(validatedConfig.out, "schema.ts");
|
61408
|
-
(0, import_fs11.writeFileSync)(schemaFile, ts);
|
61468
|
+
(0, import_fs11.writeFileSync)(schemaFile, ts.file);
|
61409
61469
|
console.log();
|
61410
61470
|
if (snapshots.length === 0) {
|
61411
61471
|
const { sqlStatements, _meta } = await prepareSQL(
|
@@ -61458,7 +61518,7 @@ var introspectMySqlCommand = new import_commander.Command("introspect:mysql").op
|
|
61458
61518
|
const tablesFilter = filterConfig ? typeof filterConfig === "string" ? [filterConfig] : filterConfig : [];
|
61459
61519
|
const { schema: schema4, ts } = await mysqlIntrospect2(res, tablesFilter);
|
61460
61520
|
const schemaFile = import_path7.default.join(out, "schema.ts");
|
61461
|
-
(0, import_fs11.writeFileSync)(schemaFile, ts);
|
61521
|
+
(0, import_fs11.writeFileSync)(schemaFile, ts.file);
|
61462
61522
|
console.log();
|
61463
61523
|
if (snapshots.length === 0) {
|
61464
61524
|
const { sqlStatements, _meta } = await prepareSQL(
|
@@ -61511,7 +61571,7 @@ var introspectSQLiteCommand = new import_commander.Command("introspect:sqlite").
|
|
61511
61571
|
const tablesFilter = filterConfig ? typeof filterConfig === "string" ? [filterConfig] : filterConfig : [];
|
61512
61572
|
const { schema: schema4, ts } = await sqliteIntrospect2(res, tablesFilter);
|
61513
61573
|
const schemaFile = import_path7.default.join(out, "schema.ts");
|
61514
|
-
(0, import_fs11.writeFileSync)(schemaFile, ts);
|
61574
|
+
(0, import_fs11.writeFileSync)(schemaFile, ts.file);
|
61515
61575
|
console.log();
|
61516
61576
|
if (snapshots.length === 0) {
|
61517
61577
|
const { sqlStatements, _meta } = await prepareSQL(
|
@@ -61578,33 +61638,63 @@ var studioCommand = new import_commander.Command("studio").option("--port <port>
|
|
61578
61638
|
const { driver, schema: schemaPath } = drizzleConfig;
|
61579
61639
|
let setup;
|
61580
61640
|
if (driver === "pg") {
|
61641
|
+
const { schemaToTypeScript: schemaToTypeScript4 } = await Promise.resolve().then(() => (init_introspect_pg(), introspect_pg_exports));
|
61642
|
+
const { serializePg: serializePg2 } = await Promise.resolve().then(() => (init_serializer(), serializer_exports));
|
61581
61643
|
const { schema: schema4, relations: relations4 } = await preparePgSchema2(schemaPath);
|
61644
|
+
const internalSchema = await serializePg2(schemaPath);
|
61645
|
+
const ts = schemaToTypeScript4(internalSchema, { casing: "camel" });
|
61582
61646
|
setup = await drizzleForPostgres2(
|
61583
61647
|
drizzleConfig,
|
61584
61648
|
schema4,
|
61585
61649
|
relations4,
|
61650
|
+
{
|
61651
|
+
imports: ts.imports,
|
61652
|
+
declarations: ts.decalrations,
|
61653
|
+
schemaEntry: ts.schemaEntry
|
61654
|
+
},
|
61586
61655
|
Boolean(options.verbose)
|
61587
61656
|
);
|
61588
61657
|
} else if (driver === "mysql2") {
|
61658
|
+
const { schemaToTypeScript: schemaToTypeScript4 } = await Promise.resolve().then(() => (init_introspect_mysql(), introspect_mysql_exports));
|
61589
61659
|
const { schema: schema4, relations: relations4 } = await prepareMySqlSchema2(schemaPath);
|
61660
|
+
const { serializeMySql: serializeMySql2 } = await Promise.resolve().then(() => (init_serializer(), serializer_exports));
|
61661
|
+
const internalSchema = await serializeMySql2(schemaPath);
|
61662
|
+
const ts = schemaToTypeScript4(internalSchema, "camel");
|
61590
61663
|
setup = await drizzleForMySQL2(
|
61591
61664
|
drizzleConfig,
|
61592
61665
|
schema4,
|
61593
61666
|
relations4,
|
61667
|
+
{
|
61668
|
+
imports: ts.imports,
|
61669
|
+
declarations: ts.decalrations,
|
61670
|
+
schemaEntry: ts.schemaEntry
|
61671
|
+
},
|
61594
61672
|
Boolean(options.verbose)
|
61595
61673
|
);
|
61596
61674
|
} else if (driver === "better-sqlite" || driver === "d1" || driver === "libsql" || driver === "turso") {
|
61675
|
+
const { schemaToTypeScript: schemaToTypeScript4 } = await Promise.resolve().then(() => (init_introspect_sqlite(), introspect_sqlite_exports));
|
61597
61676
|
const { schema: schema4, relations: relations4 } = await prepareSQLiteSchema2(schemaPath);
|
61677
|
+
const { serializeSQLite: serializeSQLite2 } = await Promise.resolve().then(() => (init_serializer(), serializer_exports));
|
61678
|
+
const internalSchema = await serializeSQLite2(schemaPath);
|
61679
|
+
const ts = schemaToTypeScript4(internalSchema, "camel");
|
61598
61680
|
setup = await drizzleForSQLite2(
|
61599
61681
|
drizzleConfig,
|
61600
61682
|
schema4,
|
61601
61683
|
relations4,
|
61684
|
+
{
|
61685
|
+
imports: ts.imports,
|
61686
|
+
declarations: ts.decalrations,
|
61687
|
+
schemaEntry: ts.schemaEntry
|
61688
|
+
},
|
61602
61689
|
Boolean(options.verbose)
|
61603
61690
|
);
|
61604
61691
|
} else {
|
61605
61692
|
assertUnreachable(driver);
|
61606
61693
|
}
|
61607
|
-
const
|
61694
|
+
const qeueryEngine = (0, import_studio.queryEngineForSetup)(setup);
|
61695
|
+
const server = await (0, import_server.prepareServer)((_) => {
|
61696
|
+
return qeueryEngine;
|
61697
|
+
});
|
61608
61698
|
const port = options.port ?? 4983;
|
61609
61699
|
const host = options.host ?? "127.0.0.1";
|
61610
61700
|
console.log();
|