drizzle-kit 0.19.0-3126e54 → 0.19.0-9770e22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +942 -1161
- package/index.d.ts +35 -1
- package/package.json +3 -2
- package/utils.js +9 -5
package/index.cjs
CHANGED
|
@@ -4202,7 +4202,7 @@ var require_hanji = __commonJS({
|
|
|
4202
4202
|
return;
|
|
4203
4203
|
}
|
|
4204
4204
|
exports.render = render6;
|
|
4205
|
-
function
|
|
4205
|
+
function renderWithTask4(view, task) {
|
|
4206
4206
|
return __awaiter(this, void 0, void 0, function* () {
|
|
4207
4207
|
const terminal = new TaskTerminal(view, process.stdout);
|
|
4208
4208
|
terminal.requestLayout();
|
|
@@ -4211,7 +4211,7 @@ var require_hanji = __commonJS({
|
|
|
4211
4211
|
return result;
|
|
4212
4212
|
});
|
|
4213
4213
|
}
|
|
4214
|
-
exports.renderWithTask =
|
|
4214
|
+
exports.renderWithTask = renderWithTask4;
|
|
4215
4215
|
var terminateHandler;
|
|
4216
4216
|
function onTerminate(callback) {
|
|
4217
4217
|
terminateHandler = callback;
|
|
@@ -6127,22 +6127,23 @@ var init_pgSerializer = __esm({
|
|
|
6127
6127
|
--end;
|
|
6128
6128
|
return start > 0 || end < str.length ? str.substring(start, end) : str.toString();
|
|
6129
6129
|
};
|
|
6130
|
-
fromDatabase2 = async (db, progressCallback) => {
|
|
6130
|
+
fromDatabase2 = async (db, tablesFilter = (table4) => true, progressCallback) => {
|
|
6131
6131
|
const result = {};
|
|
6132
6132
|
const allTables = await db.query(
|
|
6133
6133
|
`SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema = 'public';`
|
|
6134
6134
|
);
|
|
6135
6135
|
const schemas = new Set(allTables.rows.map((it) => it.table_schema));
|
|
6136
6136
|
schemas.delete("public");
|
|
6137
|
-
if (progressCallback) {
|
|
6138
|
-
progressCallback("tables", allTables.rows.length, "done");
|
|
6139
|
-
}
|
|
6140
6137
|
let columnsCount = 0;
|
|
6141
6138
|
let indexesCount = 0;
|
|
6142
6139
|
let foreignKeysCount = 0;
|
|
6140
|
+
let tableCount = 0;
|
|
6143
6141
|
const all = allTables.rows.map((row) => {
|
|
6144
6142
|
return new Promise(async (res, rej) => {
|
|
6145
6143
|
const tableName = row.table_name;
|
|
6144
|
+
if (!tablesFilter(tableName))
|
|
6145
|
+
return res("");
|
|
6146
|
+
tableCount += 1;
|
|
6146
6147
|
const tableSchema = row.table_schema;
|
|
6147
6148
|
try {
|
|
6148
6149
|
const columnToReturn = {};
|
|
@@ -6350,6 +6351,9 @@ var init_pgSerializer = __esm({
|
|
|
6350
6351
|
res("");
|
|
6351
6352
|
});
|
|
6352
6353
|
});
|
|
6354
|
+
if (progressCallback) {
|
|
6355
|
+
progressCallback("tables", tableCount, "done");
|
|
6356
|
+
}
|
|
6353
6357
|
for await (const _ of all) {
|
|
6354
6358
|
}
|
|
6355
6359
|
if (progressCallback) {
|
|
@@ -7821,7 +7825,7 @@ var init_words = __esm({
|
|
|
7821
7825
|
"mesmero",
|
|
7822
7826
|
"metal_master",
|
|
7823
7827
|
"meteorite",
|
|
7824
|
-
"
|
|
7828
|
+
"micromacro",
|
|
7825
7829
|
"microbe",
|
|
7826
7830
|
"microchip",
|
|
7827
7831
|
"micromax",
|
|
@@ -8397,7 +8401,7 @@ var init_migrate = __esm({
|
|
|
8397
8401
|
prepareSQLitePush = async (config, snapshot) => {
|
|
8398
8402
|
const schemaPath = config.schema;
|
|
8399
8403
|
try {
|
|
8400
|
-
const { prev, cur } = prepareSQLiteDbPushSnapshot(snapshot, schemaPath);
|
|
8404
|
+
const { prev, cur } = await prepareSQLiteDbPushSnapshot(snapshot, schemaPath);
|
|
8401
8405
|
const validatedPrev = sqliteSchema.parse(prev);
|
|
8402
8406
|
const validatedCur = sqliteSchema.parse(cur);
|
|
8403
8407
|
const squashedPrev = squashSqliteScheme(validatedPrev);
|
|
@@ -8822,7 +8826,7 @@ var init_sqlgenerator = __esm({
|
|
|
8822
8826
|
const primaryKeyStatement = column7.primaryKey ? "PRIMARY KEY" : "";
|
|
8823
8827
|
const notNullStatement = column7.notNull ? "NOT NULL" : "";
|
|
8824
8828
|
const defaultStatement = column7.default !== void 0 ? `DEFAULT ${column7.default}` : "";
|
|
8825
|
-
const type = isPgNativeType(column7.type) ? column7.type :
|
|
8829
|
+
const type = isPgNativeType(column7.type) ? column7.type : `"${column7.type}"`;
|
|
8826
8830
|
statement += " " + `"${column7.name}" ${type} ${primaryKeyStatement} ${defaultStatement} ${notNullStatement}`.replace(/ +/g, " ").trim();
|
|
8827
8831
|
statement += (i === columns.length - 1 ? "" : ",") + "\n";
|
|
8828
8832
|
}
|
|
@@ -8986,9 +8990,9 @@ var init_sqlgenerator = __esm({
|
|
|
8986
8990
|
return statement.type === "rename_table" && dialect6 === "pg";
|
|
8987
8991
|
}
|
|
8988
8992
|
convert(statement) {
|
|
8989
|
-
const { tableNameFrom, tableNameTo, toSchema
|
|
8990
|
-
const from =
|
|
8991
|
-
const to =
|
|
8993
|
+
const { tableNameFrom, tableNameTo, toSchema, fromSchema } = statement;
|
|
8994
|
+
const from = fromSchema ? `"${fromSchema}"."${tableNameFrom}"` : `"${tableNameFrom}"`;
|
|
8995
|
+
const to = `"${tableNameTo}"`;
|
|
8992
8996
|
return `ALTER TABLE ${from} RENAME TO ${to};`;
|
|
8993
8997
|
}
|
|
8994
8998
|
};
|
|
@@ -10916,7 +10920,11 @@ var init_snapshotsDiffer = __esm({
|
|
|
10916
10920
|
}).flat();
|
|
10917
10921
|
const jsonReferencesForAllAlteredTables = allAltered.map((it) => {
|
|
10918
10922
|
const schema4 = valueFromSelfOrPatchedNew(it.schema);
|
|
10919
|
-
const forAdded =
|
|
10923
|
+
const forAdded = prepareCreateReferencesJson(
|
|
10924
|
+
it.name,
|
|
10925
|
+
schema4,
|
|
10926
|
+
it.addedForeignKeys
|
|
10927
|
+
);
|
|
10920
10928
|
const forAltered = prepareDropReferencesJson(
|
|
10921
10929
|
it.name,
|
|
10922
10930
|
schema4,
|
|
@@ -28744,7 +28752,7 @@ var require_promise = __commonJS({
|
|
|
28744
28752
|
});
|
|
28745
28753
|
|
|
28746
28754
|
// src/mysql-introspect.ts
|
|
28747
|
-
var mysqlImportsList, objToStatement2, timeConfig, binaryConfig, importsPatch, relations, schemaToTypeScript, isCyclic, isSelf, mapColumnDefault, mapColumnDefaultForJson, column4, createTableColumns, createTableIndexes, createTablePKs, createTableFKs;
|
|
28755
|
+
var mysqlImportsList, objToStatement2, timeConfig, binaryConfig, importsPatch, relations, withCasing, schemaToTypeScript, isCyclic, isSelf, mapColumnDefault, mapColumnDefaultForJson, column4, createTableColumns, createTableIndexes, createTablePKs, createTableFKs;
|
|
28748
28756
|
var init_mysql_introspect = __esm({
|
|
28749
28757
|
"src/mysql-introspect.ts"() {
|
|
28750
28758
|
init_utils2();
|
|
@@ -28814,7 +28822,16 @@ var init_mysql_introspect = __esm({
|
|
|
28814
28822
|
"timestamp without time zone": "timestamp"
|
|
28815
28823
|
};
|
|
28816
28824
|
relations = /* @__PURE__ */ new Set();
|
|
28817
|
-
|
|
28825
|
+
withCasing = (value, casing) => {
|
|
28826
|
+
if (typeof casing === "undefined") {
|
|
28827
|
+
return value;
|
|
28828
|
+
}
|
|
28829
|
+
if (casing === "camel") {
|
|
28830
|
+
return value.camelCase();
|
|
28831
|
+
}
|
|
28832
|
+
return value;
|
|
28833
|
+
};
|
|
28834
|
+
schemaToTypeScript = (schema4, casing) => {
|
|
28818
28835
|
Object.values(schema4.tables).forEach((table4) => {
|
|
28819
28836
|
Object.values(table4.foreignKeys).forEach((fk4) => {
|
|
28820
28837
|
const relation = `${fk4.tableFrom}-${fk4.tableTo}`;
|
|
@@ -28823,7 +28840,7 @@ var init_mysql_introspect = __esm({
|
|
|
28823
28840
|
});
|
|
28824
28841
|
const schemas = Object.fromEntries(
|
|
28825
28842
|
Object.entries(schema4.schemas).map((it) => {
|
|
28826
|
-
return [it[0], it[1]
|
|
28843
|
+
return [it[0], withCasing(it[1], casing)];
|
|
28827
28844
|
})
|
|
28828
28845
|
);
|
|
28829
28846
|
const imports = Object.values(schema4.tables).reduce(
|
|
@@ -28865,16 +28882,20 @@ var init_mysql_introspect = __esm({
|
|
|
28865
28882
|
const schema5 = schemas[table4.schema];
|
|
28866
28883
|
const func = schema5 ? schema5 : "mysqlTable";
|
|
28867
28884
|
let statement = "";
|
|
28868
|
-
if (imports.mysql.includes(table4.name
|
|
28869
|
-
statement = `// Table name is in conflict with ${
|
|
28885
|
+
if (imports.mysql.includes(withCasing(table4.name, casing))) {
|
|
28886
|
+
statement = `// Table name is in conflict with ${withCasing(
|
|
28887
|
+
table4.name,
|
|
28888
|
+
casing
|
|
28889
|
+
)} import.
|
|
28870
28890
|
// Please change to any other name, that is not in imports list
|
|
28871
28891
|
`;
|
|
28872
28892
|
}
|
|
28873
|
-
statement += `export const ${table4.name
|
|
28893
|
+
statement += `export const ${withCasing(table4.name, casing)} = ${func}("${table4.name}", {
|
|
28874
28894
|
`;
|
|
28875
28895
|
statement += createTableColumns(
|
|
28876
28896
|
Object.values(table4.columns),
|
|
28877
|
-
Object.values(table4.foreignKeys)
|
|
28897
|
+
Object.values(table4.foreignKeys),
|
|
28898
|
+
casing
|
|
28878
28899
|
);
|
|
28879
28900
|
statement += "}";
|
|
28880
28901
|
const filteredFKs = Object.values(table4.foreignKeys).filter((it) => {
|
|
@@ -28884,9 +28905,16 @@ var init_mysql_introspect = __esm({
|
|
|
28884
28905
|
statement += ",\n";
|
|
28885
28906
|
statement += "(table) => {\n";
|
|
28886
28907
|
statement += " return {\n";
|
|
28887
|
-
statement += createTableIndexes(
|
|
28888
|
-
|
|
28889
|
-
|
|
28908
|
+
statement += createTableIndexes(
|
|
28909
|
+
table4.name,
|
|
28910
|
+
Object.values(table4.indexes),
|
|
28911
|
+
casing
|
|
28912
|
+
);
|
|
28913
|
+
statement += createTableFKs(Object.values(filteredFKs), casing);
|
|
28914
|
+
statement += createTablePKs(
|
|
28915
|
+
Object.values(table4.compositePrimaryKeys),
|
|
28916
|
+
casing
|
|
28917
|
+
);
|
|
28890
28918
|
statement += " }\n";
|
|
28891
28919
|
statement += "}";
|
|
28892
28920
|
}
|
|
@@ -28930,46 +28958,49 @@ import { sql } from "drizzle-orm"
|
|
|
28930
28958
|
}
|
|
28931
28959
|
return defaultValue;
|
|
28932
28960
|
};
|
|
28933
|
-
column4 = (type, name, defaultValue, autoincrement, onUpdate) => {
|
|
28961
|
+
column4 = (type, name, defaultValue, autoincrement, onUpdate, casing) => {
|
|
28934
28962
|
let lowered = type;
|
|
28935
28963
|
if (!type.startsWith("enum(")) {
|
|
28936
28964
|
lowered = type.toLowerCase();
|
|
28937
28965
|
}
|
|
28938
28966
|
if (lowered === "serial") {
|
|
28939
|
-
return `${name
|
|
28967
|
+
return `${withCasing(name, casing)}: serial("${name}")`;
|
|
28940
28968
|
}
|
|
28941
28969
|
if (lowered.startsWith("int")) {
|
|
28942
|
-
let out = `${name
|
|
28970
|
+
let out = `${withCasing(name, casing)}: int("${name}")`;
|
|
28943
28971
|
out += autoincrement ? `.autoincrement()` : "";
|
|
28944
28972
|
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
28945
28973
|
return out;
|
|
28946
28974
|
}
|
|
28947
28975
|
if (lowered.startsWith("tinyint")) {
|
|
28948
|
-
let out = `${name
|
|
28976
|
+
let out = `${withCasing(name, casing)}: tinyint("${name}")`;
|
|
28949
28977
|
out += autoincrement ? `.autoincrement()` : "";
|
|
28950
28978
|
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
28951
28979
|
return out;
|
|
28952
28980
|
}
|
|
28953
28981
|
if (lowered.startsWith("smallint")) {
|
|
28954
|
-
let out = `${name
|
|
28982
|
+
let out = `${withCasing(name, casing)}: smallint("${name}")`;
|
|
28955
28983
|
out += autoincrement ? `.autoincrement()` : "";
|
|
28956
28984
|
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
28957
28985
|
return out;
|
|
28958
28986
|
}
|
|
28959
28987
|
if (lowered.startsWith("mediumint")) {
|
|
28960
|
-
let out = `${name
|
|
28988
|
+
let out = `${withCasing(name, casing)}: mediumint("${name}")`;
|
|
28961
28989
|
out += autoincrement ? `.autoincrement()` : "";
|
|
28962
28990
|
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
28963
28991
|
return out;
|
|
28964
28992
|
}
|
|
28965
28993
|
if (lowered.startsWith("bigint")) {
|
|
28966
|
-
let out = `${
|
|
28994
|
+
let out = `${withCasing(
|
|
28995
|
+
name,
|
|
28996
|
+
casing
|
|
28997
|
+
)}: bigint("${name}", { mode: "number" })`;
|
|
28967
28998
|
out += autoincrement ? `.autoincrement()` : "";
|
|
28968
28999
|
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
28969
29000
|
return out;
|
|
28970
29001
|
}
|
|
28971
29002
|
if (lowered === "boolean") {
|
|
28972
|
-
let out = `${name
|
|
29003
|
+
let out = `${withCasing(name, casing)}: boolean("${name}")`;
|
|
28973
29004
|
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
28974
29005
|
return out;
|
|
28975
29006
|
}
|
|
@@ -28979,17 +29010,17 @@ import { sql } from "drizzle-orm"
|
|
|
28979
29010
|
const [precision, scale] = lowered.slice(7, lowered.length - 1).split(",");
|
|
28980
29011
|
params = { precision, scale };
|
|
28981
29012
|
}
|
|
28982
|
-
let out = params ? `${name
|
|
29013
|
+
let out = params ? `${withCasing(name, casing)}: double("${name}", ${timeConfig(params)})` : `${withCasing(name, casing)}: double("${name}")`;
|
|
28983
29014
|
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
28984
29015
|
return out;
|
|
28985
29016
|
}
|
|
28986
29017
|
if (lowered === "float") {
|
|
28987
|
-
let out = `${name
|
|
29018
|
+
let out = `${withCasing(name, casing)}: float("${name}")`;
|
|
28988
29019
|
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
28989
29020
|
return out;
|
|
28990
29021
|
}
|
|
28991
29022
|
if (lowered === "real") {
|
|
28992
|
-
let out = `${name
|
|
29023
|
+
let out = `${withCasing(name, casing)}: real("${name}")`;
|
|
28993
29024
|
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
28994
29025
|
return out;
|
|
28995
29026
|
}
|
|
@@ -28998,7 +29029,7 @@ import { sql } from "drizzle-orm"
|
|
|
28998
29029
|
let fsp = lowered.length > keyLength ? Number(lowered.substring(keyLength, lowered.length - 1)) : null;
|
|
28999
29030
|
fsp = fsp ? fsp : null;
|
|
29000
29031
|
const params = timeConfig({ fsp, mode: "'string'" });
|
|
29001
|
-
let out = params ? `${name
|
|
29032
|
+
let out = params ? `${withCasing(name, casing)}: timestamp("${name}", ${params})` : `${withCasing(name, casing)}: timestamp("${name}")`;
|
|
29002
29033
|
defaultValue = defaultValue === "now()" || defaultValue === "(CURRENT_TIMESTAMP)" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
29003
29034
|
out += defaultValue;
|
|
29004
29035
|
let onUpdateNow = onUpdate ? ".onUpdateNow()" : "";
|
|
@@ -29010,50 +29041,56 @@ import { sql } from "drizzle-orm"
|
|
|
29010
29041
|
let fsp = lowered.length > keyLength ? Number(lowered.substring(keyLength, lowered.length - 1)) : null;
|
|
29011
29042
|
fsp = fsp ? fsp : null;
|
|
29012
29043
|
const params = timeConfig({ fsp });
|
|
29013
|
-
let out = params ? `${name
|
|
29044
|
+
let out = params ? `${withCasing(name, casing)}: time("${name}", ${params})` : `${withCasing(name, casing)}: time("${name}")`;
|
|
29014
29045
|
defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
29015
29046
|
out += defaultValue;
|
|
29016
29047
|
return out;
|
|
29017
29048
|
}
|
|
29018
29049
|
if (lowered === "date") {
|
|
29019
29050
|
let out = `// you can use { mode: 'date' }, if you want to have Date as type for this column
|
|
29020
|
-
${
|
|
29051
|
+
${withCasing(
|
|
29052
|
+
name,
|
|
29053
|
+
casing
|
|
29054
|
+
)}: date("${name}", { mode: 'string' })`;
|
|
29021
29055
|
defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
29022
29056
|
out += defaultValue;
|
|
29023
29057
|
return out;
|
|
29024
29058
|
}
|
|
29025
29059
|
if (lowered === "text") {
|
|
29026
|
-
let out = `${name
|
|
29060
|
+
let out = `${withCasing(name, casing)}: text("${name}")`;
|
|
29027
29061
|
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
29028
29062
|
return out;
|
|
29029
29063
|
}
|
|
29030
29064
|
if (lowered === "tinytext") {
|
|
29031
|
-
let out = `${name
|
|
29065
|
+
let out = `${withCasing(name, casing)}: tinytext("${name}")`;
|
|
29032
29066
|
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
29033
29067
|
return out;
|
|
29034
29068
|
}
|
|
29035
29069
|
if (lowered === "mediumtext") {
|
|
29036
|
-
let out = `${name
|
|
29070
|
+
let out = `${withCasing(name, casing)}: mediumtext("${name}")`;
|
|
29037
29071
|
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
29038
29072
|
return out;
|
|
29039
29073
|
}
|
|
29040
29074
|
if (lowered === "longtext") {
|
|
29041
|
-
let out = `${name
|
|
29075
|
+
let out = `${withCasing(name, casing)}: longtext("${name}")`;
|
|
29042
29076
|
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
29043
29077
|
return out;
|
|
29044
29078
|
}
|
|
29045
29079
|
if (lowered === "year") {
|
|
29046
|
-
let out = `${name
|
|
29080
|
+
let out = `${withCasing(name, casing)}: year("${name}")`;
|
|
29047
29081
|
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
29048
29082
|
return out;
|
|
29049
29083
|
}
|
|
29050
29084
|
if (lowered === "json") {
|
|
29051
|
-
let out = `${name
|
|
29085
|
+
let out = `${withCasing(name, casing)}: json("${name}")`;
|
|
29052
29086
|
out += defaultValue ? `.default(${mapColumnDefaultForJson(defaultValue)})` : "";
|
|
29053
29087
|
return out;
|
|
29054
29088
|
}
|
|
29055
29089
|
if (lowered.startsWith("varchar")) {
|
|
29056
|
-
let out = `${
|
|
29090
|
+
let out = `${withCasing(
|
|
29091
|
+
name,
|
|
29092
|
+
casing
|
|
29093
|
+
)}: varchar("${name}", { length: ${lowered.substring(
|
|
29057
29094
|
"varchar".length + 1,
|
|
29058
29095
|
lowered.length - 1
|
|
29059
29096
|
)} })`;
|
|
@@ -29061,7 +29098,10 @@ import { sql } from "drizzle-orm"
|
|
|
29061
29098
|
return out;
|
|
29062
29099
|
}
|
|
29063
29100
|
if (lowered.startsWith("char")) {
|
|
29064
|
-
let out = `${
|
|
29101
|
+
let out = `${withCasing(
|
|
29102
|
+
name,
|
|
29103
|
+
casing
|
|
29104
|
+
)}: char("${name}", { length: ${lowered.substring(
|
|
29065
29105
|
"char".length + 1,
|
|
29066
29106
|
lowered.length - 1
|
|
29067
29107
|
)} })`;
|
|
@@ -29072,10 +29112,13 @@ import { sql } from "drizzle-orm"
|
|
|
29072
29112
|
let out = `// you can use { mode: 'date' }, if you want to have Date as type for this column
|
|
29073
29113
|
`;
|
|
29074
29114
|
const fsp = lowered.startsWith("datetime(") ? lowered.substring("datetime".length + 1, lowered.length - 1) : void 0;
|
|
29075
|
-
out = fsp ? `${
|
|
29115
|
+
out = fsp ? `${withCasing(
|
|
29116
|
+
name,
|
|
29117
|
+
casing
|
|
29118
|
+
)}: datetime("${name}", { mode: 'string', fsp: ${lowered.substring(
|
|
29076
29119
|
"datetime".length + 1,
|
|
29077
29120
|
lowered.length - 1
|
|
29078
|
-
)} })` : `${name
|
|
29121
|
+
)} })` : `${withCasing(name, casing)}: datetime("${name}", { mode: 'string'})`;
|
|
29079
29122
|
defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
29080
29123
|
out += defaultValue;
|
|
29081
29124
|
return out;
|
|
@@ -29086,7 +29129,7 @@ import { sql } from "drizzle-orm"
|
|
|
29086
29129
|
const [precision, scale] = lowered.slice(8, lowered.length - 1).split(",");
|
|
29087
29130
|
params = { precision, scale };
|
|
29088
29131
|
}
|
|
29089
|
-
let out = params ? `${name
|
|
29132
|
+
let out = params ? `${withCasing(name, casing)}: decimal("${name}", ${timeConfig(params)})` : `${withCasing(name, casing)}: decimal("${name}")`;
|
|
29090
29133
|
defaultValue = typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
29091
29134
|
out += defaultValue;
|
|
29092
29135
|
return out;
|
|
@@ -29096,14 +29139,14 @@ import { sql } from "drizzle-orm"
|
|
|
29096
29139
|
let length = lowered.length > keyLength ? Number(lowered.substring(keyLength, lowered.length - 1)) : null;
|
|
29097
29140
|
length = length ? length : null;
|
|
29098
29141
|
const params = binaryConfig({ length });
|
|
29099
|
-
let out = params ? `${name
|
|
29142
|
+
let out = params ? `${withCasing(name, casing)}: binary("${name}", ${params})` : `${withCasing(name, casing)}: binary("${name}")`;
|
|
29100
29143
|
defaultValue = defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
29101
29144
|
out += defaultValue;
|
|
29102
29145
|
return out;
|
|
29103
29146
|
}
|
|
29104
29147
|
if (lowered.startsWith("enum")) {
|
|
29105
29148
|
const values = lowered.substring("enum".length + 1, lowered.length - 1);
|
|
29106
|
-
let out = `${name
|
|
29149
|
+
let out = `${withCasing(name, casing)}: mysqlEnum("${name}", [${values}])`;
|
|
29107
29150
|
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
29108
29151
|
return out;
|
|
29109
29152
|
}
|
|
@@ -29112,7 +29155,7 @@ import { sql } from "drizzle-orm"
|
|
|
29112
29155
|
let length = lowered.length > keyLength ? Number(lowered.substring(keyLength, lowered.length - 1)) : null;
|
|
29113
29156
|
length = length ? length : null;
|
|
29114
29157
|
const params = binaryConfig({ length });
|
|
29115
|
-
let out = params ? `${name
|
|
29158
|
+
let out = params ? `${withCasing(name, casing)}: varbinary("${name}", ${params})` : `${withCasing(name, casing)}: varbinary("${name}")`;
|
|
29116
29159
|
defaultValue = defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
29117
29160
|
out += defaultValue;
|
|
29118
29161
|
return out;
|
|
@@ -29121,7 +29164,7 @@ import { sql } from "drizzle-orm"
|
|
|
29121
29164
|
return `// Warning: Can't parse ${type} from database
|
|
29122
29165
|
// ${type}Type: ${type}("${name}")`;
|
|
29123
29166
|
};
|
|
29124
|
-
createTableColumns = (columns, fks) => {
|
|
29167
|
+
createTableColumns = (columns, fks, casing) => {
|
|
29125
29168
|
let statement = "";
|
|
29126
29169
|
const oneColumnsFKs = Object.values(fks).filter((it) => {
|
|
29127
29170
|
return !isSelf(it);
|
|
@@ -29139,7 +29182,8 @@ import { sql } from "drizzle-orm"
|
|
|
29139
29182
|
it.name,
|
|
29140
29183
|
it.default,
|
|
29141
29184
|
it.autoincrement,
|
|
29142
|
-
it.onUpdate
|
|
29185
|
+
it.onUpdate,
|
|
29186
|
+
casing
|
|
29143
29187
|
);
|
|
29144
29188
|
statement += it.primaryKey ? ".primaryKey()" : "";
|
|
29145
29189
|
statement += it.notNull ? ".notNull()" : "";
|
|
@@ -29152,9 +29196,15 @@ import { sql } from "drizzle-orm"
|
|
|
29152
29196
|
const typeSuffix = isCyclic(it2) ? ": AnyMySqlColumn" : "";
|
|
29153
29197
|
const paramsStr = objToStatement2(params);
|
|
29154
29198
|
if (paramsStr) {
|
|
29155
|
-
return `.references(()${typeSuffix} => ${
|
|
29156
|
-
|
|
29157
|
-
|
|
29199
|
+
return `.references(()${typeSuffix} => ${withCasing(
|
|
29200
|
+
it2.tableTo,
|
|
29201
|
+
casing
|
|
29202
|
+
)}.${withCasing(it2.columnsTo[0], casing)}, ${paramsStr} )`;
|
|
29203
|
+
}
|
|
29204
|
+
return `.references(()${typeSuffix} => ${withCasing(
|
|
29205
|
+
it2.tableTo,
|
|
29206
|
+
casing
|
|
29207
|
+
)}.${withCasing(it2.columnsTo[0], casing)})`;
|
|
29158
29208
|
}).join("");
|
|
29159
29209
|
statement += fksStatement;
|
|
29160
29210
|
}
|
|
@@ -29162,31 +29212,31 @@ import { sql } from "drizzle-orm"
|
|
|
29162
29212
|
});
|
|
29163
29213
|
return statement;
|
|
29164
29214
|
};
|
|
29165
|
-
createTableIndexes = (tableName, idxs) => {
|
|
29215
|
+
createTableIndexes = (tableName, idxs, casing) => {
|
|
29166
29216
|
let statement = "";
|
|
29167
29217
|
idxs.forEach((it) => {
|
|
29168
29218
|
let idxKey = it.name.startsWith(tableName) && it.name !== tableName ? it.name.slice(tableName.length + 1) : it.name;
|
|
29169
29219
|
idxKey = idxKey.endsWith("_index") ? idxKey.slice(0, -"_index".length) + "_idx" : idxKey;
|
|
29170
|
-
idxKey = idxKey
|
|
29220
|
+
idxKey = withCasing(idxKey, casing);
|
|
29171
29221
|
const indexGeneratedName = indexName(tableName, it.columns);
|
|
29172
29222
|
const escapedIndexName = indexGeneratedName === it.name ? "" : `"${it.name}"`;
|
|
29173
29223
|
statement += ` ${idxKey}: `;
|
|
29174
29224
|
statement += it.isUnique ? "uniqueIndex(" : "index(";
|
|
29175
29225
|
statement += `${escapedIndexName})`;
|
|
29176
|
-
statement += `.on(${it.columns.map((it2) => `table.${it2
|
|
29226
|
+
statement += `.on(${it.columns.map((it2) => `table.${withCasing(it2, casing)}`).join(", ")}),`;
|
|
29177
29227
|
statement += `
|
|
29178
29228
|
`;
|
|
29179
29229
|
});
|
|
29180
29230
|
return statement;
|
|
29181
29231
|
};
|
|
29182
|
-
createTablePKs = (pks) => {
|
|
29232
|
+
createTablePKs = (pks, casing) => {
|
|
29183
29233
|
let statement = "";
|
|
29184
29234
|
pks.forEach((it) => {
|
|
29185
|
-
let idxKey = it.name
|
|
29235
|
+
let idxKey = withCasing(it.name, casing);
|
|
29186
29236
|
statement += ` ${idxKey}: `;
|
|
29187
29237
|
statement += "primaryKey(";
|
|
29188
29238
|
statement += `${it.columns.map((c) => {
|
|
29189
|
-
return `table.${c
|
|
29239
|
+
return `table.${withCasing(c, casing)}`;
|
|
29190
29240
|
}).join(", ")}`;
|
|
29191
29241
|
statement += ")";
|
|
29192
29242
|
statement += `
|
|
@@ -29194,16 +29244,16 @@ import { sql } from "drizzle-orm"
|
|
|
29194
29244
|
});
|
|
29195
29245
|
return statement;
|
|
29196
29246
|
};
|
|
29197
|
-
createTableFKs = (fks) => {
|
|
29247
|
+
createTableFKs = (fks, casing) => {
|
|
29198
29248
|
let statement = "";
|
|
29199
29249
|
fks.forEach((it) => {
|
|
29200
29250
|
const isSelf4 = it.tableTo === it.tableFrom;
|
|
29201
|
-
const tableTo = isSelf4 ? "table" : `${it.tableTo
|
|
29202
|
-
statement += ` ${it.name
|
|
29251
|
+
const tableTo = isSelf4 ? "table" : `${withCasing(it.tableTo, casing)}`;
|
|
29252
|
+
statement += ` ${withCasing(it.name, casing)}: foreignKey({
|
|
29203
29253
|
`;
|
|
29204
|
-
statement += ` columns: [${it.columnsFrom.map((i) => `table.${i
|
|
29254
|
+
statement += ` columns: [${it.columnsFrom.map((i) => `table.${withCasing(i, casing)}`).join(", ")}],
|
|
29205
29255
|
`;
|
|
29206
|
-
statement += ` foreignColumns: [${it.columnsTo.map((i) => `${tableTo}.${i
|
|
29256
|
+
statement += ` foreignColumns: [${it.columnsTo.map((i) => `${tableTo}.${withCasing(i, casing)}`).join(", ")}]
|
|
29207
29257
|
`;
|
|
29208
29258
|
statement += ` })`;
|
|
29209
29259
|
statement += it.onUpdate && it.onUpdate !== "no action" ? `.onUpdate("${it.onUpdate}")` : "";
|
|
@@ -30516,15 +30566,21 @@ var init_mysqlIntrospect = __esm({
|
|
|
30516
30566
|
connectToMySQL = async (config) => {
|
|
30517
30567
|
let client;
|
|
30518
30568
|
let databaseName;
|
|
30519
|
-
if ("
|
|
30520
|
-
const connection = config.connectionString;
|
|
30569
|
+
if (config.dbCredentials.type === "url") {
|
|
30570
|
+
const connection = config.dbCredentials.connectionString;
|
|
30521
30571
|
client = await (0, import_promise.createConnection)(connection);
|
|
30522
30572
|
const connectionUrl = new URL(connection);
|
|
30523
30573
|
const pathname = connectionUrl.pathname;
|
|
30524
30574
|
databaseName = pathname.split("/")[pathname.split("/").length - 1];
|
|
30525
|
-
|
|
30526
|
-
|
|
30527
|
-
|
|
30575
|
+
if (!databaseName || databaseName === "") {
|
|
30576
|
+
throw Error(
|
|
30577
|
+
"You should specify a database name in connection string (mysql://USER:PASSWORD@HOST:PORT/DATABASE)"
|
|
30578
|
+
);
|
|
30579
|
+
}
|
|
30580
|
+
} else if (config.dbCredentials.type === "params") {
|
|
30581
|
+
const { type, ...creds } = config.dbCredentials;
|
|
30582
|
+
client = await (0, import_promise.createConnection)(creds);
|
|
30583
|
+
databaseName = creds.database;
|
|
30528
30584
|
} else {
|
|
30529
30585
|
throw Error(
|
|
30530
30586
|
"Either `connectionString` or `host, port, etc.` params be provided in config file"
|
|
@@ -30533,22 +30589,35 @@ var init_mysqlIntrospect = __esm({
|
|
|
30533
30589
|
await client.connect();
|
|
30534
30590
|
return { client, databaseName };
|
|
30535
30591
|
};
|
|
30536
|
-
mysqlIntrospect = async (config) => {
|
|
30592
|
+
mysqlIntrospect = async (config, filters) => {
|
|
30537
30593
|
const { client, databaseName } = await connectToMySQL(config);
|
|
30594
|
+
const matchers = filters.map((it) => {
|
|
30595
|
+
return new Minimatch(it);
|
|
30596
|
+
});
|
|
30597
|
+
const filter2 = (tableName) => {
|
|
30598
|
+
if (matchers.length === 0)
|
|
30599
|
+
return true;
|
|
30600
|
+
for (let i = 0; i < matchers.length; i++) {
|
|
30601
|
+
const matcher = matchers[i];
|
|
30602
|
+
if (matcher.match(tableName))
|
|
30603
|
+
return true;
|
|
30604
|
+
}
|
|
30605
|
+
return false;
|
|
30606
|
+
};
|
|
30538
30607
|
const progress = new IntrospectProgress();
|
|
30539
30608
|
const res = await (0, import_hanji5.renderWithTask)(
|
|
30540
30609
|
progress,
|
|
30541
30610
|
fromDatabase(
|
|
30542
30611
|
client,
|
|
30543
30612
|
databaseName,
|
|
30544
|
-
|
|
30613
|
+
filter2,
|
|
30545
30614
|
(stage, count, status) => {
|
|
30546
30615
|
progress.update(stage, count, status);
|
|
30547
30616
|
}
|
|
30548
30617
|
)
|
|
30549
30618
|
);
|
|
30550
30619
|
const schema4 = { id: originUUID, prevId: "", ...res };
|
|
30551
|
-
const ts = schemaToTypeScript(schema4);
|
|
30620
|
+
const ts = schemaToTypeScript(schema4, config.introspect.casing);
|
|
30552
30621
|
return { schema: schema4, ts };
|
|
30553
30622
|
};
|
|
30554
30623
|
mysqlPushIntrospect = async (connection, filters) => {
|
|
@@ -30573,825 +30642,8 @@ var init_mysqlIntrospect = __esm({
|
|
|
30573
30642
|
}
|
|
30574
30643
|
});
|
|
30575
30644
|
|
|
30576
|
-
// node_modules/.pnpm/better-sqlite3@8.4.0/node_modules/better-sqlite3/lib/util.js
|
|
30577
|
-
var require_util = __commonJS({
|
|
30578
|
-
"node_modules/.pnpm/better-sqlite3@8.4.0/node_modules/better-sqlite3/lib/util.js"(exports) {
|
|
30579
|
-
"use strict";
|
|
30580
|
-
exports.getBooleanOption = (options, key) => {
|
|
30581
|
-
let value = false;
|
|
30582
|
-
if (key in options && typeof (value = options[key]) !== "boolean") {
|
|
30583
|
-
throw new TypeError(`Expected the "${key}" option to be a boolean`);
|
|
30584
|
-
}
|
|
30585
|
-
return value;
|
|
30586
|
-
};
|
|
30587
|
-
exports.cppdb = Symbol();
|
|
30588
|
-
exports.inspect = Symbol.for("nodejs.util.inspect.custom");
|
|
30589
|
-
}
|
|
30590
|
-
});
|
|
30591
|
-
|
|
30592
|
-
// node_modules/.pnpm/better-sqlite3@8.4.0/node_modules/better-sqlite3/lib/sqlite-error.js
|
|
30593
|
-
var require_sqlite_error = __commonJS({
|
|
30594
|
-
"node_modules/.pnpm/better-sqlite3@8.4.0/node_modules/better-sqlite3/lib/sqlite-error.js"(exports, module2) {
|
|
30595
|
-
"use strict";
|
|
30596
|
-
var descriptor = { value: "SqliteError", writable: true, enumerable: false, configurable: true };
|
|
30597
|
-
function SqliteError(message, code) {
|
|
30598
|
-
if (new.target !== SqliteError) {
|
|
30599
|
-
return new SqliteError(message, code);
|
|
30600
|
-
}
|
|
30601
|
-
if (typeof code !== "string") {
|
|
30602
|
-
throw new TypeError("Expected second argument to be a string");
|
|
30603
|
-
}
|
|
30604
|
-
Error.call(this, message);
|
|
30605
|
-
descriptor.value = "" + message;
|
|
30606
|
-
Object.defineProperty(this, "message", descriptor);
|
|
30607
|
-
Error.captureStackTrace(this, SqliteError);
|
|
30608
|
-
this.code = code;
|
|
30609
|
-
}
|
|
30610
|
-
Object.setPrototypeOf(SqliteError, Error);
|
|
30611
|
-
Object.setPrototypeOf(SqliteError.prototype, Error.prototype);
|
|
30612
|
-
Object.defineProperty(SqliteError.prototype, "name", descriptor);
|
|
30613
|
-
module2.exports = SqliteError;
|
|
30614
|
-
}
|
|
30615
|
-
});
|
|
30616
|
-
|
|
30617
|
-
// node_modules/.pnpm/file-uri-to-path@1.0.0/node_modules/file-uri-to-path/index.js
|
|
30618
|
-
var require_file_uri_to_path = __commonJS({
|
|
30619
|
-
"node_modules/.pnpm/file-uri-to-path@1.0.0/node_modules/file-uri-to-path/index.js"(exports, module2) {
|
|
30620
|
-
var sep2 = require("path").sep || "/";
|
|
30621
|
-
module2.exports = fileUriToPath;
|
|
30622
|
-
function fileUriToPath(uri) {
|
|
30623
|
-
if ("string" != typeof uri || uri.length <= 7 || "file://" != uri.substring(0, 7)) {
|
|
30624
|
-
throw new TypeError("must pass in a file:// URI to convert to a file path");
|
|
30625
|
-
}
|
|
30626
|
-
var rest = decodeURI(uri.substring(7));
|
|
30627
|
-
var firstSlash = rest.indexOf("/");
|
|
30628
|
-
var host = rest.substring(0, firstSlash);
|
|
30629
|
-
var path3 = rest.substring(firstSlash + 1);
|
|
30630
|
-
if ("localhost" == host)
|
|
30631
|
-
host = "";
|
|
30632
|
-
if (host) {
|
|
30633
|
-
host = sep2 + sep2 + host;
|
|
30634
|
-
}
|
|
30635
|
-
path3 = path3.replace(/^(.+)\|/, "$1:");
|
|
30636
|
-
if (sep2 == "\\") {
|
|
30637
|
-
path3 = path3.replace(/\//g, "\\");
|
|
30638
|
-
}
|
|
30639
|
-
if (/^.+\:/.test(path3)) {
|
|
30640
|
-
} else {
|
|
30641
|
-
path3 = sep2 + path3;
|
|
30642
|
-
}
|
|
30643
|
-
return host + path3;
|
|
30644
|
-
}
|
|
30645
|
-
}
|
|
30646
|
-
});
|
|
30647
|
-
|
|
30648
|
-
// node_modules/.pnpm/bindings@1.5.0/node_modules/bindings/bindings.js
|
|
30649
|
-
var require_bindings = __commonJS({
|
|
30650
|
-
"node_modules/.pnpm/bindings@1.5.0/node_modules/bindings/bindings.js"(exports, module2) {
|
|
30651
|
-
var fs6 = require("fs");
|
|
30652
|
-
var path3 = require("path");
|
|
30653
|
-
var fileURLToPath = require_file_uri_to_path();
|
|
30654
|
-
var join6 = path3.join;
|
|
30655
|
-
var dirname = path3.dirname;
|
|
30656
|
-
var exists = fs6.accessSync && function(path4) {
|
|
30657
|
-
try {
|
|
30658
|
-
fs6.accessSync(path4);
|
|
30659
|
-
} catch (e) {
|
|
30660
|
-
return false;
|
|
30661
|
-
}
|
|
30662
|
-
return true;
|
|
30663
|
-
} || fs6.existsSync || path3.existsSync;
|
|
30664
|
-
var defaults2 = {
|
|
30665
|
-
arrow: process.env.NODE_BINDINGS_ARROW || " \u2192 ",
|
|
30666
|
-
compiled: process.env.NODE_BINDINGS_COMPILED_DIR || "compiled",
|
|
30667
|
-
platform: process.platform,
|
|
30668
|
-
arch: process.arch,
|
|
30669
|
-
nodePreGyp: "node-v" + process.versions.modules + "-" + process.platform + "-" + process.arch,
|
|
30670
|
-
version: process.versions.node,
|
|
30671
|
-
bindings: "bindings.node",
|
|
30672
|
-
try: [
|
|
30673
|
-
// node-gyp's linked version in the "build" dir
|
|
30674
|
-
["module_root", "build", "bindings"],
|
|
30675
|
-
// node-waf and gyp_addon (a.k.a node-gyp)
|
|
30676
|
-
["module_root", "build", "Debug", "bindings"],
|
|
30677
|
-
["module_root", "build", "Release", "bindings"],
|
|
30678
|
-
// Debug files, for development (legacy behavior, remove for node v0.9)
|
|
30679
|
-
["module_root", "out", "Debug", "bindings"],
|
|
30680
|
-
["module_root", "Debug", "bindings"],
|
|
30681
|
-
// Release files, but manually compiled (legacy behavior, remove for node v0.9)
|
|
30682
|
-
["module_root", "out", "Release", "bindings"],
|
|
30683
|
-
["module_root", "Release", "bindings"],
|
|
30684
|
-
// Legacy from node-waf, node <= 0.4.x
|
|
30685
|
-
["module_root", "build", "default", "bindings"],
|
|
30686
|
-
// Production "Release" buildtype binary (meh...)
|
|
30687
|
-
["module_root", "compiled", "version", "platform", "arch", "bindings"],
|
|
30688
|
-
// node-qbs builds
|
|
30689
|
-
["module_root", "addon-build", "release", "install-root", "bindings"],
|
|
30690
|
-
["module_root", "addon-build", "debug", "install-root", "bindings"],
|
|
30691
|
-
["module_root", "addon-build", "default", "install-root", "bindings"],
|
|
30692
|
-
// node-pre-gyp path ./lib/binding/{node_abi}-{platform}-{arch}
|
|
30693
|
-
["module_root", "lib", "binding", "nodePreGyp", "bindings"]
|
|
30694
|
-
]
|
|
30695
|
-
};
|
|
30696
|
-
function bindings(opts) {
|
|
30697
|
-
if (typeof opts == "string") {
|
|
30698
|
-
opts = { bindings: opts };
|
|
30699
|
-
} else if (!opts) {
|
|
30700
|
-
opts = {};
|
|
30701
|
-
}
|
|
30702
|
-
Object.keys(defaults2).map(function(i2) {
|
|
30703
|
-
if (!(i2 in opts))
|
|
30704
|
-
opts[i2] = defaults2[i2];
|
|
30705
|
-
});
|
|
30706
|
-
if (!opts.module_root) {
|
|
30707
|
-
opts.module_root = exports.getRoot(exports.getFileName());
|
|
30708
|
-
}
|
|
30709
|
-
if (path3.extname(opts.bindings) != ".node") {
|
|
30710
|
-
opts.bindings += ".node";
|
|
30711
|
-
}
|
|
30712
|
-
var requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
|
|
30713
|
-
var tries = [], i = 0, l = opts.try.length, n, b, err2;
|
|
30714
|
-
for (; i < l; i++) {
|
|
30715
|
-
n = join6.apply(
|
|
30716
|
-
null,
|
|
30717
|
-
opts.try[i].map(function(p) {
|
|
30718
|
-
return opts[p] || p;
|
|
30719
|
-
})
|
|
30720
|
-
);
|
|
30721
|
-
tries.push(n);
|
|
30722
|
-
try {
|
|
30723
|
-
b = opts.path ? requireFunc.resolve(n) : requireFunc(n);
|
|
30724
|
-
if (!opts.path) {
|
|
30725
|
-
b.path = n;
|
|
30726
|
-
}
|
|
30727
|
-
return b;
|
|
30728
|
-
} catch (e) {
|
|
30729
|
-
if (e.code !== "MODULE_NOT_FOUND" && e.code !== "QUALIFIED_PATH_RESOLUTION_FAILED" && !/not find/i.test(e.message)) {
|
|
30730
|
-
throw e;
|
|
30731
|
-
}
|
|
30732
|
-
}
|
|
30733
|
-
}
|
|
30734
|
-
err2 = new Error(
|
|
30735
|
-
"Could not locate the bindings file. Tried:\n" + tries.map(function(a) {
|
|
30736
|
-
return opts.arrow + a;
|
|
30737
|
-
}).join("\n")
|
|
30738
|
-
);
|
|
30739
|
-
err2.tries = tries;
|
|
30740
|
-
throw err2;
|
|
30741
|
-
}
|
|
30742
|
-
module2.exports = exports = bindings;
|
|
30743
|
-
exports.getFileName = function getFileName(calling_file) {
|
|
30744
|
-
var origPST = Error.prepareStackTrace, origSTL = Error.stackTraceLimit, dummy = {}, fileName;
|
|
30745
|
-
Error.stackTraceLimit = 10;
|
|
30746
|
-
Error.prepareStackTrace = function(e, st) {
|
|
30747
|
-
for (var i = 0, l = st.length; i < l; i++) {
|
|
30748
|
-
fileName = st[i].getFileName();
|
|
30749
|
-
if (fileName !== __filename) {
|
|
30750
|
-
if (calling_file) {
|
|
30751
|
-
if (fileName !== calling_file) {
|
|
30752
|
-
return;
|
|
30753
|
-
}
|
|
30754
|
-
} else {
|
|
30755
|
-
return;
|
|
30756
|
-
}
|
|
30757
|
-
}
|
|
30758
|
-
}
|
|
30759
|
-
};
|
|
30760
|
-
Error.captureStackTrace(dummy);
|
|
30761
|
-
dummy.stack;
|
|
30762
|
-
Error.prepareStackTrace = origPST;
|
|
30763
|
-
Error.stackTraceLimit = origSTL;
|
|
30764
|
-
var fileSchema = "file://";
|
|
30765
|
-
if (fileName.indexOf(fileSchema) === 0) {
|
|
30766
|
-
fileName = fileURLToPath(fileName);
|
|
30767
|
-
}
|
|
30768
|
-
return fileName;
|
|
30769
|
-
};
|
|
30770
|
-
exports.getRoot = function getRoot(file) {
|
|
30771
|
-
var dir = dirname(file), prev;
|
|
30772
|
-
while (true) {
|
|
30773
|
-
if (dir === ".") {
|
|
30774
|
-
dir = process.cwd();
|
|
30775
|
-
}
|
|
30776
|
-
if (exists(join6(dir, "package.json")) || exists(join6(dir, "node_modules"))) {
|
|
30777
|
-
return dir;
|
|
30778
|
-
}
|
|
30779
|
-
if (prev === dir) {
|
|
30780
|
-
throw new Error(
|
|
30781
|
-
'Could not find module root given file: "' + file + '". Do you have a `package.json` file? '
|
|
30782
|
-
);
|
|
30783
|
-
}
|
|
30784
|
-
prev = dir;
|
|
30785
|
-
dir = join6(dir, "..");
|
|
30786
|
-
}
|
|
30787
|
-
};
|
|
30788
|
-
}
|
|
30789
|
-
});
|
|
30790
|
-
|
|
30791
|
-
// node_modules/.pnpm/better-sqlite3@8.4.0/node_modules/better-sqlite3/lib/methods/wrappers.js
|
|
30792
|
-
var require_wrappers = __commonJS({
|
|
30793
|
-
"node_modules/.pnpm/better-sqlite3@8.4.0/node_modules/better-sqlite3/lib/methods/wrappers.js"(exports) {
|
|
30794
|
-
"use strict";
|
|
30795
|
-
var { cppdb } = require_util();
|
|
30796
|
-
exports.prepare = function prepare(sql) {
|
|
30797
|
-
return this[cppdb].prepare(sql, this, false);
|
|
30798
|
-
};
|
|
30799
|
-
exports.exec = function exec(sql) {
|
|
30800
|
-
this[cppdb].exec(sql);
|
|
30801
|
-
return this;
|
|
30802
|
-
};
|
|
30803
|
-
exports.close = function close() {
|
|
30804
|
-
this[cppdb].close();
|
|
30805
|
-
return this;
|
|
30806
|
-
};
|
|
30807
|
-
exports.loadExtension = function loadExtension(...args) {
|
|
30808
|
-
this[cppdb].loadExtension(...args);
|
|
30809
|
-
return this;
|
|
30810
|
-
};
|
|
30811
|
-
exports.defaultSafeIntegers = function defaultSafeIntegers(...args) {
|
|
30812
|
-
this[cppdb].defaultSafeIntegers(...args);
|
|
30813
|
-
return this;
|
|
30814
|
-
};
|
|
30815
|
-
exports.unsafeMode = function unsafeMode(...args) {
|
|
30816
|
-
this[cppdb].unsafeMode(...args);
|
|
30817
|
-
return this;
|
|
30818
|
-
};
|
|
30819
|
-
exports.getters = {
|
|
30820
|
-
name: {
|
|
30821
|
-
get: function name() {
|
|
30822
|
-
return this[cppdb].name;
|
|
30823
|
-
},
|
|
30824
|
-
enumerable: true
|
|
30825
|
-
},
|
|
30826
|
-
open: {
|
|
30827
|
-
get: function open2() {
|
|
30828
|
-
return this[cppdb].open;
|
|
30829
|
-
},
|
|
30830
|
-
enumerable: true
|
|
30831
|
-
},
|
|
30832
|
-
inTransaction: {
|
|
30833
|
-
get: function inTransaction() {
|
|
30834
|
-
return this[cppdb].inTransaction;
|
|
30835
|
-
},
|
|
30836
|
-
enumerable: true
|
|
30837
|
-
},
|
|
30838
|
-
readonly: {
|
|
30839
|
-
get: function readonly() {
|
|
30840
|
-
return this[cppdb].readonly;
|
|
30841
|
-
},
|
|
30842
|
-
enumerable: true
|
|
30843
|
-
},
|
|
30844
|
-
memory: {
|
|
30845
|
-
get: function memory() {
|
|
30846
|
-
return this[cppdb].memory;
|
|
30847
|
-
},
|
|
30848
|
-
enumerable: true
|
|
30849
|
-
}
|
|
30850
|
-
};
|
|
30851
|
-
}
|
|
30852
|
-
});
|
|
30853
|
-
|
|
30854
|
-
// node_modules/.pnpm/better-sqlite3@8.4.0/node_modules/better-sqlite3/lib/methods/transaction.js
|
|
30855
|
-
var require_transaction = __commonJS({
|
|
30856
|
-
"node_modules/.pnpm/better-sqlite3@8.4.0/node_modules/better-sqlite3/lib/methods/transaction.js"(exports, module2) {
|
|
30857
|
-
"use strict";
|
|
30858
|
-
var { cppdb } = require_util();
|
|
30859
|
-
var controllers = /* @__PURE__ */ new WeakMap();
|
|
30860
|
-
module2.exports = function transaction(fn) {
|
|
30861
|
-
if (typeof fn !== "function")
|
|
30862
|
-
throw new TypeError("Expected first argument to be a function");
|
|
30863
|
-
const db = this[cppdb];
|
|
30864
|
-
const controller = getController(db, this);
|
|
30865
|
-
const { apply } = Function.prototype;
|
|
30866
|
-
const properties = {
|
|
30867
|
-
default: { value: wrapTransaction(apply, fn, db, controller.default) },
|
|
30868
|
-
deferred: { value: wrapTransaction(apply, fn, db, controller.deferred) },
|
|
30869
|
-
immediate: { value: wrapTransaction(apply, fn, db, controller.immediate) },
|
|
30870
|
-
exclusive: { value: wrapTransaction(apply, fn, db, controller.exclusive) },
|
|
30871
|
-
database: { value: this, enumerable: true }
|
|
30872
|
-
};
|
|
30873
|
-
Object.defineProperties(properties.default.value, properties);
|
|
30874
|
-
Object.defineProperties(properties.deferred.value, properties);
|
|
30875
|
-
Object.defineProperties(properties.immediate.value, properties);
|
|
30876
|
-
Object.defineProperties(properties.exclusive.value, properties);
|
|
30877
|
-
return properties.default.value;
|
|
30878
|
-
};
|
|
30879
|
-
var getController = (db, self2) => {
|
|
30880
|
-
let controller = controllers.get(db);
|
|
30881
|
-
if (!controller) {
|
|
30882
|
-
const shared = {
|
|
30883
|
-
commit: db.prepare("COMMIT", self2, false),
|
|
30884
|
-
rollback: db.prepare("ROLLBACK", self2, false),
|
|
30885
|
-
savepoint: db.prepare("SAVEPOINT ` _bs3. `", self2, false),
|
|
30886
|
-
release: db.prepare("RELEASE ` _bs3. `", self2, false),
|
|
30887
|
-
rollbackTo: db.prepare("ROLLBACK TO ` _bs3. `", self2, false)
|
|
30888
|
-
};
|
|
30889
|
-
controllers.set(db, controller = {
|
|
30890
|
-
default: Object.assign({ begin: db.prepare("BEGIN", self2, false) }, shared),
|
|
30891
|
-
deferred: Object.assign({ begin: db.prepare("BEGIN DEFERRED", self2, false) }, shared),
|
|
30892
|
-
immediate: Object.assign({ begin: db.prepare("BEGIN IMMEDIATE", self2, false) }, shared),
|
|
30893
|
-
exclusive: Object.assign({ begin: db.prepare("BEGIN EXCLUSIVE", self2, false) }, shared)
|
|
30894
|
-
});
|
|
30895
|
-
}
|
|
30896
|
-
return controller;
|
|
30897
|
-
};
|
|
30898
|
-
var wrapTransaction = (apply, fn, db, { begin, commit, rollback, savepoint, release, rollbackTo }) => function sqliteTransaction() {
|
|
30899
|
-
let before, after, undo;
|
|
30900
|
-
if (db.inTransaction) {
|
|
30901
|
-
before = savepoint;
|
|
30902
|
-
after = release;
|
|
30903
|
-
undo = rollbackTo;
|
|
30904
|
-
} else {
|
|
30905
|
-
before = begin;
|
|
30906
|
-
after = commit;
|
|
30907
|
-
undo = rollback;
|
|
30908
|
-
}
|
|
30909
|
-
before.run();
|
|
30910
|
-
try {
|
|
30911
|
-
const result = apply.call(fn, this, arguments);
|
|
30912
|
-
after.run();
|
|
30913
|
-
return result;
|
|
30914
|
-
} catch (ex) {
|
|
30915
|
-
if (db.inTransaction) {
|
|
30916
|
-
undo.run();
|
|
30917
|
-
if (undo !== rollback)
|
|
30918
|
-
after.run();
|
|
30919
|
-
}
|
|
30920
|
-
throw ex;
|
|
30921
|
-
}
|
|
30922
|
-
};
|
|
30923
|
-
}
|
|
30924
|
-
});
|
|
30925
|
-
|
|
30926
|
-
// node_modules/.pnpm/better-sqlite3@8.4.0/node_modules/better-sqlite3/lib/methods/pragma.js
|
|
30927
|
-
var require_pragma = __commonJS({
|
|
30928
|
-
"node_modules/.pnpm/better-sqlite3@8.4.0/node_modules/better-sqlite3/lib/methods/pragma.js"(exports, module2) {
|
|
30929
|
-
"use strict";
|
|
30930
|
-
var { getBooleanOption, cppdb } = require_util();
|
|
30931
|
-
module2.exports = function pragma(source, options) {
|
|
30932
|
-
if (options == null)
|
|
30933
|
-
options = {};
|
|
30934
|
-
if (typeof source !== "string")
|
|
30935
|
-
throw new TypeError("Expected first argument to be a string");
|
|
30936
|
-
if (typeof options !== "object")
|
|
30937
|
-
throw new TypeError("Expected second argument to be an options object");
|
|
30938
|
-
const simple = getBooleanOption(options, "simple");
|
|
30939
|
-
const stmt = this[cppdb].prepare(`PRAGMA ${source}`, this, true);
|
|
30940
|
-
return simple ? stmt.pluck().get() : stmt.all();
|
|
30941
|
-
};
|
|
30942
|
-
}
|
|
30943
|
-
});
|
|
30944
|
-
|
|
30945
|
-
// node_modules/.pnpm/better-sqlite3@8.4.0/node_modules/better-sqlite3/lib/methods/backup.js
|
|
30946
|
-
var require_backup = __commonJS({
|
|
30947
|
-
"node_modules/.pnpm/better-sqlite3@8.4.0/node_modules/better-sqlite3/lib/methods/backup.js"(exports, module2) {
|
|
30948
|
-
"use strict";
|
|
30949
|
-
var fs6 = require("fs");
|
|
30950
|
-
var path3 = require("path");
|
|
30951
|
-
var { promisify } = require("util");
|
|
30952
|
-
var { cppdb } = require_util();
|
|
30953
|
-
var fsAccess = promisify(fs6.access);
|
|
30954
|
-
module2.exports = async function backup(filename, options) {
|
|
30955
|
-
if (options == null)
|
|
30956
|
-
options = {};
|
|
30957
|
-
if (typeof filename !== "string")
|
|
30958
|
-
throw new TypeError("Expected first argument to be a string");
|
|
30959
|
-
if (typeof options !== "object")
|
|
30960
|
-
throw new TypeError("Expected second argument to be an options object");
|
|
30961
|
-
filename = filename.trim();
|
|
30962
|
-
const attachedName = "attached" in options ? options.attached : "main";
|
|
30963
|
-
const handler = "progress" in options ? options.progress : null;
|
|
30964
|
-
if (!filename)
|
|
30965
|
-
throw new TypeError("Backup filename cannot be an empty string");
|
|
30966
|
-
if (filename === ":memory:")
|
|
30967
|
-
throw new TypeError('Invalid backup filename ":memory:"');
|
|
30968
|
-
if (typeof attachedName !== "string")
|
|
30969
|
-
throw new TypeError('Expected the "attached" option to be a string');
|
|
30970
|
-
if (!attachedName)
|
|
30971
|
-
throw new TypeError('The "attached" option cannot be an empty string');
|
|
30972
|
-
if (handler != null && typeof handler !== "function")
|
|
30973
|
-
throw new TypeError('Expected the "progress" option to be a function');
|
|
30974
|
-
await fsAccess(path3.dirname(filename)).catch(() => {
|
|
30975
|
-
throw new TypeError("Cannot save backup because the directory does not exist");
|
|
30976
|
-
});
|
|
30977
|
-
const isNewFile = await fsAccess(filename).then(() => false, () => true);
|
|
30978
|
-
return runBackup(this[cppdb].backup(this, attachedName, filename, isNewFile), handler || null);
|
|
30979
|
-
};
|
|
30980
|
-
var runBackup = (backup, handler) => {
|
|
30981
|
-
let rate = 0;
|
|
30982
|
-
let useDefault = true;
|
|
30983
|
-
return new Promise((resolve2, reject) => {
|
|
30984
|
-
setImmediate(function step() {
|
|
30985
|
-
try {
|
|
30986
|
-
const progress = backup.transfer(rate);
|
|
30987
|
-
if (!progress.remainingPages) {
|
|
30988
|
-
backup.close();
|
|
30989
|
-
resolve2(progress);
|
|
30990
|
-
return;
|
|
30991
|
-
}
|
|
30992
|
-
if (useDefault) {
|
|
30993
|
-
useDefault = false;
|
|
30994
|
-
rate = 100;
|
|
30995
|
-
}
|
|
30996
|
-
if (handler) {
|
|
30997
|
-
const ret = handler(progress);
|
|
30998
|
-
if (ret !== void 0) {
|
|
30999
|
-
if (typeof ret === "number" && ret === ret)
|
|
31000
|
-
rate = Math.max(0, Math.min(2147483647, Math.round(ret)));
|
|
31001
|
-
else
|
|
31002
|
-
throw new TypeError("Expected progress callback to return a number or undefined");
|
|
31003
|
-
}
|
|
31004
|
-
}
|
|
31005
|
-
setImmediate(step);
|
|
31006
|
-
} catch (err2) {
|
|
31007
|
-
backup.close();
|
|
31008
|
-
reject(err2);
|
|
31009
|
-
}
|
|
31010
|
-
});
|
|
31011
|
-
});
|
|
31012
|
-
};
|
|
31013
|
-
}
|
|
31014
|
-
});
|
|
31015
|
-
|
|
31016
|
-
// node_modules/.pnpm/better-sqlite3@8.4.0/node_modules/better-sqlite3/lib/methods/serialize.js
|
|
31017
|
-
var require_serialize = __commonJS({
|
|
31018
|
-
"node_modules/.pnpm/better-sqlite3@8.4.0/node_modules/better-sqlite3/lib/methods/serialize.js"(exports, module2) {
|
|
31019
|
-
"use strict";
|
|
31020
|
-
var { cppdb } = require_util();
|
|
31021
|
-
module2.exports = function serialize(options) {
|
|
31022
|
-
if (options == null)
|
|
31023
|
-
options = {};
|
|
31024
|
-
if (typeof options !== "object")
|
|
31025
|
-
throw new TypeError("Expected first argument to be an options object");
|
|
31026
|
-
const attachedName = "attached" in options ? options.attached : "main";
|
|
31027
|
-
if (typeof attachedName !== "string")
|
|
31028
|
-
throw new TypeError('Expected the "attached" option to be a string');
|
|
31029
|
-
if (!attachedName)
|
|
31030
|
-
throw new TypeError('The "attached" option cannot be an empty string');
|
|
31031
|
-
return this[cppdb].serialize(attachedName);
|
|
31032
|
-
};
|
|
31033
|
-
}
|
|
31034
|
-
});
|
|
31035
|
-
|
|
31036
|
-
// node_modules/.pnpm/better-sqlite3@8.4.0/node_modules/better-sqlite3/lib/methods/function.js
|
|
31037
|
-
var require_function = __commonJS({
|
|
31038
|
-
"node_modules/.pnpm/better-sqlite3@8.4.0/node_modules/better-sqlite3/lib/methods/function.js"(exports, module2) {
|
|
31039
|
-
"use strict";
|
|
31040
|
-
var { getBooleanOption, cppdb } = require_util();
|
|
31041
|
-
module2.exports = function defineFunction(name, options, fn) {
|
|
31042
|
-
if (options == null)
|
|
31043
|
-
options = {};
|
|
31044
|
-
if (typeof options === "function") {
|
|
31045
|
-
fn = options;
|
|
31046
|
-
options = {};
|
|
31047
|
-
}
|
|
31048
|
-
if (typeof name !== "string")
|
|
31049
|
-
throw new TypeError("Expected first argument to be a string");
|
|
31050
|
-
if (typeof fn !== "function")
|
|
31051
|
-
throw new TypeError("Expected last argument to be a function");
|
|
31052
|
-
if (typeof options !== "object")
|
|
31053
|
-
throw new TypeError("Expected second argument to be an options object");
|
|
31054
|
-
if (!name)
|
|
31055
|
-
throw new TypeError("User-defined function name cannot be an empty string");
|
|
31056
|
-
const safeIntegers = "safeIntegers" in options ? +getBooleanOption(options, "safeIntegers") : 2;
|
|
31057
|
-
const deterministic = getBooleanOption(options, "deterministic");
|
|
31058
|
-
const directOnly = getBooleanOption(options, "directOnly");
|
|
31059
|
-
const varargs = getBooleanOption(options, "varargs");
|
|
31060
|
-
let argCount = -1;
|
|
31061
|
-
if (!varargs) {
|
|
31062
|
-
argCount = fn.length;
|
|
31063
|
-
if (!Number.isInteger(argCount) || argCount < 0)
|
|
31064
|
-
throw new TypeError("Expected function.length to be a positive integer");
|
|
31065
|
-
if (argCount > 100)
|
|
31066
|
-
throw new RangeError("User-defined functions cannot have more than 100 arguments");
|
|
31067
|
-
}
|
|
31068
|
-
this[cppdb].function(fn, name, argCount, safeIntegers, deterministic, directOnly);
|
|
31069
|
-
return this;
|
|
31070
|
-
};
|
|
31071
|
-
}
|
|
31072
|
-
});
|
|
31073
|
-
|
|
31074
|
-
// node_modules/.pnpm/better-sqlite3@8.4.0/node_modules/better-sqlite3/lib/methods/aggregate.js
|
|
31075
|
-
var require_aggregate = __commonJS({
|
|
31076
|
-
"node_modules/.pnpm/better-sqlite3@8.4.0/node_modules/better-sqlite3/lib/methods/aggregate.js"(exports, module2) {
|
|
31077
|
-
"use strict";
|
|
31078
|
-
var { getBooleanOption, cppdb } = require_util();
|
|
31079
|
-
module2.exports = function defineAggregate(name, options) {
|
|
31080
|
-
if (typeof name !== "string")
|
|
31081
|
-
throw new TypeError("Expected first argument to be a string");
|
|
31082
|
-
if (typeof options !== "object" || options === null)
|
|
31083
|
-
throw new TypeError("Expected second argument to be an options object");
|
|
31084
|
-
if (!name)
|
|
31085
|
-
throw new TypeError("User-defined function name cannot be an empty string");
|
|
31086
|
-
const start = "start" in options ? options.start : null;
|
|
31087
|
-
const step = getFunctionOption(options, "step", true);
|
|
31088
|
-
const inverse = getFunctionOption(options, "inverse", false);
|
|
31089
|
-
const result = getFunctionOption(options, "result", false);
|
|
31090
|
-
const safeIntegers = "safeIntegers" in options ? +getBooleanOption(options, "safeIntegers") : 2;
|
|
31091
|
-
const deterministic = getBooleanOption(options, "deterministic");
|
|
31092
|
-
const directOnly = getBooleanOption(options, "directOnly");
|
|
31093
|
-
const varargs = getBooleanOption(options, "varargs");
|
|
31094
|
-
let argCount = -1;
|
|
31095
|
-
if (!varargs) {
|
|
31096
|
-
argCount = Math.max(getLength(step), inverse ? getLength(inverse) : 0);
|
|
31097
|
-
if (argCount > 0)
|
|
31098
|
-
argCount -= 1;
|
|
31099
|
-
if (argCount > 100)
|
|
31100
|
-
throw new RangeError("User-defined functions cannot have more than 100 arguments");
|
|
31101
|
-
}
|
|
31102
|
-
this[cppdb].aggregate(start, step, inverse, result, name, argCount, safeIntegers, deterministic, directOnly);
|
|
31103
|
-
return this;
|
|
31104
|
-
};
|
|
31105
|
-
var getFunctionOption = (options, key, required) => {
|
|
31106
|
-
const value = key in options ? options[key] : null;
|
|
31107
|
-
if (typeof value === "function")
|
|
31108
|
-
return value;
|
|
31109
|
-
if (value != null)
|
|
31110
|
-
throw new TypeError(`Expected the "${key}" option to be a function`);
|
|
31111
|
-
if (required)
|
|
31112
|
-
throw new TypeError(`Missing required option "${key}"`);
|
|
31113
|
-
return null;
|
|
31114
|
-
};
|
|
31115
|
-
var getLength = ({ length }) => {
|
|
31116
|
-
if (Number.isInteger(length) && length >= 0)
|
|
31117
|
-
return length;
|
|
31118
|
-
throw new TypeError("Expected function.length to be a positive integer");
|
|
31119
|
-
};
|
|
31120
|
-
}
|
|
31121
|
-
});
|
|
31122
|
-
|
|
31123
|
-
// node_modules/.pnpm/better-sqlite3@8.4.0/node_modules/better-sqlite3/lib/methods/table.js
|
|
31124
|
-
var require_table = __commonJS({
|
|
31125
|
-
"node_modules/.pnpm/better-sqlite3@8.4.0/node_modules/better-sqlite3/lib/methods/table.js"(exports, module2) {
|
|
31126
|
-
"use strict";
|
|
31127
|
-
var { cppdb } = require_util();
|
|
31128
|
-
module2.exports = function defineTable(name, factory) {
|
|
31129
|
-
if (typeof name !== "string")
|
|
31130
|
-
throw new TypeError("Expected first argument to be a string");
|
|
31131
|
-
if (!name)
|
|
31132
|
-
throw new TypeError("Virtual table module name cannot be an empty string");
|
|
31133
|
-
let eponymous = false;
|
|
31134
|
-
if (typeof factory === "object" && factory !== null) {
|
|
31135
|
-
eponymous = true;
|
|
31136
|
-
factory = defer(parseTableDefinition(factory, "used", name));
|
|
31137
|
-
} else {
|
|
31138
|
-
if (typeof factory !== "function")
|
|
31139
|
-
throw new TypeError("Expected second argument to be a function or a table definition object");
|
|
31140
|
-
factory = wrapFactory(factory);
|
|
31141
|
-
}
|
|
31142
|
-
this[cppdb].table(factory, name, eponymous);
|
|
31143
|
-
return this;
|
|
31144
|
-
};
|
|
31145
|
-
function wrapFactory(factory) {
|
|
31146
|
-
return function virtualTableFactory(moduleName, databaseName, tableName, ...args) {
|
|
31147
|
-
const thisObject = {
|
|
31148
|
-
module: moduleName,
|
|
31149
|
-
database: databaseName,
|
|
31150
|
-
table: tableName
|
|
31151
|
-
};
|
|
31152
|
-
const def = apply.call(factory, thisObject, args);
|
|
31153
|
-
if (typeof def !== "object" || def === null) {
|
|
31154
|
-
throw new TypeError(`Virtual table module "${moduleName}" did not return a table definition object`);
|
|
31155
|
-
}
|
|
31156
|
-
return parseTableDefinition(def, "returned", moduleName);
|
|
31157
|
-
};
|
|
31158
|
-
}
|
|
31159
|
-
function parseTableDefinition(def, verb, moduleName) {
|
|
31160
|
-
if (!hasOwnProperty.call(def, "rows")) {
|
|
31161
|
-
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition without a "rows" property`);
|
|
31162
|
-
}
|
|
31163
|
-
if (!hasOwnProperty.call(def, "columns")) {
|
|
31164
|
-
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition without a "columns" property`);
|
|
31165
|
-
}
|
|
31166
|
-
const rows = def.rows;
|
|
31167
|
-
if (typeof rows !== "function" || Object.getPrototypeOf(rows) !== GeneratorFunctionPrototype) {
|
|
31168
|
-
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "rows" property (should be a generator function)`);
|
|
31169
|
-
}
|
|
31170
|
-
let columns = def.columns;
|
|
31171
|
-
if (!Array.isArray(columns) || !(columns = [...columns]).every((x) => typeof x === "string")) {
|
|
31172
|
-
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "columns" property (should be an array of strings)`);
|
|
31173
|
-
}
|
|
31174
|
-
if (columns.length !== new Set(columns).size) {
|
|
31175
|
-
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with duplicate column names`);
|
|
31176
|
-
}
|
|
31177
|
-
if (!columns.length) {
|
|
31178
|
-
throw new RangeError(`Virtual table module "${moduleName}" ${verb} a table definition with zero columns`);
|
|
31179
|
-
}
|
|
31180
|
-
let parameters;
|
|
31181
|
-
if (hasOwnProperty.call(def, "parameters")) {
|
|
31182
|
-
parameters = def.parameters;
|
|
31183
|
-
if (!Array.isArray(parameters) || !(parameters = [...parameters]).every((x) => typeof x === "string")) {
|
|
31184
|
-
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "parameters" property (should be an array of strings)`);
|
|
31185
|
-
}
|
|
31186
|
-
} else {
|
|
31187
|
-
parameters = inferParameters(rows);
|
|
31188
|
-
}
|
|
31189
|
-
if (parameters.length !== new Set(parameters).size) {
|
|
31190
|
-
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with duplicate parameter names`);
|
|
31191
|
-
}
|
|
31192
|
-
if (parameters.length > 32) {
|
|
31193
|
-
throw new RangeError(`Virtual table module "${moduleName}" ${verb} a table definition with more than the maximum number of 32 parameters`);
|
|
31194
|
-
}
|
|
31195
|
-
for (const parameter of parameters) {
|
|
31196
|
-
if (columns.includes(parameter)) {
|
|
31197
|
-
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with column "${parameter}" which was ambiguously defined as both a column and parameter`);
|
|
31198
|
-
}
|
|
31199
|
-
}
|
|
31200
|
-
let safeIntegers = 2;
|
|
31201
|
-
if (hasOwnProperty.call(def, "safeIntegers")) {
|
|
31202
|
-
const bool = def.safeIntegers;
|
|
31203
|
-
if (typeof bool !== "boolean") {
|
|
31204
|
-
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "safeIntegers" property (should be a boolean)`);
|
|
31205
|
-
}
|
|
31206
|
-
safeIntegers = +bool;
|
|
31207
|
-
}
|
|
31208
|
-
let directOnly = false;
|
|
31209
|
-
if (hasOwnProperty.call(def, "directOnly")) {
|
|
31210
|
-
directOnly = def.directOnly;
|
|
31211
|
-
if (typeof directOnly !== "boolean") {
|
|
31212
|
-
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "directOnly" property (should be a boolean)`);
|
|
31213
|
-
}
|
|
31214
|
-
}
|
|
31215
|
-
const columnDefinitions = [
|
|
31216
|
-
...parameters.map(identifier).map((str) => `${str} HIDDEN`),
|
|
31217
|
-
...columns.map(identifier)
|
|
31218
|
-
];
|
|
31219
|
-
return [
|
|
31220
|
-
`CREATE TABLE x(${columnDefinitions.join(", ")});`,
|
|
31221
|
-
wrapGenerator(rows, new Map(columns.map((x, i) => [x, parameters.length + i])), moduleName),
|
|
31222
|
-
parameters,
|
|
31223
|
-
safeIntegers,
|
|
31224
|
-
directOnly
|
|
31225
|
-
];
|
|
31226
|
-
}
|
|
31227
|
-
function wrapGenerator(generator, columnMap, moduleName) {
|
|
31228
|
-
return function* virtualTable(...args) {
|
|
31229
|
-
const output = args.map((x) => Buffer.isBuffer(x) ? Buffer.from(x) : x);
|
|
31230
|
-
for (let i = 0; i < columnMap.size; ++i) {
|
|
31231
|
-
output.push(null);
|
|
31232
|
-
}
|
|
31233
|
-
for (const row of generator(...args)) {
|
|
31234
|
-
if (Array.isArray(row)) {
|
|
31235
|
-
extractRowArray(row, output, columnMap.size, moduleName);
|
|
31236
|
-
yield output;
|
|
31237
|
-
} else if (typeof row === "object" && row !== null) {
|
|
31238
|
-
extractRowObject(row, output, columnMap, moduleName);
|
|
31239
|
-
yield output;
|
|
31240
|
-
} else {
|
|
31241
|
-
throw new TypeError(`Virtual table module "${moduleName}" yielded something that isn't a valid row object`);
|
|
31242
|
-
}
|
|
31243
|
-
}
|
|
31244
|
-
};
|
|
31245
|
-
}
|
|
31246
|
-
function extractRowArray(row, output, columnCount, moduleName) {
|
|
31247
|
-
if (row.length !== columnCount) {
|
|
31248
|
-
throw new TypeError(`Virtual table module "${moduleName}" yielded a row with an incorrect number of columns`);
|
|
31249
|
-
}
|
|
31250
|
-
const offset = output.length - columnCount;
|
|
31251
|
-
for (let i = 0; i < columnCount; ++i) {
|
|
31252
|
-
output[i + offset] = row[i];
|
|
31253
|
-
}
|
|
31254
|
-
}
|
|
31255
|
-
function extractRowObject(row, output, columnMap, moduleName) {
|
|
31256
|
-
let count = 0;
|
|
31257
|
-
for (const key of Object.keys(row)) {
|
|
31258
|
-
const index4 = columnMap.get(key);
|
|
31259
|
-
if (index4 === void 0) {
|
|
31260
|
-
throw new TypeError(`Virtual table module "${moduleName}" yielded a row with an undeclared column "${key}"`);
|
|
31261
|
-
}
|
|
31262
|
-
output[index4] = row[key];
|
|
31263
|
-
count += 1;
|
|
31264
|
-
}
|
|
31265
|
-
if (count !== columnMap.size) {
|
|
31266
|
-
throw new TypeError(`Virtual table module "${moduleName}" yielded a row with missing columns`);
|
|
31267
|
-
}
|
|
31268
|
-
}
|
|
31269
|
-
function inferParameters({ length }) {
|
|
31270
|
-
if (!Number.isInteger(length) || length < 0) {
|
|
31271
|
-
throw new TypeError("Expected function.length to be a positive integer");
|
|
31272
|
-
}
|
|
31273
|
-
const params = [];
|
|
31274
|
-
for (let i = 0; i < length; ++i) {
|
|
31275
|
-
params.push(`$${i + 1}`);
|
|
31276
|
-
}
|
|
31277
|
-
return params;
|
|
31278
|
-
}
|
|
31279
|
-
var { hasOwnProperty } = Object.prototype;
|
|
31280
|
-
var { apply } = Function.prototype;
|
|
31281
|
-
var GeneratorFunctionPrototype = Object.getPrototypeOf(function* () {
|
|
31282
|
-
});
|
|
31283
|
-
var identifier = (str) => `"${str.replace(/"/g, '""')}"`;
|
|
31284
|
-
var defer = (x) => () => x;
|
|
31285
|
-
}
|
|
31286
|
-
});
|
|
31287
|
-
|
|
31288
|
-
// node_modules/.pnpm/better-sqlite3@8.4.0/node_modules/better-sqlite3/lib/methods/inspect.js
|
|
31289
|
-
var require_inspect = __commonJS({
|
|
31290
|
-
"node_modules/.pnpm/better-sqlite3@8.4.0/node_modules/better-sqlite3/lib/methods/inspect.js"(exports, module2) {
|
|
31291
|
-
"use strict";
|
|
31292
|
-
var DatabaseInspection = function Database3() {
|
|
31293
|
-
};
|
|
31294
|
-
module2.exports = function inspect(depth, opts) {
|
|
31295
|
-
return Object.assign(new DatabaseInspection(), this);
|
|
31296
|
-
};
|
|
31297
|
-
}
|
|
31298
|
-
});
|
|
31299
|
-
|
|
31300
|
-
// node_modules/.pnpm/better-sqlite3@8.4.0/node_modules/better-sqlite3/lib/database.js
|
|
31301
|
-
var require_database = __commonJS({
|
|
31302
|
-
"node_modules/.pnpm/better-sqlite3@8.4.0/node_modules/better-sqlite3/lib/database.js"(exports, module2) {
|
|
31303
|
-
"use strict";
|
|
31304
|
-
var fs6 = require("fs");
|
|
31305
|
-
var path3 = require("path");
|
|
31306
|
-
var util2 = require_util();
|
|
31307
|
-
var SqliteError = require_sqlite_error();
|
|
31308
|
-
var DEFAULT_ADDON;
|
|
31309
|
-
function Database3(filenameGiven, options) {
|
|
31310
|
-
if (new.target == null) {
|
|
31311
|
-
return new Database3(filenameGiven, options);
|
|
31312
|
-
}
|
|
31313
|
-
let buffer;
|
|
31314
|
-
if (Buffer.isBuffer(filenameGiven)) {
|
|
31315
|
-
buffer = filenameGiven;
|
|
31316
|
-
filenameGiven = ":memory:";
|
|
31317
|
-
}
|
|
31318
|
-
if (filenameGiven == null)
|
|
31319
|
-
filenameGiven = "";
|
|
31320
|
-
if (options == null)
|
|
31321
|
-
options = {};
|
|
31322
|
-
if (typeof filenameGiven !== "string")
|
|
31323
|
-
throw new TypeError("Expected first argument to be a string");
|
|
31324
|
-
if (typeof options !== "object")
|
|
31325
|
-
throw new TypeError("Expected second argument to be an options object");
|
|
31326
|
-
if ("readOnly" in options)
|
|
31327
|
-
throw new TypeError('Misspelled option "readOnly" should be "readonly"');
|
|
31328
|
-
if ("memory" in options)
|
|
31329
|
-
throw new TypeError('Option "memory" was removed in v7.0.0 (use ":memory:" filename instead)');
|
|
31330
|
-
const filename = filenameGiven.trim();
|
|
31331
|
-
const anonymous = filename === "" || filename === ":memory:";
|
|
31332
|
-
const readonly = util2.getBooleanOption(options, "readonly");
|
|
31333
|
-
const fileMustExist = util2.getBooleanOption(options, "fileMustExist");
|
|
31334
|
-
const timeout = "timeout" in options ? options.timeout : 5e3;
|
|
31335
|
-
const verbose = "verbose" in options ? options.verbose : null;
|
|
31336
|
-
const nativeBindingPath = "nativeBinding" in options ? options.nativeBinding : null;
|
|
31337
|
-
if (readonly && anonymous && !buffer)
|
|
31338
|
-
throw new TypeError("In-memory/temporary databases cannot be readonly");
|
|
31339
|
-
if (!Number.isInteger(timeout) || timeout < 0)
|
|
31340
|
-
throw new TypeError('Expected the "timeout" option to be a positive integer');
|
|
31341
|
-
if (timeout > 2147483647)
|
|
31342
|
-
throw new RangeError('Option "timeout" cannot be greater than 2147483647');
|
|
31343
|
-
if (verbose != null && typeof verbose !== "function")
|
|
31344
|
-
throw new TypeError('Expected the "verbose" option to be a function');
|
|
31345
|
-
if (nativeBindingPath != null && typeof nativeBindingPath !== "string")
|
|
31346
|
-
throw new TypeError('Expected the "nativeBinding" option to be a string');
|
|
31347
|
-
let addon;
|
|
31348
|
-
if (nativeBindingPath == null) {
|
|
31349
|
-
addon = DEFAULT_ADDON || (DEFAULT_ADDON = require_bindings()("better_sqlite3.node"));
|
|
31350
|
-
} else {
|
|
31351
|
-
addon = require(path3.resolve(nativeBindingPath).replace(/(\.node)?$/, ".node"));
|
|
31352
|
-
}
|
|
31353
|
-
if (!addon.isInitialized) {
|
|
31354
|
-
addon.setErrorConstructor(SqliteError);
|
|
31355
|
-
addon.isInitialized = true;
|
|
31356
|
-
}
|
|
31357
|
-
if (!anonymous && !fs6.existsSync(path3.dirname(filename))) {
|
|
31358
|
-
throw new TypeError("Cannot open database because the directory does not exist");
|
|
31359
|
-
}
|
|
31360
|
-
Object.defineProperties(this, {
|
|
31361
|
-
[util2.cppdb]: { value: new addon.Database(filename, filenameGiven, anonymous, readonly, fileMustExist, timeout, verbose || null, buffer || null) },
|
|
31362
|
-
...wrappers.getters
|
|
31363
|
-
});
|
|
31364
|
-
}
|
|
31365
|
-
var wrappers = require_wrappers();
|
|
31366
|
-
Database3.prototype.prepare = wrappers.prepare;
|
|
31367
|
-
Database3.prototype.transaction = require_transaction();
|
|
31368
|
-
Database3.prototype.pragma = require_pragma();
|
|
31369
|
-
Database3.prototype.backup = require_backup();
|
|
31370
|
-
Database3.prototype.serialize = require_serialize();
|
|
31371
|
-
Database3.prototype.function = require_function();
|
|
31372
|
-
Database3.prototype.aggregate = require_aggregate();
|
|
31373
|
-
Database3.prototype.table = require_table();
|
|
31374
|
-
Database3.prototype.loadExtension = wrappers.loadExtension;
|
|
31375
|
-
Database3.prototype.exec = wrappers.exec;
|
|
31376
|
-
Database3.prototype.close = wrappers.close;
|
|
31377
|
-
Database3.prototype.defaultSafeIntegers = wrappers.defaultSafeIntegers;
|
|
31378
|
-
Database3.prototype.unsafeMode = wrappers.unsafeMode;
|
|
31379
|
-
Database3.prototype[util2.inspect] = require_inspect();
|
|
31380
|
-
module2.exports = Database3;
|
|
31381
|
-
}
|
|
31382
|
-
});
|
|
31383
|
-
|
|
31384
|
-
// node_modules/.pnpm/better-sqlite3@8.4.0/node_modules/better-sqlite3/lib/index.js
|
|
31385
|
-
var require_lib2 = __commonJS({
|
|
31386
|
-
"node_modules/.pnpm/better-sqlite3@8.4.0/node_modules/better-sqlite3/lib/index.js"(exports, module2) {
|
|
31387
|
-
"use strict";
|
|
31388
|
-
module2.exports = require_database();
|
|
31389
|
-
module2.exports.SqliteError = require_sqlite_error();
|
|
31390
|
-
}
|
|
31391
|
-
});
|
|
31392
|
-
|
|
31393
30645
|
// src/sqlite-introspect.ts
|
|
31394
|
-
var sqliteImportsList, indexName3, objToStatement22, relations2, schemaToTypeScript2, isCyclic2, isSelf2, mapColumnDefault2, column5, createTableColumns2, createTableIndexes2, createTablePKs2, createTableFKs2;
|
|
30646
|
+
var sqliteImportsList, indexName3, objToStatement22, relations2, withCasing2, schemaToTypeScript2, isCyclic2, isSelf2, mapColumnDefault2, column5, createTableColumns2, createTableIndexes2, createTablePKs2, createTableFKs2;
|
|
31395
30647
|
var init_sqlite_introspect = __esm({
|
|
31396
30648
|
"src/sqlite-introspect.ts"() {
|
|
31397
30649
|
init_utils2();
|
|
@@ -31417,7 +30669,16 @@ var init_sqlite_introspect = __esm({
|
|
|
31417
30669
|
return statement;
|
|
31418
30670
|
};
|
|
31419
30671
|
relations2 = /* @__PURE__ */ new Set();
|
|
31420
|
-
|
|
30672
|
+
withCasing2 = (value, casing) => {
|
|
30673
|
+
if (typeof casing === "undefined") {
|
|
30674
|
+
return value;
|
|
30675
|
+
}
|
|
30676
|
+
if (casing === "camel") {
|
|
30677
|
+
return value.camelCase();
|
|
30678
|
+
}
|
|
30679
|
+
return value;
|
|
30680
|
+
};
|
|
30681
|
+
schemaToTypeScript2 = (schema4, casing) => {
|
|
31421
30682
|
Object.values(schema4.tables).forEach((table4) => {
|
|
31422
30683
|
Object.values(table4.foreignKeys).forEach((fk4) => {
|
|
31423
30684
|
const relation = `${fk4.tableFrom}-${fk4.tableTo}`;
|
|
@@ -31449,16 +30710,20 @@ var init_sqlite_introspect = __esm({
|
|
|
31449
30710
|
const tableStatements = Object.values(schema4.tables).map((table4) => {
|
|
31450
30711
|
const func = "sqliteTable";
|
|
31451
30712
|
let statement = "";
|
|
31452
|
-
if (imports.sqlite.includes(table4.name
|
|
31453
|
-
statement = `// Table name is in conflict with ${
|
|
30713
|
+
if (imports.sqlite.includes(withCasing2(table4.name, casing))) {
|
|
30714
|
+
statement = `// Table name is in conflict with ${withCasing2(
|
|
30715
|
+
table4.name,
|
|
30716
|
+
casing
|
|
30717
|
+
)} import.
|
|
31454
30718
|
// Please change to any other name, that is not in imports list
|
|
31455
30719
|
`;
|
|
31456
30720
|
}
|
|
31457
|
-
statement += `export const ${table4.name
|
|
30721
|
+
statement += `export const ${withCasing2(table4.name, casing)} = ${func}("${table4.name}", {
|
|
31458
30722
|
`;
|
|
31459
30723
|
statement += createTableColumns2(
|
|
31460
30724
|
Object.values(table4.columns),
|
|
31461
|
-
Object.values(table4.foreignKeys)
|
|
30725
|
+
Object.values(table4.foreignKeys),
|
|
30726
|
+
casing
|
|
31462
30727
|
);
|
|
31463
30728
|
statement += "}";
|
|
31464
30729
|
const filteredFKs = Object.values(table4.foreignKeys).filter((it) => {
|
|
@@ -31468,9 +30733,16 @@ var init_sqlite_introspect = __esm({
|
|
|
31468
30733
|
statement += ",\n";
|
|
31469
30734
|
statement += "(table) => {\n";
|
|
31470
30735
|
statement += " return {\n";
|
|
31471
|
-
statement += createTableIndexes2(
|
|
31472
|
-
|
|
31473
|
-
|
|
30736
|
+
statement += createTableIndexes2(
|
|
30737
|
+
table4.name,
|
|
30738
|
+
Object.values(table4.indexes),
|
|
30739
|
+
casing
|
|
30740
|
+
);
|
|
30741
|
+
statement += createTableFKs2(Object.values(filteredFKs), casing);
|
|
30742
|
+
statement += createTablePKs2(
|
|
30743
|
+
Object.values(table4.compositePrimaryKeys),
|
|
30744
|
+
casing
|
|
30745
|
+
);
|
|
31474
30746
|
statement += " }\n";
|
|
31475
30747
|
statement += "}";
|
|
31476
30748
|
}
|
|
@@ -31506,37 +30778,37 @@ import { sql } from "drizzle-orm"
|
|
|
31506
30778
|
}
|
|
31507
30779
|
return defaultValue;
|
|
31508
30780
|
};
|
|
31509
|
-
column5 = (type, name, defaultValue, autoincrement,
|
|
30781
|
+
column5 = (type, name, defaultValue, autoincrement, casing) => {
|
|
31510
30782
|
let lowered = type;
|
|
31511
30783
|
if (lowered.startsWith("integer")) {
|
|
31512
|
-
let out = `${name
|
|
30784
|
+
let out = `${withCasing2(name, casing)}: integer("${name}")`;
|
|
31513
30785
|
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault2(defaultValue)})` : "";
|
|
31514
30786
|
return out;
|
|
31515
30787
|
}
|
|
31516
30788
|
if (lowered === "real") {
|
|
31517
|
-
let out = `${name
|
|
30789
|
+
let out = `${withCasing2(name, casing)}: real("${name}")`;
|
|
31518
30790
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue)})` : "";
|
|
31519
30791
|
return out;
|
|
31520
30792
|
}
|
|
31521
30793
|
if (lowered === "text") {
|
|
31522
|
-
let out = `${name
|
|
30794
|
+
let out = `${withCasing2(name, casing)}: text("${name}")`;
|
|
31523
30795
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue)})` : "";
|
|
31524
30796
|
return out;
|
|
31525
30797
|
}
|
|
31526
30798
|
if (lowered === "blob") {
|
|
31527
|
-
let out = `${name
|
|
30799
|
+
let out = `${withCasing2(name, casing)}: blob("${name}")`;
|
|
31528
30800
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue)})` : "";
|
|
31529
30801
|
return out;
|
|
31530
30802
|
}
|
|
31531
30803
|
if (lowered === "numeric") {
|
|
31532
|
-
let out = `${name
|
|
30804
|
+
let out = `${withCasing2(name, casing)}: numeric("${name}")`;
|
|
31533
30805
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue)})` : "";
|
|
31534
30806
|
return out;
|
|
31535
30807
|
}
|
|
31536
30808
|
return `// Warning: Can't parse ${type} from database
|
|
31537
30809
|
// ${type}Type: ${type}("${name}")`;
|
|
31538
30810
|
};
|
|
31539
|
-
createTableColumns2 = (columns, fks) => {
|
|
30811
|
+
createTableColumns2 = (columns, fks, casing) => {
|
|
31540
30812
|
let statement = "";
|
|
31541
30813
|
const oneColumnsFKs = Object.values(fks).filter((it) => {
|
|
31542
30814
|
return !isSelf2(it);
|
|
@@ -31549,7 +30821,7 @@ import { sql } from "drizzle-orm"
|
|
|
31549
30821
|
}, {});
|
|
31550
30822
|
columns.forEach((it) => {
|
|
31551
30823
|
statement += " ";
|
|
31552
|
-
statement += column5(it.type, it.name, it.default, it.autoincrement);
|
|
30824
|
+
statement += column5(it.type, it.name, it.default, it.autoincrement, casing);
|
|
31553
30825
|
statement += it.primaryKey ? `.primaryKey(${it.autoincrement ? "{ autoIncrement: true }" : ""})` : "";
|
|
31554
30826
|
statement += it.notNull ? ".notNull()" : "";
|
|
31555
30827
|
const fks2 = fkByColumnName[it.name];
|
|
@@ -31561,9 +30833,15 @@ import { sql } from "drizzle-orm"
|
|
|
31561
30833
|
const typeSuffix = isCyclic2(it2) ? ": AnySQLiteColumn" : "";
|
|
31562
30834
|
const paramsStr = objToStatement22(params);
|
|
31563
30835
|
if (paramsStr) {
|
|
31564
|
-
return `.references(()${typeSuffix} => ${
|
|
31565
|
-
|
|
31566
|
-
|
|
30836
|
+
return `.references(()${typeSuffix} => ${withCasing2(
|
|
30837
|
+
it2.tableTo,
|
|
30838
|
+
casing
|
|
30839
|
+
)}.${withCasing2(it2.columnsTo[0], casing)}, ${paramsStr} )`;
|
|
30840
|
+
}
|
|
30841
|
+
return `.references(()${typeSuffix} => ${withCasing2(
|
|
30842
|
+
it2.tableTo,
|
|
30843
|
+
casing
|
|
30844
|
+
)}.${withCasing2(it2.columnsTo[0], casing)})`;
|
|
31567
30845
|
}).join("");
|
|
31568
30846
|
statement += fksStatement;
|
|
31569
30847
|
}
|
|
@@ -31571,30 +30849,30 @@ import { sql } from "drizzle-orm"
|
|
|
31571
30849
|
});
|
|
31572
30850
|
return statement;
|
|
31573
30851
|
};
|
|
31574
|
-
createTableIndexes2 = (tableName, idxs) => {
|
|
30852
|
+
createTableIndexes2 = (tableName, idxs, casing) => {
|
|
31575
30853
|
let statement = "";
|
|
31576
30854
|
idxs.forEach((it) => {
|
|
31577
30855
|
let idxKey = it.name.startsWith(tableName) && it.name !== tableName ? it.name.slice(tableName.length + 1) : it.name;
|
|
31578
30856
|
idxKey = idxKey.endsWith("_index") ? idxKey.slice(0, -"_index".length) + "_idx" : idxKey;
|
|
31579
|
-
idxKey = idxKey
|
|
30857
|
+
idxKey = withCasing2(idxKey, casing);
|
|
31580
30858
|
const indexGeneratedName = indexName3(tableName, it.columns);
|
|
31581
30859
|
const escapedIndexName = indexGeneratedName === it.name ? "" : `"${it.name}"`;
|
|
31582
30860
|
statement += ` ${idxKey}: `;
|
|
31583
30861
|
statement += it.isUnique ? "uniqueIndex(" : "index(";
|
|
31584
30862
|
statement += `${escapedIndexName})`;
|
|
31585
|
-
statement += `.on(${it.columns.map((it2) => `table.${it2
|
|
30863
|
+
statement += `.on(${it.columns.map((it2) => `table.${withCasing2(it2, casing)}`).join(", ")}),`;
|
|
31586
30864
|
statement += `
|
|
31587
30865
|
`;
|
|
31588
30866
|
});
|
|
31589
30867
|
return statement;
|
|
31590
30868
|
};
|
|
31591
|
-
createTablePKs2 = (pks) => {
|
|
30869
|
+
createTablePKs2 = (pks, casing) => {
|
|
31592
30870
|
let statement = "";
|
|
31593
30871
|
pks.forEach((it, i) => {
|
|
31594
30872
|
statement += ` pk${i}: `;
|
|
31595
30873
|
statement += "primaryKey(";
|
|
31596
30874
|
statement += `${it.columns.map((c) => {
|
|
31597
|
-
return `table.${c
|
|
30875
|
+
return `table.${withCasing2(c, casing)}`;
|
|
31598
30876
|
}).join(", ")}`;
|
|
31599
30877
|
statement += ")";
|
|
31600
30878
|
statement += `
|
|
@@ -31602,16 +30880,16 @@ import { sql } from "drizzle-orm"
|
|
|
31602
30880
|
});
|
|
31603
30881
|
return statement;
|
|
31604
30882
|
};
|
|
31605
|
-
createTableFKs2 = (fks) => {
|
|
30883
|
+
createTableFKs2 = (fks, casing) => {
|
|
31606
30884
|
let statement = "";
|
|
31607
30885
|
fks.forEach((it) => {
|
|
31608
30886
|
const isSelf4 = it.tableTo === it.tableFrom;
|
|
31609
|
-
const tableTo = isSelf4 ? "table" : `${it.tableTo
|
|
31610
|
-
statement += ` ${it.name
|
|
30887
|
+
const tableTo = isSelf4 ? "table" : `${withCasing2(it.tableTo, casing)}`;
|
|
30888
|
+
statement += ` ${withCasing2(it.name, casing)}: foreignKey(() => ({
|
|
31611
30889
|
`;
|
|
31612
|
-
statement += ` columns: [${it.columnsFrom.map((i) => `table.${i
|
|
30890
|
+
statement += ` columns: [${it.columnsFrom.map((i) => `table.${withCasing2(i, casing)}`).join(", ")}],
|
|
31613
30891
|
`;
|
|
31614
|
-
statement += ` foreignColumns: [${it.columnsTo.map((i) => `${tableTo}.${i
|
|
30892
|
+
statement += ` foreignColumns: [${it.columnsTo.map((i) => `${tableTo}.${withCasing2(i, casing)}`).join(", ")}]
|
|
31615
30893
|
`;
|
|
31616
30894
|
statement += ` }))`;
|
|
31617
30895
|
statement += it.onUpdate && it.onUpdate !== "no action" ? `.onUpdate("${it.onUpdate}")` : "";
|
|
@@ -31901,7 +31179,7 @@ function valueToSql(value) {
|
|
|
31901
31179
|
var import_better_sqlite3, import_node_buffer, Sqlite3Client, Sqlite3Transaction;
|
|
31902
31180
|
var init_sqlite3 = __esm({
|
|
31903
31181
|
"node_modules/.pnpm/@libsql+client@0.1.6/node_modules/@libsql/client/lib-esm/sqlite3.js"() {
|
|
31904
|
-
import_better_sqlite3 = __toESM(
|
|
31182
|
+
import_better_sqlite3 = __toESM(require("better-sqlite3"), 1);
|
|
31905
31183
|
import_node_buffer = require("node:buffer");
|
|
31906
31184
|
init_api();
|
|
31907
31185
|
init_config();
|
|
@@ -36962,7 +36240,7 @@ var init_hrana = __esm({
|
|
|
36962
36240
|
});
|
|
36963
36241
|
|
|
36964
36242
|
// node_modules/.pnpm/webidl-conversions@3.0.1/node_modules/webidl-conversions/lib/index.js
|
|
36965
|
-
var
|
|
36243
|
+
var require_lib2 = __commonJS({
|
|
36966
36244
|
"node_modules/.pnpm/webidl-conversions@3.0.1/node_modules/webidl-conversions/lib/index.js"(exports, module2) {
|
|
36967
36245
|
"use strict";
|
|
36968
36246
|
var conversions = {};
|
|
@@ -38541,7 +37819,7 @@ var require_URL_impl = __commonJS({
|
|
|
38541
37819
|
var require_URL = __commonJS({
|
|
38542
37820
|
"node_modules/.pnpm/whatwg-url@5.0.0/node_modules/whatwg-url/lib/URL.js"(exports, module2) {
|
|
38543
37821
|
"use strict";
|
|
38544
|
-
var conversions =
|
|
37822
|
+
var conversions = require_lib2();
|
|
38545
37823
|
var utils = require_utils2();
|
|
38546
37824
|
var Impl = require_URL_impl();
|
|
38547
37825
|
var impl = utils.implSymbol;
|
|
@@ -38737,7 +38015,7 @@ var require_public_api = __commonJS({
|
|
|
38737
38015
|
});
|
|
38738
38016
|
|
|
38739
38017
|
// node_modules/.pnpm/node-fetch@2.6.11/node_modules/node-fetch/lib/index.js
|
|
38740
|
-
var
|
|
38018
|
+
var require_lib3 = __commonJS({
|
|
38741
38019
|
"node_modules/.pnpm/node-fetch@2.6.11/node_modules/node-fetch/lib/index.js"(exports, module2) {
|
|
38742
38020
|
"use strict";
|
|
38743
38021
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -39989,7 +39267,7 @@ var require_lib4 = __commonJS({
|
|
|
39989
39267
|
var import_node_fetch, Request, Response, Headers;
|
|
39990
39268
|
var init_node2 = __esm({
|
|
39991
39269
|
"node_modules/.pnpm/@libsql+isomorphic-fetch@0.1.1/node_modules/@libsql/isomorphic-fetch/node.mjs"() {
|
|
39992
|
-
import_node_fetch = __toESM(
|
|
39270
|
+
import_node_fetch = __toESM(require_lib3(), 1);
|
|
39993
39271
|
({ Request, Response, Headers } = import_node_fetch.default);
|
|
39994
39272
|
}
|
|
39995
39273
|
});
|
|
@@ -40169,15 +39447,16 @@ __export(sqliteIntrospect_exports, {
|
|
|
40169
39447
|
sqliteIntrospect: () => sqliteIntrospect,
|
|
40170
39448
|
sqlitePushIntrospect: () => sqlitePushIntrospect
|
|
40171
39449
|
});
|
|
40172
|
-
var
|
|
39450
|
+
var import_hanji6, SqliteClient, BetterSqlite, TursoSqlite, connectToSQLite, sqliteIntrospect, sqlitePushIntrospect;
|
|
40173
39451
|
var init_sqliteIntrospect = __esm({
|
|
40174
39452
|
"src/cli/commands/sqliteIntrospect.ts"() {
|
|
39453
|
+
init_views();
|
|
40175
39454
|
init_global();
|
|
40176
|
-
import_better_sqlite32 = __toESM(require_lib2());
|
|
40177
39455
|
init_sqliteSerializer();
|
|
40178
39456
|
init_sqlite_introspect();
|
|
40179
39457
|
init_mjs();
|
|
40180
39458
|
init_lib_esm2();
|
|
39459
|
+
import_hanji6 = __toESM(require_hanji());
|
|
40181
39460
|
SqliteClient = class {
|
|
40182
39461
|
constructor(db) {
|
|
40183
39462
|
this.db = db;
|
|
@@ -40202,8 +39481,9 @@ var init_sqliteIntrospect = __esm({
|
|
|
40202
39481
|
};
|
|
40203
39482
|
connectToSQLite = async (config) => {
|
|
40204
39483
|
if (config.driver === "better-sqlite") {
|
|
39484
|
+
const { default: Database2 } = await import("better-sqlite3");
|
|
40205
39485
|
return {
|
|
40206
|
-
client: new BetterSqlite(new
|
|
39486
|
+
client: new BetterSqlite(new Database2(config.dbCredentials.url))
|
|
40207
39487
|
};
|
|
40208
39488
|
}
|
|
40209
39489
|
if (config.driver === "libsql") {
|
|
@@ -40226,11 +39506,34 @@ var init_sqliteIntrospect = __esm({
|
|
|
40226
39506
|
}
|
|
40227
39507
|
return {};
|
|
40228
39508
|
};
|
|
40229
|
-
sqliteIntrospect = async (config) => {
|
|
39509
|
+
sqliteIntrospect = async (config, filters) => {
|
|
40230
39510
|
const { client } = await connectToSQLite(config);
|
|
40231
|
-
const
|
|
39511
|
+
const matchers = filters.map((it) => {
|
|
39512
|
+
return new Minimatch(it);
|
|
39513
|
+
});
|
|
39514
|
+
const filter2 = (tableName) => {
|
|
39515
|
+
if (matchers.length === 0)
|
|
39516
|
+
return true;
|
|
39517
|
+
for (let i = 0; i < matchers.length; i++) {
|
|
39518
|
+
const matcher = matchers[i];
|
|
39519
|
+
if (matcher.match(tableName))
|
|
39520
|
+
return true;
|
|
39521
|
+
}
|
|
39522
|
+
return false;
|
|
39523
|
+
};
|
|
39524
|
+
const progress = new IntrospectProgress();
|
|
39525
|
+
const res = await (0, import_hanji6.renderWithTask)(
|
|
39526
|
+
progress,
|
|
39527
|
+
fromDatabase3(
|
|
39528
|
+
client,
|
|
39529
|
+
filter2,
|
|
39530
|
+
(stage, count, status) => {
|
|
39531
|
+
progress.update(stage, count, status);
|
|
39532
|
+
}
|
|
39533
|
+
)
|
|
39534
|
+
);
|
|
40232
39535
|
const schema4 = { id: originUUID, prevId: "", ...res };
|
|
40233
|
-
const ts = schemaToTypeScript2(schema4);
|
|
39536
|
+
const ts = schemaToTypeScript2(schema4, config.introspect.casing);
|
|
40234
39537
|
return { schema: schema4, ts };
|
|
40235
39538
|
};
|
|
40236
39539
|
sqlitePushIntrospect = async (client, filters) => {
|
|
@@ -41838,7 +41141,7 @@ var require_helper = __commonJS({
|
|
|
41838
41141
|
});
|
|
41839
41142
|
|
|
41840
41143
|
// node_modules/.pnpm/pgpass@1.0.5/node_modules/pgpass/lib/index.js
|
|
41841
|
-
var
|
|
41144
|
+
var require_lib4 = __commonJS({
|
|
41842
41145
|
"node_modules/.pnpm/pgpass@1.0.5/node_modules/pgpass/lib/index.js"(exports, module2) {
|
|
41843
41146
|
"use strict";
|
|
41844
41147
|
var path3 = require("path");
|
|
@@ -41893,50 +41196,47 @@ var require_type_overrides = __commonJS({
|
|
|
41893
41196
|
}
|
|
41894
41197
|
});
|
|
41895
41198
|
|
|
41896
|
-
// node_modules/.pnpm/pg-connection-string@2.
|
|
41199
|
+
// node_modules/.pnpm/pg-connection-string@2.6.0/node_modules/pg-connection-string/index.js
|
|
41897
41200
|
var require_pg_connection_string = __commonJS({
|
|
41898
|
-
"node_modules/.pnpm/pg-connection-string@2.
|
|
41201
|
+
"node_modules/.pnpm/pg-connection-string@2.6.0/node_modules/pg-connection-string/index.js"(exports, module2) {
|
|
41899
41202
|
"use strict";
|
|
41900
|
-
var url = require("url");
|
|
41901
|
-
var fs6 = require("fs");
|
|
41902
41203
|
function parse(str) {
|
|
41903
41204
|
if (str.charAt(0) === "/") {
|
|
41904
|
-
|
|
41905
|
-
return { host:
|
|
41205
|
+
const config2 = str.split(" ");
|
|
41206
|
+
return { host: config2[0], database: config2[1] };
|
|
41906
41207
|
}
|
|
41907
|
-
|
|
41908
|
-
|
|
41909
|
-
|
|
41910
|
-
)
|
|
41911
|
-
|
|
41912
|
-
|
|
41913
|
-
|
|
41914
|
-
|
|
41915
|
-
|
|
41208
|
+
const config = {};
|
|
41209
|
+
let result;
|
|
41210
|
+
let dummyHost = false;
|
|
41211
|
+
if (/ |%[^a-f0-9]|%[a-f0-9][^a-f0-9]/i.test(str)) {
|
|
41212
|
+
str = encodeURI(str).replace(/\%25(\d\d)/g, "%$1");
|
|
41213
|
+
}
|
|
41214
|
+
try {
|
|
41215
|
+
result = new URL(str, "postgres://base");
|
|
41216
|
+
} catch (e) {
|
|
41217
|
+
result = new URL(str.replace("@/", "@___DUMMY___/"), "postgres://base");
|
|
41218
|
+
dummyHost = true;
|
|
41219
|
+
}
|
|
41220
|
+
for (const entry of result.searchParams.entries()) {
|
|
41221
|
+
config[entry[0]] = entry[1];
|
|
41916
41222
|
}
|
|
41917
|
-
|
|
41918
|
-
config.
|
|
41919
|
-
config.password = auth.splice(1).join(":");
|
|
41223
|
+
config.user = config.user || decodeURIComponent(result.username);
|
|
41224
|
+
config.password = config.password || decodeURIComponent(result.password);
|
|
41920
41225
|
config.port = result.port;
|
|
41921
41226
|
if (result.protocol == "socket:") {
|
|
41922
41227
|
config.host = decodeURI(result.pathname);
|
|
41923
|
-
config.database = result.
|
|
41924
|
-
config.client_encoding = result.
|
|
41228
|
+
config.database = result.searchParams.get("db");
|
|
41229
|
+
config.client_encoding = result.searchParams.get("encoding");
|
|
41925
41230
|
return config;
|
|
41926
41231
|
}
|
|
41232
|
+
const hostname = dummyHost ? "" : result.hostname;
|
|
41927
41233
|
if (!config.host) {
|
|
41928
|
-
config.host =
|
|
41929
|
-
}
|
|
41930
|
-
|
|
41931
|
-
if (!config.host && pathname && /^%2f/i.test(pathname)) {
|
|
41932
|
-
var pathnameSplit = pathname.split("/");
|
|
41933
|
-
config.host = decodeURIComponent(pathnameSplit[0]);
|
|
41934
|
-
pathname = pathnameSplit.splice(1).join("/");
|
|
41234
|
+
config.host = decodeURIComponent(hostname);
|
|
41235
|
+
} else if (hostname) {
|
|
41236
|
+
result.pathname = hostname + result.pathname;
|
|
41935
41237
|
}
|
|
41936
|
-
|
|
41937
|
-
|
|
41938
|
-
}
|
|
41939
|
-
config.database = pathname && decodeURI(pathname);
|
|
41238
|
+
const pathname = result.pathname.slice(1) || null;
|
|
41239
|
+
config.database = pathname ? decodeURI(pathname) : null;
|
|
41940
41240
|
if (config.ssl === "true" || config.ssl === "1") {
|
|
41941
41241
|
config.ssl = true;
|
|
41942
41242
|
}
|
|
@@ -41946,6 +41246,7 @@ var require_pg_connection_string = __commonJS({
|
|
|
41946
41246
|
if (config.sslcert || config.sslkey || config.sslrootcert || config.sslmode) {
|
|
41947
41247
|
config.ssl = {};
|
|
41948
41248
|
}
|
|
41249
|
+
const fs6 = config.sslcert || config.sslkey || config.sslrootcert ? require("fs") : null;
|
|
41949
41250
|
if (config.sslcert) {
|
|
41950
41251
|
config.ssl.cert = fs6.readFileSync(config.sslcert).toString();
|
|
41951
41252
|
}
|
|
@@ -43424,7 +42725,7 @@ var require_client2 = __commonJS({
|
|
|
43424
42725
|
var util2 = require("util");
|
|
43425
42726
|
var utils = require_utils3();
|
|
43426
42727
|
var sasl = require_sasl();
|
|
43427
|
-
var pgPass =
|
|
42728
|
+
var pgPass = require_lib4();
|
|
43428
42729
|
var TypeOverrides = require_type_overrides();
|
|
43429
42730
|
var ConnectionParameters = require_connection_parameters();
|
|
43430
42731
|
var Query = require_query3();
|
|
@@ -43991,7 +43292,7 @@ var require_pg_pool = __commonJS({
|
|
|
43991
43292
|
this.options.maxLifetimeSeconds = this.options.maxLifetimeSeconds || 0;
|
|
43992
43293
|
this.log = this.options.log || function() {
|
|
43993
43294
|
};
|
|
43994
|
-
this.Client = this.options.Client || Client2 ||
|
|
43295
|
+
this.Client = this.options.Client || Client2 || require_lib5().Client;
|
|
43995
43296
|
this.Promise = this.options.Promise || global.Promise;
|
|
43996
43297
|
if (typeof this.options.idleTimeoutMillis === "undefined") {
|
|
43997
43298
|
this.options.idleTimeoutMillis = 1e4;
|
|
@@ -44743,7 +44044,7 @@ var require_native = __commonJS({
|
|
|
44743
44044
|
});
|
|
44744
44045
|
|
|
44745
44046
|
// node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/index.js
|
|
44746
|
-
var
|
|
44047
|
+
var require_lib5 = __commonJS({
|
|
44747
44048
|
"node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/index.js"(exports, module2) {
|
|
44748
44049
|
"use strict";
|
|
44749
44050
|
var Client2 = require_client2();
|
|
@@ -44795,7 +44096,7 @@ var require_lib6 = __commonJS({
|
|
|
44795
44096
|
});
|
|
44796
44097
|
|
|
44797
44098
|
// src/introspect.ts
|
|
44798
|
-
var pgImportsList, objToStatement23, timeConfig2, possibleIntervals, intervalStrToObj, intervalConfig, importsPatch2, relations3, schemaToTypeScript3, isCyclic3, isSelf3, column6, dimensionsInArray, createTableColumns3, createTableIndexes3, createTablePKs3, createTableFKs3;
|
|
44099
|
+
var pgImportsList, objToStatement23, timeConfig2, possibleIntervals, intervalStrToObj, intervalConfig, importsPatch2, relations3, withCasing3, schemaToTypeScript3, isCyclic3, isSelf3, column6, dimensionsInArray, createTableColumns3, createTableIndexes3, createTablePKs3, createTableFKs3;
|
|
44799
44100
|
var init_introspect = __esm({
|
|
44800
44101
|
"src/introspect.ts"() {
|
|
44801
44102
|
init_utils2();
|
|
@@ -44907,7 +44208,16 @@ var init_introspect = __esm({
|
|
|
44907
44208
|
"time with time zone": "time"
|
|
44908
44209
|
};
|
|
44909
44210
|
relations3 = /* @__PURE__ */ new Set();
|
|
44910
|
-
|
|
44211
|
+
withCasing3 = (value, casing) => {
|
|
44212
|
+
if (typeof casing === "undefined") {
|
|
44213
|
+
return value;
|
|
44214
|
+
}
|
|
44215
|
+
if (casing.casing === "camel") {
|
|
44216
|
+
return value.camelCase();
|
|
44217
|
+
}
|
|
44218
|
+
return value;
|
|
44219
|
+
};
|
|
44220
|
+
schemaToTypeScript3 = (schema4, casing) => {
|
|
44911
44221
|
Object.values(schema4.tables).forEach((table4) => {
|
|
44912
44222
|
Object.values(table4.foreignKeys).forEach((fk4) => {
|
|
44913
44223
|
const relation = `${fk4.tableFrom}-${fk4.tableTo}`;
|
|
@@ -44916,7 +44226,7 @@ var init_introspect = __esm({
|
|
|
44916
44226
|
});
|
|
44917
44227
|
const schemas = Object.fromEntries(
|
|
44918
44228
|
Object.entries(schema4.schemas).map((it) => {
|
|
44919
|
-
return [it[0], it[1]
|
|
44229
|
+
return [it[0], withCasing3(it[1], casing)];
|
|
44920
44230
|
})
|
|
44921
44231
|
);
|
|
44922
44232
|
const enumTypes = new Set(Object.values(schema4.enums).map((it) => it.name));
|
|
@@ -44950,7 +44260,7 @@ var init_introspect = __esm({
|
|
|
44950
44260
|
);
|
|
44951
44261
|
const enumStatements = Object.values(schema4.enums).map((it) => {
|
|
44952
44262
|
const values = Object.values(it.values).map((it2) => `'${it2}'`).join(", ");
|
|
44953
|
-
return `export const ${it.name
|
|
44263
|
+
return `export const ${withCasing3(it.name, casing)} = pgEnum("${it.name}", [${values}])
|
|
44954
44264
|
`;
|
|
44955
44265
|
}).join("").concat("\n");
|
|
44956
44266
|
const schemaStatements = Object.entries(schemas).map((it) => {
|
|
@@ -44960,12 +44270,16 @@ var init_introspect = __esm({
|
|
|
44960
44270
|
const tableStatements = Object.values(schema4.tables).map((table4) => {
|
|
44961
44271
|
const schema5 = schemas[table4.schema];
|
|
44962
44272
|
const func = schema5 ? schema5 : "pgTable";
|
|
44963
|
-
let statement = `export const ${
|
|
44273
|
+
let statement = `export const ${withCasing3(
|
|
44274
|
+
table4.name,
|
|
44275
|
+
casing
|
|
44276
|
+
)} = ${func}("${table4.name}", {
|
|
44964
44277
|
`;
|
|
44965
44278
|
statement += createTableColumns3(
|
|
44966
44279
|
Object.values(table4.columns),
|
|
44967
44280
|
Object.values(table4.foreignKeys),
|
|
44968
|
-
enumTypes
|
|
44281
|
+
enumTypes,
|
|
44282
|
+
casing
|
|
44969
44283
|
);
|
|
44970
44284
|
statement += "}";
|
|
44971
44285
|
const filteredFKs = Object.values(table4.foreignKeys).filter((it) => {
|
|
@@ -44975,9 +44289,16 @@ var init_introspect = __esm({
|
|
|
44975
44289
|
statement += ",\n";
|
|
44976
44290
|
statement += "(table) => {\n";
|
|
44977
44291
|
statement += " return {\n";
|
|
44978
|
-
statement += createTableIndexes3(
|
|
44979
|
-
|
|
44980
|
-
|
|
44292
|
+
statement += createTableIndexes3(
|
|
44293
|
+
table4.name,
|
|
44294
|
+
Object.values(table4.indexes),
|
|
44295
|
+
casing
|
|
44296
|
+
);
|
|
44297
|
+
statement += createTableFKs3(Object.values(filteredFKs), casing);
|
|
44298
|
+
statement += createTablePKs3(
|
|
44299
|
+
Object.values(table4.compositePrimaryKeys),
|
|
44300
|
+
casing
|
|
44301
|
+
);
|
|
44981
44302
|
statement += " }\n";
|
|
44982
44303
|
statement += "}";
|
|
44983
44304
|
}
|
|
@@ -45012,51 +44333,54 @@ var init_introspect = __esm({
|
|
|
45012
44333
|
isSelf3 = (fk4) => {
|
|
45013
44334
|
return fk4.tableFrom === fk4.tableTo;
|
|
45014
44335
|
};
|
|
45015
|
-
column6 = (type, name, enumTypes, defaultValue) => {
|
|
44336
|
+
column6 = (type, name, enumTypes, defaultValue, casing) => {
|
|
45016
44337
|
const lowered = type.toLowerCase();
|
|
45017
44338
|
if (lowered.startsWith("serial")) {
|
|
45018
|
-
return `${name
|
|
44339
|
+
return `${withCasing3(name, casing)}: serial("${name}")`;
|
|
45019
44340
|
}
|
|
45020
44341
|
if (lowered.startsWith("smallserial")) {
|
|
45021
|
-
return `${name
|
|
44342
|
+
return `${withCasing3(name, casing)}: smallserial("${name}")`;
|
|
45022
44343
|
}
|
|
45023
44344
|
if (lowered.startsWith("bigserial")) {
|
|
45024
|
-
return `${
|
|
44345
|
+
return `${withCasing3(
|
|
44346
|
+
name,
|
|
44347
|
+
casing
|
|
44348
|
+
)}: bigserial("${name}", { mode: "bigint" })`;
|
|
45025
44349
|
}
|
|
45026
44350
|
if (lowered.startsWith("integer")) {
|
|
45027
|
-
let out = `${name
|
|
44351
|
+
let out = `${withCasing3(name, casing)}: integer("${name}")`;
|
|
45028
44352
|
out += defaultValue ? `.default(${defaultValue})` : "";
|
|
45029
44353
|
return out;
|
|
45030
44354
|
}
|
|
45031
44355
|
if (lowered.startsWith("smallint")) {
|
|
45032
|
-
let out = `${name
|
|
44356
|
+
let out = `${withCasing3(name, casing)}: smallint("${name}")`;
|
|
45033
44357
|
out += defaultValue ? `.default(${defaultValue})` : "";
|
|
45034
44358
|
return out;
|
|
45035
44359
|
}
|
|
45036
44360
|
if (lowered.startsWith("bigint")) {
|
|
45037
44361
|
let out = `// You can use { mode: "bigint" } if numbers are exceeding js number limitations
|
|
45038
44362
|
`;
|
|
45039
|
-
out += `${name
|
|
44363
|
+
out += `${withCasing3(name, casing)}: bigint("${name}", { mode: "number" })`;
|
|
45040
44364
|
out += defaultValue ? `.default(${defaultValue})` : "";
|
|
45041
44365
|
return out;
|
|
45042
44366
|
}
|
|
45043
44367
|
if (lowered.startsWith("boolean")) {
|
|
45044
|
-
let out = `${name
|
|
44368
|
+
let out = `${withCasing3(name, casing)}: boolean("${name}")`;
|
|
45045
44369
|
out += defaultValue ? `.default(${defaultValue})` : "";
|
|
45046
44370
|
return out;
|
|
45047
44371
|
}
|
|
45048
44372
|
if (lowered.startsWith("double precision")) {
|
|
45049
|
-
let out = `${name
|
|
44373
|
+
let out = `${withCasing3(name, casing)}: doublePrecision("${name}")`;
|
|
45050
44374
|
out += defaultValue ? `.default(${defaultValue})` : "";
|
|
45051
44375
|
return out;
|
|
45052
44376
|
}
|
|
45053
44377
|
if (lowered.startsWith("real")) {
|
|
45054
|
-
let out = `${name
|
|
44378
|
+
let out = `${withCasing3(name, casing)}: real("${name}")`;
|
|
45055
44379
|
out += defaultValue ? `.default(${defaultValue})` : "";
|
|
45056
44380
|
return out;
|
|
45057
44381
|
}
|
|
45058
44382
|
if (lowered.startsWith("uuid")) {
|
|
45059
|
-
let out = `${name
|
|
44383
|
+
let out = `${withCasing3(name, casing)}: uuid("${name}")`;
|
|
45060
44384
|
out += defaultValue === "gen_random_uuid()" ? ".defaultRandom()" : defaultValue ? `.default(sql\`${defaultValue}\`)` : "";
|
|
45061
44385
|
return out;
|
|
45062
44386
|
}
|
|
@@ -45066,7 +44390,7 @@ var init_introspect = __esm({
|
|
|
45066
44390
|
const [precision, scale] = lowered.slice(8, lowered.length - 1).split(",");
|
|
45067
44391
|
params = { precision, scale };
|
|
45068
44392
|
}
|
|
45069
|
-
let out = params ? `${name
|
|
44393
|
+
let out = params ? `${withCasing3(name, casing)}: numeric("${name}", ${timeConfig2(params)})` : `${withCasing3(name, casing)}: numeric("${name}")`;
|
|
45070
44394
|
defaultValue = defaultValue ? defaultValue.startsWith(`'`) && defaultValue.endsWith(`'`) ? defaultValue.substring(1, defaultValue.length - 1) : defaultValue : void 0;
|
|
45071
44395
|
out += defaultValue ? `.default('${defaultValue}')` : "";
|
|
45072
44396
|
return out;
|
|
@@ -45082,7 +44406,7 @@ var init_introspect = __esm({
|
|
|
45082
44406
|
withTimezone,
|
|
45083
44407
|
mode: "'string'"
|
|
45084
44408
|
});
|
|
45085
|
-
let out = params ? `${name
|
|
44409
|
+
let out = params ? `${withCasing3(name, casing)}: timestamp("${name}", ${params})` : `${withCasing3(name, casing)}: timestamp("${name}")`;
|
|
45086
44410
|
defaultValue = defaultValue === "now()" || defaultValue === "CURRENT_TIMESTAMP" ? ".defaultNow()" : defaultValue ? `.default(${defaultValue})` : "";
|
|
45087
44411
|
out += defaultValue;
|
|
45088
44412
|
return out;
|
|
@@ -45094,59 +44418,59 @@ var init_introspect = __esm({
|
|
|
45094
44418
|
) : null;
|
|
45095
44419
|
precision = precision ? precision : null;
|
|
45096
44420
|
const params = timeConfig2({ precision, withTimezone });
|
|
45097
|
-
let out = params ? `${name
|
|
44421
|
+
let out = params ? `${withCasing3(name, casing)}: time("${name}", ${params})` : `${withCasing3(name, casing)}: time("${name}")`;
|
|
45098
44422
|
defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${defaultValue})` : "";
|
|
45099
44423
|
out += defaultValue;
|
|
45100
44424
|
return out;
|
|
45101
44425
|
}
|
|
45102
44426
|
if (lowered.startsWith("interval")) {
|
|
45103
44427
|
const params = intervalConfig(lowered);
|
|
45104
|
-
let out = params ? `${name
|
|
44428
|
+
let out = params ? `${withCasing3(name, casing)}: interval("${name}", ${params})` : `${withCasing3(name, casing)}: interval("${name}")`;
|
|
45105
44429
|
out += defaultValue ? `.default(${defaultValue})` : "";
|
|
45106
44430
|
return out;
|
|
45107
44431
|
}
|
|
45108
44432
|
if (lowered === "date") {
|
|
45109
|
-
let out = `${name
|
|
44433
|
+
let out = `${withCasing3(name, casing)}: date("${name}")`;
|
|
45110
44434
|
defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${defaultValue})` : "";
|
|
45111
44435
|
out += defaultValue;
|
|
45112
44436
|
return out;
|
|
45113
44437
|
}
|
|
45114
44438
|
if (lowered.startsWith("text")) {
|
|
45115
|
-
let out = `${name
|
|
44439
|
+
let out = `${withCasing3(name, casing)}: text("${name}")`;
|
|
45116
44440
|
out += defaultValue ? `.default(${defaultValue})` : "";
|
|
45117
44441
|
return out;
|
|
45118
44442
|
}
|
|
45119
44443
|
if (lowered === "json") {
|
|
45120
|
-
let out = `${name
|
|
44444
|
+
let out = `${withCasing3(name, casing)}: json("${name}")`;
|
|
45121
44445
|
defaultValue = (defaultValue == null ? void 0 : defaultValue.endsWith("::json")) ? defaultValue.substring(1, defaultValue.length - 7) : defaultValue;
|
|
45122
44446
|
const def = defaultValue ? defaultValue : null;
|
|
45123
44447
|
out += defaultValue ? `.default(${def})` : "";
|
|
45124
44448
|
return out;
|
|
45125
44449
|
}
|
|
45126
44450
|
if (lowered === "jsonb") {
|
|
45127
|
-
let out = `${name
|
|
44451
|
+
let out = `${withCasing3(name, casing)}: jsonb("${name}")`;
|
|
45128
44452
|
defaultValue = (defaultValue == null ? void 0 : defaultValue.endsWith("::jsonb")) ? defaultValue.substring(1, defaultValue.length - 8) : defaultValue;
|
|
45129
44453
|
const def = defaultValue ? defaultValue : null;
|
|
45130
44454
|
out += defaultValue ? `.default(${def})` : "";
|
|
45131
44455
|
return out;
|
|
45132
44456
|
}
|
|
45133
44457
|
if (lowered.startsWith("inet")) {
|
|
45134
|
-
let out = `${name
|
|
44458
|
+
let out = `${withCasing3(name, casing)}: inet("${name}")`;
|
|
45135
44459
|
out += defaultValue ? `.default(${defaultValue})` : "";
|
|
45136
44460
|
return out;
|
|
45137
44461
|
}
|
|
45138
44462
|
if (lowered.startsWith("cidr")) {
|
|
45139
|
-
let out = `${name
|
|
44463
|
+
let out = `${withCasing3(name, casing)}: cidr("${name}")`;
|
|
45140
44464
|
out += defaultValue ? `.default(${defaultValue})` : "";
|
|
45141
44465
|
return out;
|
|
45142
44466
|
}
|
|
45143
44467
|
if (lowered.startsWith("macaddr")) {
|
|
45144
|
-
let out = `${name
|
|
44468
|
+
let out = `${withCasing3(name, casing)}: macaddr("${name}")`;
|
|
45145
44469
|
out += defaultValue ? `.default(${defaultValue})` : "";
|
|
45146
44470
|
return out;
|
|
45147
44471
|
}
|
|
45148
44472
|
if (lowered.startsWith("macaddr8")) {
|
|
45149
|
-
let out = `${name
|
|
44473
|
+
let out = `${withCasing3(name, casing)}: macaddr8("${name}")`;
|
|
45150
44474
|
out += defaultValue ? `.default(${defaultValue})` : "";
|
|
45151
44475
|
return out;
|
|
45152
44476
|
}
|
|
@@ -45154,12 +44478,15 @@ var init_introspect = __esm({
|
|
|
45154
44478
|
const split = lowered.split(" ");
|
|
45155
44479
|
let out;
|
|
45156
44480
|
if (lowered.length !== 7) {
|
|
45157
|
-
out = `${
|
|
44481
|
+
out = `${withCasing3(
|
|
44482
|
+
name,
|
|
44483
|
+
casing
|
|
44484
|
+
)}: varchar("${name}", { length: ${lowered.substring(
|
|
45158
44485
|
8,
|
|
45159
44486
|
lowered.length - 1
|
|
45160
44487
|
)} })`;
|
|
45161
44488
|
} else {
|
|
45162
|
-
out = `${name
|
|
44489
|
+
out = `${withCasing3(name, casing)}: varchar("${name}")`;
|
|
45163
44490
|
}
|
|
45164
44491
|
out += defaultValue ? `.default(${defaultValue})` : "";
|
|
45165
44492
|
return out;
|
|
@@ -45167,24 +44494,30 @@ var init_introspect = __esm({
|
|
|
45167
44494
|
if (lowered.startsWith("char")) {
|
|
45168
44495
|
let out;
|
|
45169
44496
|
if (lowered.length !== 4) {
|
|
45170
|
-
out = `${
|
|
44497
|
+
out = `${withCasing3(
|
|
44498
|
+
name,
|
|
44499
|
+
casing
|
|
44500
|
+
)}: char("${name}", { length: ${lowered.substring(
|
|
45171
44501
|
5,
|
|
45172
44502
|
lowered.length - 1
|
|
45173
44503
|
)} })`;
|
|
45174
44504
|
} else {
|
|
45175
|
-
out = `${name
|
|
44505
|
+
out = `${withCasing3(name, casing)}: char("${name}")`;
|
|
45176
44506
|
}
|
|
45177
44507
|
out += defaultValue ? `.default(${defaultValue})` : "";
|
|
45178
44508
|
return out;
|
|
45179
44509
|
}
|
|
45180
44510
|
if (enumTypes.has(type)) {
|
|
45181
|
-
let out = `${name
|
|
44511
|
+
let out = `${withCasing3(name, casing)}: ${withCasing3(
|
|
44512
|
+
type,
|
|
44513
|
+
casing
|
|
44514
|
+
)}("${name}")`;
|
|
45182
44515
|
out += defaultValue ? `.default(${defaultValue})` : "";
|
|
45183
44516
|
return out;
|
|
45184
44517
|
}
|
|
45185
44518
|
let unknown = `// TODO: failed to parse database type '${type}'
|
|
45186
44519
|
`;
|
|
45187
|
-
unknown += ` ${name
|
|
44520
|
+
unknown += ` ${withCasing3(name, casing)}: unknown("${name}")`;
|
|
45188
44521
|
return unknown;
|
|
45189
44522
|
};
|
|
45190
44523
|
dimensionsInArray = (str) => {
|
|
@@ -45196,7 +44529,7 @@ var init_introspect = __esm({
|
|
|
45196
44529
|
}
|
|
45197
44530
|
return res;
|
|
45198
44531
|
};
|
|
45199
|
-
createTableColumns3 = (columns, fks, enumTypes) => {
|
|
44532
|
+
createTableColumns3 = (columns, fks, enumTypes, casing) => {
|
|
45200
44533
|
let statement = "";
|
|
45201
44534
|
const oneColumnsFKs = Object.values(fks).filter((it) => {
|
|
45202
44535
|
return !isSelf3(it);
|
|
@@ -45208,7 +44541,7 @@ var init_introspect = __esm({
|
|
|
45208
44541
|
return res;
|
|
45209
44542
|
}, {});
|
|
45210
44543
|
columns.forEach((it) => {
|
|
45211
|
-
const columnStatement = column6(it.type, it.name, enumTypes, it.default);
|
|
44544
|
+
const columnStatement = column6(it.type, it.name, enumTypes, it.default, casing);
|
|
45212
44545
|
statement += " ";
|
|
45213
44546
|
statement += columnStatement;
|
|
45214
44547
|
statement += dimensionsInArray(it.type);
|
|
@@ -45223,9 +44556,15 @@ var init_introspect = __esm({
|
|
|
45223
44556
|
const typeSuffix = isCyclic3(it2) ? ": AnyPgColumn" : "";
|
|
45224
44557
|
const paramsStr = objToStatement23(params);
|
|
45225
44558
|
if (paramsStr) {
|
|
45226
|
-
return `.references(()${typeSuffix} => ${
|
|
45227
|
-
|
|
45228
|
-
|
|
44559
|
+
return `.references(()${typeSuffix} => ${withCasing3(
|
|
44560
|
+
it2.tableTo,
|
|
44561
|
+
casing
|
|
44562
|
+
)}.${withCasing3(it2.columnsTo[0], casing)}, ${paramsStr} )`;
|
|
44563
|
+
}
|
|
44564
|
+
return `.references(()${typeSuffix} => ${withCasing3(
|
|
44565
|
+
it2.tableTo,
|
|
44566
|
+
casing
|
|
44567
|
+
)}.${withCasing3(it2.columnsTo[0], casing)})`;
|
|
45229
44568
|
}).join("");
|
|
45230
44569
|
statement += fksStatement;
|
|
45231
44570
|
}
|
|
@@ -45233,31 +44572,31 @@ var init_introspect = __esm({
|
|
|
45233
44572
|
});
|
|
45234
44573
|
return statement;
|
|
45235
44574
|
};
|
|
45236
|
-
createTableIndexes3 = (tableName, idxs) => {
|
|
44575
|
+
createTableIndexes3 = (tableName, idxs, casing) => {
|
|
45237
44576
|
let statement = "";
|
|
45238
44577
|
idxs.forEach((it) => {
|
|
45239
44578
|
let idxKey = it.name.startsWith(tableName) && it.name !== tableName ? it.name.slice(tableName.length + 1) : it.name;
|
|
45240
44579
|
idxKey = idxKey.endsWith("_index") ? idxKey.slice(0, -"_index".length) + "_idx" : idxKey;
|
|
45241
|
-
idxKey = idxKey
|
|
44580
|
+
idxKey = withCasing3(idxKey, casing);
|
|
45242
44581
|
const indexGeneratedName = indexName2(tableName, it.columns);
|
|
45243
44582
|
const escapedIndexName = indexGeneratedName === it.name ? "" : `"${it.name}"`;
|
|
45244
44583
|
statement += ` ${idxKey}: `;
|
|
45245
44584
|
statement += it.isUnique ? "uniqueIndex(" : "index(";
|
|
45246
44585
|
statement += `${escapedIndexName})`;
|
|
45247
|
-
statement += `.on(${it.columns.map((it2) => `table.${it2
|
|
44586
|
+
statement += `.on(${it.columns.map((it2) => `table.${withCasing3(it2, casing)}`).join(", ")}),`;
|
|
45248
44587
|
statement += `
|
|
45249
44588
|
`;
|
|
45250
44589
|
});
|
|
45251
44590
|
return statement;
|
|
45252
44591
|
};
|
|
45253
|
-
createTablePKs3 = (pks) => {
|
|
44592
|
+
createTablePKs3 = (pks, casing) => {
|
|
45254
44593
|
let statement = "";
|
|
45255
44594
|
pks.forEach((it) => {
|
|
45256
|
-
let idxKey = it.name
|
|
44595
|
+
let idxKey = withCasing3(it.name, casing);
|
|
45257
44596
|
statement += ` ${idxKey}: `;
|
|
45258
44597
|
statement += "primaryKey(";
|
|
45259
44598
|
statement += `${it.columns.map((c) => {
|
|
45260
|
-
return `table.${c
|
|
44599
|
+
return `table.${withCasing3(c, casing)}`;
|
|
45261
44600
|
}).join(", ")}`;
|
|
45262
44601
|
statement += ")";
|
|
45263
44602
|
statement += `
|
|
@@ -45265,16 +44604,16 @@ var init_introspect = __esm({
|
|
|
45265
44604
|
});
|
|
45266
44605
|
return statement;
|
|
45267
44606
|
};
|
|
45268
|
-
createTableFKs3 = (fks) => {
|
|
44607
|
+
createTableFKs3 = (fks, casing) => {
|
|
45269
44608
|
let statement = "";
|
|
45270
44609
|
fks.forEach((it) => {
|
|
45271
44610
|
const isSelf4 = it.tableTo === it.tableFrom;
|
|
45272
|
-
const tableTo = isSelf4 ? "table" : `${it.tableTo
|
|
45273
|
-
statement += ` ${it.name
|
|
44611
|
+
const tableTo = isSelf4 ? "table" : `${withCasing3(it.tableTo, casing)}`;
|
|
44612
|
+
statement += ` ${withCasing3(it.name, casing)}: foreignKey({
|
|
45274
44613
|
`;
|
|
45275
|
-
statement += ` columns: [${it.columnsFrom.map((i) => `table.${i
|
|
44614
|
+
statement += ` columns: [${it.columnsFrom.map((i) => `table.${withCasing3(i, casing)}`).join(", ")}],
|
|
45276
44615
|
`;
|
|
45277
|
-
statement += ` foreignColumns: [${it.columnsTo.map((i) => `${tableTo}.${i
|
|
44616
|
+
statement += ` foreignColumns: [${it.columnsTo.map((i) => `${tableTo}.${withCasing3(i, casing)}`).join(", ")}]
|
|
45278
44617
|
`;
|
|
45279
44618
|
statement += ` })`;
|
|
45280
44619
|
statement += it.onUpdate && it.onUpdate !== "no action" ? `.onUpdate("${it.onUpdate}")` : "";
|
|
@@ -45290,45 +44629,42 @@ var init_introspect = __esm({
|
|
|
45290
44629
|
// src/cli/commands/pgIntrospect.ts
|
|
45291
44630
|
var pgIntrospect_exports = {};
|
|
45292
44631
|
__export(pgIntrospect_exports, {
|
|
45293
|
-
PgConfig1: () => PgConfig1,
|
|
45294
|
-
PgConfig2: () => PgConfig2,
|
|
45295
44632
|
pgIntrospect: () => pgIntrospect
|
|
45296
44633
|
});
|
|
45297
|
-
var
|
|
44634
|
+
var import_hanji7, import_pg, pgIntrospect;
|
|
45298
44635
|
var init_pgIntrospect = __esm({
|
|
45299
44636
|
"src/cli/commands/pgIntrospect.ts"() {
|
|
45300
|
-
|
|
45301
|
-
init_lib();
|
|
44637
|
+
import_hanji7 = __toESM(require_hanji());
|
|
45302
44638
|
init_views();
|
|
45303
|
-
import_pg = __toESM(
|
|
44639
|
+
import_pg = __toESM(require_lib5());
|
|
45304
44640
|
init_pgSerializer();
|
|
45305
44641
|
init_introspect();
|
|
45306
44642
|
init_global();
|
|
45307
|
-
|
|
45308
|
-
|
|
45309
|
-
|
|
45310
|
-
|
|
45311
|
-
|
|
45312
|
-
|
|
45313
|
-
|
|
45314
|
-
|
|
45315
|
-
|
|
45316
|
-
|
|
45317
|
-
|
|
45318
|
-
|
|
45319
|
-
|
|
45320
|
-
|
|
45321
|
-
|
|
45322
|
-
|
|
44643
|
+
init_mjs();
|
|
44644
|
+
pgIntrospect = async (config, filters) => {
|
|
44645
|
+
const pool = new import_pg.Pool(config.dbCredentials);
|
|
44646
|
+
const matchers = filters.map((it) => {
|
|
44647
|
+
return new Minimatch(it);
|
|
44648
|
+
});
|
|
44649
|
+
const filter2 = (tableName) => {
|
|
44650
|
+
if (matchers.length === 0)
|
|
44651
|
+
return true;
|
|
44652
|
+
for (let i = 0; i < matchers.length; i++) {
|
|
44653
|
+
const matcher = matchers[i];
|
|
44654
|
+
if (matcher.match(tableName))
|
|
44655
|
+
return true;
|
|
44656
|
+
}
|
|
44657
|
+
return false;
|
|
44658
|
+
};
|
|
45323
44659
|
const progress = new IntrospectProgress();
|
|
45324
|
-
const res = await (0,
|
|
44660
|
+
const res = await (0, import_hanji7.renderWithTask)(
|
|
45325
44661
|
progress,
|
|
45326
|
-
fromDatabase2(pool, (stage, count, status) => {
|
|
44662
|
+
fromDatabase2(pool, filter2, (stage, count, status) => {
|
|
45327
44663
|
progress.update(stage, count, status);
|
|
45328
44664
|
})
|
|
45329
44665
|
);
|
|
45330
44666
|
const schema4 = { id: originUUID, prevId: "", ...res };
|
|
45331
|
-
const ts = schemaToTypeScript3(schema4);
|
|
44667
|
+
const ts = schemaToTypeScript3(schema4, { casing: config.introspect.casing });
|
|
45332
44668
|
return { schema: schema4, ts };
|
|
45333
44669
|
};
|
|
45334
44670
|
}
|
|
@@ -45383,7 +44719,7 @@ var checkHandler = (out, dialect6) => {
|
|
|
45383
44719
|
};
|
|
45384
44720
|
|
|
45385
44721
|
// src/cli/index.ts
|
|
45386
|
-
var
|
|
44722
|
+
var import_hanji8 = __toESM(require_hanji());
|
|
45387
44723
|
var import_path7 = __toESM(require("path"));
|
|
45388
44724
|
|
|
45389
44725
|
// src/cli/utils.ts
|
|
@@ -45472,6 +44808,7 @@ var package_default = {
|
|
|
45472
44808
|
"sim:sqlite": "node -r esbuild-register ./dev/sqlite/index.ts",
|
|
45473
44809
|
test: "ava test --timeout=60s",
|
|
45474
44810
|
build: "rm -rf ./dist && tsx build.ts && tsc -p tsconfig.cli-types.json",
|
|
44811
|
+
"build:dev": "rm -rf ./dist && tsx build.dev.ts && tsc -p tsconfig.cli-types.json && chmod +x ./dist/index.cjs",
|
|
45475
44812
|
pack: "build && package",
|
|
45476
44813
|
tsc: "tsc -p tsconfig.build.json",
|
|
45477
44814
|
pub: "cp package.json readme.md dist/ && cd dist && npm publish"
|
|
@@ -45512,7 +44849,7 @@ var package_default = {
|
|
|
45512
44849
|
"better-sqlite3": "^8.4.0",
|
|
45513
44850
|
dockerode: "^3.3.4",
|
|
45514
44851
|
dotenv: "^16.0.3",
|
|
45515
|
-
"drizzle-orm": "0.
|
|
44852
|
+
"drizzle-orm": "0.27.0-56b9edc",
|
|
45516
44853
|
esbuild: "^0.17.19",
|
|
45517
44854
|
"esbuild-register": "^3.4.2",
|
|
45518
44855
|
eslint: "^8.29.0",
|
|
@@ -45596,6 +44933,10 @@ var dropMigration = async (out) => {
|
|
|
45596
44933
|
const journal = JSON.parse(
|
|
45597
44934
|
(0, import_fs9.readFileSync)(metaFilePath, "utf-8")
|
|
45598
44935
|
);
|
|
44936
|
+
if (journal.entries.length === 0) {
|
|
44937
|
+
console.log(`[${source_default.blue("i")}] no migration entries found in ${metaFilePath}`);
|
|
44938
|
+
return;
|
|
44939
|
+
}
|
|
45599
44940
|
const result = await (0, import_hanji3.render)(new DropMigrationView(journal.entries));
|
|
45600
44941
|
if (result.status === "aborted")
|
|
45601
44942
|
return;
|
|
@@ -45667,12 +45008,38 @@ var assertOutFolder = async (it) => {
|
|
|
45667
45008
|
var configCommonSchema = objectType({
|
|
45668
45009
|
schema: unionType([stringType(), stringType().array()]),
|
|
45669
45010
|
out: stringType().optional(),
|
|
45670
|
-
breakpoints: booleanType().
|
|
45011
|
+
breakpoints: booleanType().default(true),
|
|
45671
45012
|
tablesFilter: unionType([stringType(), stringType().array()]).optional()
|
|
45672
45013
|
});
|
|
45014
|
+
var introspectCasing = objectType({
|
|
45015
|
+
casing: unionType([literalType("camel"), literalType("preserve")]).default("camel")
|
|
45016
|
+
}).default({ casing: "camel" });
|
|
45673
45017
|
var configIntrospectSchema = objectType({
|
|
45018
|
+
schema: unionType([stringType(), stringType().array()]).optional(),
|
|
45674
45019
|
out: stringType().optional().default("./drizzle"),
|
|
45675
|
-
breakpoints: booleanType().
|
|
45020
|
+
breakpoints: booleanType().default(true),
|
|
45021
|
+
tablesFilter: unionType([stringType(), stringType().array()]).optional(),
|
|
45022
|
+
introspect: introspectCasing
|
|
45023
|
+
});
|
|
45024
|
+
var configIntrospectCliSchema = objectType({
|
|
45025
|
+
schema: unionType([stringType(), stringType().array()]).optional(),
|
|
45026
|
+
out: stringType().optional().default("./drizzle"),
|
|
45027
|
+
breakpoints: booleanType().default(true),
|
|
45028
|
+
tablesFilter: unionType([stringType(), stringType().array()]).optional(),
|
|
45029
|
+
introspectCasing: unionType([literalType("camel"), literalType("preserve")]).default(
|
|
45030
|
+
"camel"
|
|
45031
|
+
)
|
|
45032
|
+
});
|
|
45033
|
+
var configGenerateSchema = objectType({
|
|
45034
|
+
schema: unionType([stringType(), stringType().array()]),
|
|
45035
|
+
out: stringType().optional().default("./drizzle"),
|
|
45036
|
+
breakpoints: booleanType().default(true)
|
|
45037
|
+
});
|
|
45038
|
+
var configPushSchema = objectType({
|
|
45039
|
+
schema: unionType([stringType(), stringType().array()]),
|
|
45040
|
+
tablesFilter: unionType([stringType(), stringType().array()]).optional(),
|
|
45041
|
+
verbose: booleanType().default(false),
|
|
45042
|
+
strict: booleanType().default(false)
|
|
45676
45043
|
});
|
|
45677
45044
|
var mysqlConnectionSchema = unionType([
|
|
45678
45045
|
objectType({
|
|
@@ -45702,7 +45069,6 @@ var drizzleConfigFromFile = async (configPath) => {
|
|
|
45702
45069
|
const defaultJsonConfigExists = (0, import_fs10.existsSync)(
|
|
45703
45070
|
(0, import_path6.join)((0, import_path6.resolve)("drizzle.config.json"))
|
|
45704
45071
|
);
|
|
45705
|
-
console.log(configPath);
|
|
45706
45072
|
const defaultConfigPath = defaultTsConfigExists ? "drizzle.config.ts" : defaultJsConfigExists ? "drizzle.config.js" : "drizzle.config.json";
|
|
45707
45073
|
if (!configPath) {
|
|
45708
45074
|
console.log(
|
|
@@ -45777,6 +45143,7 @@ var logSuggestionsAndReturn = async ({
|
|
|
45777
45143
|
}) => {
|
|
45778
45144
|
let shouldAskForApprove = false;
|
|
45779
45145
|
const statementsToExecute = [];
|
|
45146
|
+
const infoToPrint = [];
|
|
45780
45147
|
const tablesToRemove = [];
|
|
45781
45148
|
const columnsToRemove = [];
|
|
45782
45149
|
const schemasToRemove = [];
|
|
@@ -45788,7 +45155,7 @@ var logSuggestionsAndReturn = async ({
|
|
|
45788
45155
|
);
|
|
45789
45156
|
const count = Number(res[0][0].count);
|
|
45790
45157
|
if (count > 0) {
|
|
45791
|
-
|
|
45158
|
+
infoToPrint.push(
|
|
45792
45159
|
`\xB7 You're about to delete ${source_default.underline(
|
|
45793
45160
|
statement.tableName
|
|
45794
45161
|
)} table with ${count} items`
|
|
@@ -45802,7 +45169,7 @@ var logSuggestionsAndReturn = async ({
|
|
|
45802
45169
|
);
|
|
45803
45170
|
const count = Number(res[0][0].count);
|
|
45804
45171
|
if (count > 0) {
|
|
45805
|
-
|
|
45172
|
+
infoToPrint.push(
|
|
45806
45173
|
`\xB7 You're about to delete ${source_default.underline(
|
|
45807
45174
|
statement.columnName
|
|
45808
45175
|
)} column in ${statement.tableName} table with ${count} items`
|
|
@@ -45816,7 +45183,7 @@ var logSuggestionsAndReturn = async ({
|
|
|
45816
45183
|
);
|
|
45817
45184
|
const count = Number(res[0][0].count);
|
|
45818
45185
|
if (count > 0) {
|
|
45819
|
-
|
|
45186
|
+
infoToPrint.push(
|
|
45820
45187
|
`\xB7 You're about to delete ${source_default.underline(
|
|
45821
45188
|
statement.name
|
|
45822
45189
|
)} schema with ${count} tables`
|
|
@@ -45830,7 +45197,7 @@ var logSuggestionsAndReturn = async ({
|
|
|
45830
45197
|
);
|
|
45831
45198
|
const count = Number(res[0][0].count);
|
|
45832
45199
|
if (count > 0) {
|
|
45833
|
-
|
|
45200
|
+
infoToPrint.push(
|
|
45834
45201
|
`\xB7 You're about to change ${source_default.underline(
|
|
45835
45202
|
statement.columnName
|
|
45836
45203
|
)} column type from ${source_default.underline(
|
|
@@ -45848,7 +45215,7 @@ var logSuggestionsAndReturn = async ({
|
|
|
45848
45215
|
);
|
|
45849
45216
|
const count = Number(res[0][0].count);
|
|
45850
45217
|
if (count > 0) {
|
|
45851
|
-
|
|
45218
|
+
infoToPrint.push(
|
|
45852
45219
|
`\xB7 You're about to remove default value from ${source_default.underline(
|
|
45853
45220
|
statement.columnName
|
|
45854
45221
|
)} not-null column with ${count} items`
|
|
@@ -45866,7 +45233,7 @@ var logSuggestionsAndReturn = async ({
|
|
|
45866
45233
|
);
|
|
45867
45234
|
const count = Number(res[0][0].count);
|
|
45868
45235
|
if (count > 0) {
|
|
45869
|
-
|
|
45236
|
+
infoToPrint.push(
|
|
45870
45237
|
`\xB7 You're about to set not-null constraint to ${source_default.underline(
|
|
45871
45238
|
statement.columnName
|
|
45872
45239
|
)} column without default, which contains ${count} items`
|
|
@@ -45882,7 +45249,7 @@ var logSuggestionsAndReturn = async ({
|
|
|
45882
45249
|
);
|
|
45883
45250
|
const count = Number(res[0][0].count);
|
|
45884
45251
|
if (count > 0) {
|
|
45885
|
-
|
|
45252
|
+
infoToPrint.push(
|
|
45886
45253
|
`\xB7 You're about to change ${source_default.underline(
|
|
45887
45254
|
statement.tableName
|
|
45888
45255
|
)} primary key. This statements may fail and you table may left without primary key`
|
|
@@ -45897,7 +45264,7 @@ var logSuggestionsAndReturn = async ({
|
|
|
45897
45264
|
);
|
|
45898
45265
|
const count = Number(res[0][0].count);
|
|
45899
45266
|
if (count > 0) {
|
|
45900
|
-
|
|
45267
|
+
infoToPrint.push(
|
|
45901
45268
|
`\xB7 You're about to add not-null ${source_default.underline(
|
|
45902
45269
|
statement.column.name
|
|
45903
45270
|
)} column without default value, which contains ${count} items`
|
|
@@ -45912,6 +45279,7 @@ var logSuggestionsAndReturn = async ({
|
|
|
45912
45279
|
return {
|
|
45913
45280
|
statementsToExecute,
|
|
45914
45281
|
shouldAskForApprove,
|
|
45282
|
+
infoToPrint,
|
|
45915
45283
|
columnsToRemove: [...new Set(columnsToRemove)],
|
|
45916
45284
|
schemasToRemove: [...new Set(schemasToRemove)],
|
|
45917
45285
|
tablesToTruncate: [...new Set(tablesToTruncate)],
|
|
@@ -46097,11 +45465,32 @@ var logSuggestionsAndReturn2 = async ({
|
|
|
46097
45465
|
}
|
|
46098
45466
|
}
|
|
46099
45467
|
} else if (statement.type === "alter_table_alter_column_set_type" || statement.type === "alter_table_alter_column_set_default" || statement.type === "alter_table_alter_column_drop_default" || statement.type === "alter_table_alter_column_set_notnull" || statement.type === "alter_table_alter_column_drop_notnull" || statement.type === "alter_table_alter_column_drop_autoincrement" || statement.type === "alter_table_alter_column_set_autoincrement" || statement.type === "alter_table_alter_column_drop_pk" || statement.type === "alter_table_alter_column_set_pk") {
|
|
46100
|
-
if (typeof
|
|
46101
|
-
|
|
46102
|
-
statement.tableName
|
|
46103
|
-
json2
|
|
45468
|
+
if (statement.type === "alter_table_alter_column_set_notnull" && typeof statement.columnDefault === "undefined") {
|
|
45469
|
+
const res = await connection.query(
|
|
45470
|
+
`select count(*) as count from \`${statement.tableName}\``
|
|
46104
45471
|
);
|
|
45472
|
+
const count = Number(res[0].count);
|
|
45473
|
+
if (count > 0) {
|
|
45474
|
+
infoToPrint.push(
|
|
45475
|
+
`\xB7 You're about to add not-null constraint to ${source_default.underline(
|
|
45476
|
+
statement.columnName
|
|
45477
|
+
)} column without default value, which contains ${count} items`
|
|
45478
|
+
);
|
|
45479
|
+
tablesContext[statement.tableName] = _moveDataStatements(
|
|
45480
|
+
statement.tableName,
|
|
45481
|
+
json2,
|
|
45482
|
+
true
|
|
45483
|
+
);
|
|
45484
|
+
tablesToTruncate.push(statement.tableName);
|
|
45485
|
+
shouldAskForApprove = true;
|
|
45486
|
+
}
|
|
45487
|
+
} else {
|
|
45488
|
+
if (typeof tablesContext[statement.tableName] === "undefined") {
|
|
45489
|
+
tablesContext[statement.tableName] = _moveDataStatements(
|
|
45490
|
+
statement.tableName,
|
|
45491
|
+
json2
|
|
45492
|
+
);
|
|
45493
|
+
}
|
|
46105
45494
|
}
|
|
46106
45495
|
const tablesReferncingCurrent = [];
|
|
46107
45496
|
for (const table4 of Object.values(json1.tables)) {
|
|
@@ -46179,14 +45568,8 @@ var sqliteConnectionSchema = unionType([
|
|
|
46179
45568
|
})
|
|
46180
45569
|
})
|
|
46181
45570
|
]);
|
|
46182
|
-
var configIntrospectSchema2 = objectType({
|
|
46183
|
-
schema: unionType([stringType(), stringType().array()]).optional(),
|
|
46184
|
-
out: stringType().optional().default("./drizzle"),
|
|
46185
|
-
breakpoints: booleanType().optional(),
|
|
46186
|
-
tablesFilter: unionType([stringType(), stringType().array()]).optional()
|
|
46187
|
-
});
|
|
46188
45571
|
var sqliteCliConfigSchema = intersectionType(
|
|
46189
|
-
|
|
45572
|
+
configIntrospectSchema,
|
|
46190
45573
|
sqliteConnectionSchema
|
|
46191
45574
|
);
|
|
46192
45575
|
|
|
@@ -46197,27 +45580,42 @@ var withStyle = {
|
|
|
46197
45580
|
warning: (str) => `${source_default.white.bgGray(" Warning ")} ${str}`
|
|
46198
45581
|
};
|
|
46199
45582
|
var outputs = {
|
|
46200
|
-
|
|
46201
|
-
|
|
46202
|
-
|
|
46203
|
-
|
|
45583
|
+
common: {
|
|
45584
|
+
ambiguousParams: (command) => withStyle.error(
|
|
45585
|
+
`You can't use both --config and other cli options for ${command} command`
|
|
45586
|
+
),
|
|
45587
|
+
schema: (command) => withStyle.error(`"--schema" is a required field for ${command} command`)
|
|
45588
|
+
},
|
|
45589
|
+
postgres: {
|
|
45590
|
+
connection: {
|
|
45591
|
+
driver: () => withStyle.error(
|
|
45592
|
+
`Only "pg" is available options for "--driver"`
|
|
45593
|
+
),
|
|
45594
|
+
required: () => withStyle.error(
|
|
45595
|
+
`Either "connectionString" or "host", "database" are required for database connection`
|
|
46204
45596
|
)
|
|
46205
|
-
}
|
|
45597
|
+
}
|
|
45598
|
+
},
|
|
45599
|
+
mysql: {
|
|
46206
45600
|
connection: {
|
|
46207
45601
|
driver: () => withStyle.error(
|
|
46208
|
-
`
|
|
45602
|
+
`Only "mysql2" is available options for "--driver"`
|
|
46209
45603
|
),
|
|
45604
|
+
required: () => withStyle.error(
|
|
45605
|
+
`Either "connectionString" or "host", "database" are required for database connection`
|
|
45606
|
+
)
|
|
45607
|
+
}
|
|
45608
|
+
},
|
|
45609
|
+
sqlite: {
|
|
45610
|
+
connection: {
|
|
45611
|
+
driver: () => withStyle.error(`Either "turso", "libsql", "better-sqlite" are available options for "--driver"`),
|
|
46210
45612
|
url: (driver) => withStyle.error(`"--url" is a required option for driver "${driver}"`),
|
|
46211
45613
|
authToken: (driver) => withStyle.error(
|
|
46212
45614
|
`"--auth-token" is a required option for driver "${driver}"`
|
|
46213
45615
|
)
|
|
46214
45616
|
},
|
|
46215
45617
|
introspect: {},
|
|
46216
|
-
push: {
|
|
46217
|
-
schema: () => withStyle.error(
|
|
46218
|
-
`"--schema" is a required field for sqlite:push command`
|
|
46219
|
-
)
|
|
46220
|
-
}
|
|
45618
|
+
push: {}
|
|
46221
45619
|
}
|
|
46222
45620
|
};
|
|
46223
45621
|
|
|
@@ -46250,7 +45648,7 @@ var checkCollisions = (options, command, inputWhitelist = []) => {
|
|
|
46250
45648
|
}
|
|
46251
45649
|
return {
|
|
46252
45650
|
success: false,
|
|
46253
|
-
message: outputs.
|
|
45651
|
+
message: outputs.common.ambiguousParams(command),
|
|
46254
45652
|
action: "error"
|
|
46255
45653
|
};
|
|
46256
45654
|
};
|
|
@@ -46272,15 +45670,9 @@ var sqliteConnectionCli = unionType([
|
|
|
46272
45670
|
})
|
|
46273
45671
|
]);
|
|
46274
45672
|
var sqliteCliIntrospectParams = intersectionType(
|
|
46275
|
-
|
|
45673
|
+
configIntrospectCliSchema,
|
|
46276
45674
|
sqliteConnectionCli
|
|
46277
45675
|
);
|
|
46278
|
-
var configPushSchema = objectType({
|
|
46279
|
-
schema: unionType([stringType(), stringType().array()]),
|
|
46280
|
-
tablesFilter: unionType([stringType(), stringType().array()]).optional(),
|
|
46281
|
-
verbose: booleanType().default(false),
|
|
46282
|
-
strict: booleanType().default(false)
|
|
46283
|
-
});
|
|
46284
45676
|
var sqliteCliPushParams = intersectionType(
|
|
46285
45677
|
configPushSchema,
|
|
46286
45678
|
sqliteConnectionCli
|
|
@@ -46330,14 +45722,14 @@ var printConfigConnectionIssues = (options) => {
|
|
|
46330
45722
|
console.log(outputs.sqlite.connection.driver());
|
|
46331
45723
|
}
|
|
46332
45724
|
};
|
|
46333
|
-
var validateIntrospect = (options) => {
|
|
45725
|
+
var validateIntrospect = async (options) => {
|
|
46334
45726
|
const collisionRes = checkCollisions(options, "introspect:sqlite");
|
|
46335
45727
|
if (!collisionRes.success) {
|
|
46336
45728
|
console.log(collisionRes.message);
|
|
46337
45729
|
process.exit(1);
|
|
46338
45730
|
}
|
|
46339
45731
|
if (collisionRes.action === "config") {
|
|
46340
|
-
const drizzleConfig = readDrizzleConfig(options.config);
|
|
45732
|
+
const drizzleConfig = await readDrizzleConfig(options.config);
|
|
46341
45733
|
const configRes = sqliteCliConfigSchema.safeParse(drizzleConfig);
|
|
46342
45734
|
if (!configRes.success) {
|
|
46343
45735
|
printConfigConnectionIssues(drizzleConfig);
|
|
@@ -46351,15 +45743,27 @@ var validateIntrospect = (options) => {
|
|
|
46351
45743
|
process.exit(1);
|
|
46352
45744
|
}
|
|
46353
45745
|
if (cliRes.data.driver === "turso") {
|
|
46354
|
-
const { authToken, url: url2, ...rest2 } = cliRes.data;
|
|
46355
|
-
return {
|
|
45746
|
+
const { authToken, url: url2, introspectCasing: introspectCasing3, ...rest2 } = cliRes.data;
|
|
45747
|
+
return {
|
|
45748
|
+
...rest2,
|
|
45749
|
+
dbCredentials: { url: url2, authToken },
|
|
45750
|
+
introspect: { casing: introspectCasing3 }
|
|
45751
|
+
};
|
|
46356
45752
|
}
|
|
46357
45753
|
if (cliRes.data.driver === "libsql") {
|
|
46358
|
-
const { url: url2, ...rest2 } = cliRes.data;
|
|
46359
|
-
return {
|
|
45754
|
+
const { url: url2, introspectCasing: introspectCasing3, ...rest2 } = cliRes.data;
|
|
45755
|
+
return {
|
|
45756
|
+
...rest2,
|
|
45757
|
+
dbCredentials: { url: url2 },
|
|
45758
|
+
introspect: { casing: introspectCasing3 }
|
|
45759
|
+
};
|
|
46360
45760
|
}
|
|
46361
|
-
const { url, ...rest } = cliRes.data;
|
|
46362
|
-
return {
|
|
45761
|
+
const { url, introspectCasing: introspectCasing2, ...rest } = cliRes.data;
|
|
45762
|
+
return {
|
|
45763
|
+
...rest,
|
|
45764
|
+
dbCredentials: { url },
|
|
45765
|
+
introspect: { casing: introspectCasing2 }
|
|
45766
|
+
};
|
|
46363
45767
|
};
|
|
46364
45768
|
var validatePush = async (options) => {
|
|
46365
45769
|
const collisionRes = checkCollisions(options, "push:sqlite");
|
|
@@ -46380,7 +45784,7 @@ var validatePush = async (options) => {
|
|
|
46380
45784
|
const cliRes = sqliteCliPushParams.safeParse(options);
|
|
46381
45785
|
if (!cliRes.success) {
|
|
46382
45786
|
if (typeof options.schema === "undefined") {
|
|
46383
|
-
console.log(outputs.
|
|
45787
|
+
console.log(outputs.common.schema("push:sqlite"));
|
|
46384
45788
|
}
|
|
46385
45789
|
printCliConnectionIssues(options);
|
|
46386
45790
|
process.exit(1);
|
|
@@ -46393,6 +45797,269 @@ var validatePush = async (options) => {
|
|
|
46393
45797
|
return { ...rest, dbCredentials: { url } };
|
|
46394
45798
|
};
|
|
46395
45799
|
|
|
45800
|
+
// src/cli/validations/pg.ts
|
|
45801
|
+
init_lib();
|
|
45802
|
+
var pgConnectionCli = unionType([
|
|
45803
|
+
objectType({
|
|
45804
|
+
driver: literalType("pg"),
|
|
45805
|
+
host: stringType(),
|
|
45806
|
+
port: coerce.number().optional(),
|
|
45807
|
+
user: stringType().default("postgres"),
|
|
45808
|
+
password: stringType().optional(),
|
|
45809
|
+
database: stringType(),
|
|
45810
|
+
ssl: coerce.boolean().optional(),
|
|
45811
|
+
type: literalType("params").default("params")
|
|
45812
|
+
}),
|
|
45813
|
+
objectType({
|
|
45814
|
+
driver: literalType("pg"),
|
|
45815
|
+
connectionString: stringType(),
|
|
45816
|
+
type: literalType("url").default("url")
|
|
45817
|
+
})
|
|
45818
|
+
]);
|
|
45819
|
+
var pgConnectionConfig = unionType([
|
|
45820
|
+
objectType({
|
|
45821
|
+
driver: literalType("pg"),
|
|
45822
|
+
dbCredentials: objectType({
|
|
45823
|
+
host: stringType(),
|
|
45824
|
+
port: coerce.number().optional(),
|
|
45825
|
+
user: stringType().default("postgres"),
|
|
45826
|
+
password: stringType().optional(),
|
|
45827
|
+
database: stringType(),
|
|
45828
|
+
ssl: coerce.boolean().optional()
|
|
45829
|
+
})
|
|
45830
|
+
}),
|
|
45831
|
+
objectType({
|
|
45832
|
+
driver: literalType("pg"),
|
|
45833
|
+
dbCredentials: objectType({
|
|
45834
|
+
connectionString: stringType()
|
|
45835
|
+
})
|
|
45836
|
+
})
|
|
45837
|
+
]);
|
|
45838
|
+
var pgConfigIntrospectSchema = intersectionType(
|
|
45839
|
+
configIntrospectSchema,
|
|
45840
|
+
pgConnectionConfig
|
|
45841
|
+
);
|
|
45842
|
+
var pgCliIntrospectParams = intersectionType(
|
|
45843
|
+
configIntrospectCliSchema,
|
|
45844
|
+
pgConnectionCli
|
|
45845
|
+
);
|
|
45846
|
+
var printCliConnectionIssues2 = (options) => {
|
|
45847
|
+
if (options.driver === "pg") {
|
|
45848
|
+
if (typeof options.connectionString === "undefined" && (typeof options.host === "undefined" || typeof options.database === "undefined")) {
|
|
45849
|
+
console.log(outputs.postgres.connection.required());
|
|
45850
|
+
}
|
|
45851
|
+
} else {
|
|
45852
|
+
console.log(outputs.postgres.connection.driver());
|
|
45853
|
+
}
|
|
45854
|
+
};
|
|
45855
|
+
var printConfigConnectionIssues2 = (options) => {
|
|
45856
|
+
if (options.driver === "pg") {
|
|
45857
|
+
if (typeof options.dbCredentials.connectionString === "undefined" && (typeof options.dbCredentials.host === "undefined" || typeof options.dbCredentials.database === "undefined")) {
|
|
45858
|
+
console.log(outputs.postgres.connection.required());
|
|
45859
|
+
}
|
|
45860
|
+
} else {
|
|
45861
|
+
console.log(outputs.postgres.connection.driver());
|
|
45862
|
+
}
|
|
45863
|
+
};
|
|
45864
|
+
var validatePgIntrospect = async (options) => {
|
|
45865
|
+
const collisionRes = checkCollisions(options, "introspect:pg");
|
|
45866
|
+
if (!collisionRes.success) {
|
|
45867
|
+
console.log(collisionRes.message);
|
|
45868
|
+
process.exit(1);
|
|
45869
|
+
}
|
|
45870
|
+
if (collisionRes.action === "config") {
|
|
45871
|
+
const drizzleConfig = await readDrizzleConfig(options.config);
|
|
45872
|
+
const configRes = pgConfigIntrospectSchema.safeParse(drizzleConfig);
|
|
45873
|
+
if (!configRes.success) {
|
|
45874
|
+
printConfigConnectionIssues2(drizzleConfig);
|
|
45875
|
+
process.exit(1);
|
|
45876
|
+
}
|
|
45877
|
+
return configRes.data;
|
|
45878
|
+
}
|
|
45879
|
+
const cliRes = pgCliIntrospectParams.safeParse(options);
|
|
45880
|
+
if (!cliRes.success) {
|
|
45881
|
+
printCliConnectionIssues2(options);
|
|
45882
|
+
process.exit(1);
|
|
45883
|
+
}
|
|
45884
|
+
if (cliRes.data.type === "url") {
|
|
45885
|
+
const { connectionString, introspectCasing: introspectCasing3, ...rest2 } = cliRes.data;
|
|
45886
|
+
return {
|
|
45887
|
+
...rest2,
|
|
45888
|
+
dbCredentials: { connectionString },
|
|
45889
|
+
introspect: { casing: introspectCasing3 }
|
|
45890
|
+
};
|
|
45891
|
+
}
|
|
45892
|
+
const {
|
|
45893
|
+
host,
|
|
45894
|
+
password,
|
|
45895
|
+
port,
|
|
45896
|
+
database,
|
|
45897
|
+
ssl,
|
|
45898
|
+
user,
|
|
45899
|
+
introspectCasing: introspectCasing2,
|
|
45900
|
+
...rest
|
|
45901
|
+
} = cliRes.data;
|
|
45902
|
+
return {
|
|
45903
|
+
...rest,
|
|
45904
|
+
dbCredentials: { host, password, port, database, ssl, user },
|
|
45905
|
+
introspect: { casing: introspectCasing2 }
|
|
45906
|
+
};
|
|
45907
|
+
};
|
|
45908
|
+
|
|
45909
|
+
// src/cli/validations/mysql.ts
|
|
45910
|
+
init_lib();
|
|
45911
|
+
var mysqlConnectionCli = unionType([
|
|
45912
|
+
objectType({
|
|
45913
|
+
driver: literalType("mysql2"),
|
|
45914
|
+
host: stringType(),
|
|
45915
|
+
port: coerce.number().optional(),
|
|
45916
|
+
user: stringType().default("mysql"),
|
|
45917
|
+
password: stringType().optional(),
|
|
45918
|
+
database: stringType(),
|
|
45919
|
+
type: literalType("params").default("params")
|
|
45920
|
+
}),
|
|
45921
|
+
objectType({
|
|
45922
|
+
driver: literalType("mysql2"),
|
|
45923
|
+
connectionString: stringType(),
|
|
45924
|
+
type: literalType("url").default("url")
|
|
45925
|
+
})
|
|
45926
|
+
]);
|
|
45927
|
+
var mysqlConnectionConfig = unionType([
|
|
45928
|
+
objectType({
|
|
45929
|
+
driver: literalType("mysql2"),
|
|
45930
|
+
dbCredentials: objectType({
|
|
45931
|
+
host: stringType(),
|
|
45932
|
+
port: coerce.number().optional(),
|
|
45933
|
+
user: stringType().default("mysql"),
|
|
45934
|
+
password: stringType().optional(),
|
|
45935
|
+
database: stringType(),
|
|
45936
|
+
type: literalType("params").default("params")
|
|
45937
|
+
})
|
|
45938
|
+
}),
|
|
45939
|
+
objectType({
|
|
45940
|
+
driver: literalType("mysql2"),
|
|
45941
|
+
dbCredentials: objectType({
|
|
45942
|
+
connectionString: stringType(),
|
|
45943
|
+
type: literalType("url").default("url")
|
|
45944
|
+
})
|
|
45945
|
+
})
|
|
45946
|
+
]);
|
|
45947
|
+
var mysqlConfigIntrospectSchema = intersectionType(
|
|
45948
|
+
configIntrospectSchema,
|
|
45949
|
+
mysqlConnectionConfig
|
|
45950
|
+
);
|
|
45951
|
+
var mysqlCliIntrospectParams = intersectionType(
|
|
45952
|
+
configIntrospectCliSchema,
|
|
45953
|
+
mysqlConnectionCli
|
|
45954
|
+
);
|
|
45955
|
+
var mysqlCliPushParams = intersectionType(
|
|
45956
|
+
configPushSchema,
|
|
45957
|
+
mysqlConnectionCli
|
|
45958
|
+
);
|
|
45959
|
+
var mysqlConfigPushParams = intersectionType(
|
|
45960
|
+
configPushSchema,
|
|
45961
|
+
mysqlConnectionConfig
|
|
45962
|
+
);
|
|
45963
|
+
var printCliConnectionIssues3 = (options) => {
|
|
45964
|
+
if (options.driver === "mysql2") {
|
|
45965
|
+
if (typeof options.connectionString === "undefined" && (typeof options.host === "undefined" || typeof options.database === "undefined")) {
|
|
45966
|
+
console.log(outputs.mysql.connection.required());
|
|
45967
|
+
}
|
|
45968
|
+
} else {
|
|
45969
|
+
console.log(outputs.mysql.connection.driver());
|
|
45970
|
+
}
|
|
45971
|
+
};
|
|
45972
|
+
var printConfigConnectionIssues3 = (options) => {
|
|
45973
|
+
if (options.driver === "mysql2") {
|
|
45974
|
+
if (typeof options.dbCredentials.connectionString === "undefined" && (typeof options.dbCredentials.host === "undefined" || typeof options.dbCredentials.database === "undefined")) {
|
|
45975
|
+
console.log(outputs.mysql.connection.required());
|
|
45976
|
+
}
|
|
45977
|
+
} else {
|
|
45978
|
+
console.log(outputs.mysql.connection.driver());
|
|
45979
|
+
}
|
|
45980
|
+
};
|
|
45981
|
+
var validateMySqlIntrospect = async (options) => {
|
|
45982
|
+
const collisionRes = checkCollisions(options, "introspect:mysql");
|
|
45983
|
+
if (!collisionRes.success) {
|
|
45984
|
+
console.log(collisionRes.message);
|
|
45985
|
+
process.exit(1);
|
|
45986
|
+
}
|
|
45987
|
+
if (collisionRes.action === "config") {
|
|
45988
|
+
const drizzleConfig = await readDrizzleConfig(options.config);
|
|
45989
|
+
const configRes = mysqlConfigIntrospectSchema.safeParse(drizzleConfig);
|
|
45990
|
+
if (!configRes.success) {
|
|
45991
|
+
printConfigConnectionIssues3(drizzleConfig);
|
|
45992
|
+
process.exit(1);
|
|
45993
|
+
}
|
|
45994
|
+
return configRes.data;
|
|
45995
|
+
}
|
|
45996
|
+
const cliRes = mysqlCliIntrospectParams.safeParse(options);
|
|
45997
|
+
if (!cliRes.success) {
|
|
45998
|
+
printCliConnectionIssues3(options);
|
|
45999
|
+
process.exit(1);
|
|
46000
|
+
}
|
|
46001
|
+
if (cliRes.data.type === "url") {
|
|
46002
|
+
const { connectionString, introspectCasing: introspectCasing3, type: type2, ...rest2 } = cliRes.data;
|
|
46003
|
+
return {
|
|
46004
|
+
...rest2,
|
|
46005
|
+
dbCredentials: { connectionString, type: type2 },
|
|
46006
|
+
introspect: { casing: introspectCasing3 }
|
|
46007
|
+
};
|
|
46008
|
+
}
|
|
46009
|
+
const {
|
|
46010
|
+
host,
|
|
46011
|
+
password,
|
|
46012
|
+
port,
|
|
46013
|
+
database,
|
|
46014
|
+
user,
|
|
46015
|
+
type,
|
|
46016
|
+
introspectCasing: introspectCasing2,
|
|
46017
|
+
...rest
|
|
46018
|
+
} = cliRes.data;
|
|
46019
|
+
return {
|
|
46020
|
+
...rest,
|
|
46021
|
+
dbCredentials: { host, password, port, database, user, type },
|
|
46022
|
+
introspect: { casing: introspectCasing2 }
|
|
46023
|
+
};
|
|
46024
|
+
};
|
|
46025
|
+
var validateMySqlPush = async (options) => {
|
|
46026
|
+
const collisionRes = checkCollisions(options, "push:mysql");
|
|
46027
|
+
if (!collisionRes.success) {
|
|
46028
|
+
console.log(collisionRes.message);
|
|
46029
|
+
console.log();
|
|
46030
|
+
process.exit(1);
|
|
46031
|
+
}
|
|
46032
|
+
if (collisionRes.action === "config") {
|
|
46033
|
+
const drizzleConfig = await readDrizzleConfig(options.config);
|
|
46034
|
+
const configRes = mysqlConfigPushParams.safeParse(drizzleConfig);
|
|
46035
|
+
if (!configRes.success) {
|
|
46036
|
+
printConfigConnectionIssues3(drizzleConfig);
|
|
46037
|
+
process.exit(1);
|
|
46038
|
+
}
|
|
46039
|
+
return configRes.data;
|
|
46040
|
+
}
|
|
46041
|
+
const cliRes = mysqlCliPushParams.safeParse(options);
|
|
46042
|
+
if (!cliRes.success) {
|
|
46043
|
+
if (typeof options.schema === "undefined") {
|
|
46044
|
+
console.log(outputs.common.schema("push:mysql"));
|
|
46045
|
+
}
|
|
46046
|
+
printCliConnectionIssues3(options);
|
|
46047
|
+
process.exit(1);
|
|
46048
|
+
}
|
|
46049
|
+
if (cliRes.data.type === "url") {
|
|
46050
|
+
const { connectionString, type: type2, ...rest2 } = cliRes.data;
|
|
46051
|
+
return {
|
|
46052
|
+
...rest2,
|
|
46053
|
+
dbCredentials: { connectionString, type: type2 }
|
|
46054
|
+
};
|
|
46055
|
+
}
|
|
46056
|
+
const { host, password, port, database, user, type, ...rest } = cliRes.data;
|
|
46057
|
+
return {
|
|
46058
|
+
...rest,
|
|
46059
|
+
dbCredentials: { host, password, port, database, user, type }
|
|
46060
|
+
};
|
|
46061
|
+
};
|
|
46062
|
+
|
|
46396
46063
|
// src/cli/index.ts
|
|
46397
46064
|
var printVersions = async () => {
|
|
46398
46065
|
const v = await versions();
|
|
@@ -46410,7 +46077,7 @@ var optionsSchema = objectType({
|
|
|
46410
46077
|
schema: unionType([stringType(), stringType().array()]).optional(),
|
|
46411
46078
|
out: stringType().optional().default("./drizzle"),
|
|
46412
46079
|
config: stringType().optional(),
|
|
46413
|
-
breakpoints: booleanType().optional().default(
|
|
46080
|
+
breakpoints: booleanType().optional().default(true),
|
|
46414
46081
|
custom: booleanType().optional().default(false)
|
|
46415
46082
|
}).strict();
|
|
46416
46083
|
var generatePgCommand = new import_commander.Command("generate:pg").option("--schema <schema...>", "Path to a schema file or folder").option("--out <out>", `Output folder, 'drizzle' by default`).option("--breakpoints", `Prepare SQL statements with breakpoints`).option("--custom", "Prepare empty migration file for custom SQL").option(
|
|
@@ -46419,6 +46086,15 @@ var generatePgCommand = new import_commander.Command("generate:pg").option("--sc
|
|
|
46419
46086
|
).action(async (options) => {
|
|
46420
46087
|
await printVersions();
|
|
46421
46088
|
await assertOrmCoreVersion();
|
|
46089
|
+
const collisionRes = checkCollisions(
|
|
46090
|
+
options,
|
|
46091
|
+
"generate:pg",
|
|
46092
|
+
["custom"]
|
|
46093
|
+
);
|
|
46094
|
+
if (!collisionRes.success) {
|
|
46095
|
+
console.log(collisionRes.message);
|
|
46096
|
+
process.exit(1);
|
|
46097
|
+
}
|
|
46422
46098
|
const oprtionsParsed = optionsSchema.parse(options);
|
|
46423
46099
|
const result = await prepareGenerateConfig(oprtionsParsed);
|
|
46424
46100
|
await assertPackages("drizzle-orm");
|
|
@@ -46431,20 +46107,29 @@ var generateMysqlCommand = new import_commander.Command("generate:mysql").option
|
|
|
46431
46107
|
).action(async (options) => {
|
|
46432
46108
|
await printVersions();
|
|
46433
46109
|
await assertOrmCoreVersion();
|
|
46110
|
+
const collisionRes = checkCollisions(
|
|
46111
|
+
options,
|
|
46112
|
+
"generate:mysql",
|
|
46113
|
+
["custom"]
|
|
46114
|
+
);
|
|
46115
|
+
if (!collisionRes.success) {
|
|
46116
|
+
console.log(collisionRes.message);
|
|
46117
|
+
process.exit(1);
|
|
46118
|
+
}
|
|
46434
46119
|
const oprtionsParsed = optionsSchema.parse(options);
|
|
46435
46120
|
const result = await prepareGenerateConfig(oprtionsParsed);
|
|
46436
46121
|
await assertPackages("drizzle-orm");
|
|
46437
46122
|
const { prepareAndMigrateMySql: prepareAndMigrateMySql2 } = await Promise.resolve().then(() => (init_migrate(), migrate_exports));
|
|
46438
46123
|
await prepareAndMigrateMySql2(result);
|
|
46439
46124
|
});
|
|
46440
|
-
var Select = class extends
|
|
46125
|
+
var Select = class extends import_hanji8.Prompt {
|
|
46441
46126
|
// private readonly spinner: () => string;
|
|
46442
46127
|
// private timeout: NodeJS.Timer | undefined;
|
|
46443
46128
|
constructor(items) {
|
|
46444
46129
|
super();
|
|
46445
46130
|
this.on("attach", (terminal) => terminal.toggleCursor("hide"));
|
|
46446
46131
|
this.on("detach", (terminal) => terminal.toggleCursor("show"));
|
|
46447
|
-
this.data = new
|
|
46132
|
+
this.data = new import_hanji8.SelectState(
|
|
46448
46133
|
items.map((it) => ({ label: it, value: `${it}-value` }))
|
|
46449
46134
|
);
|
|
46450
46135
|
this.data.bind(this);
|
|
@@ -46469,15 +46154,17 @@ var Select = class extends import_hanji7.Prompt {
|
|
|
46469
46154
|
var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
|
|
46470
46155
|
"--config <config>",
|
|
46471
46156
|
"Path to a config.json file, drizzle.config.json by default"
|
|
46472
|
-
).action(async (options) => {
|
|
46157
|
+
).option("--schema <schema...>", "Path to a schema file or folder").option("--tableFilters", `Table name filters`).option("--connectionString <connectionString>", "MySQL connection string").option("--driver <driver>", "MySQL database path").option("--connectionString <connectionString>", "MySQL connection string").option("--host <host>", "MySQL host").option("--port <port>", "MySQL port").option("--user <user>", "MySQL user").option("--password <password>", "MySQL password").option("--database <database>", "MySQL database name").option("--verbose", "Print all statements for each push").option("--strict", "Always ask for confirmation").action(async (options) => {
|
|
46473
46158
|
await printVersions();
|
|
46474
46159
|
await assertPackages("drizzle-orm");
|
|
46475
46160
|
await assertOrmCoreVersion();
|
|
46476
46161
|
const { mysqlPushIntrospect: mysqlPushIntrospect2, connectToMySQL: connectToMySQL2 } = await Promise.resolve().then(() => (init_mysqlIntrospect(), mysqlIntrospect_exports));
|
|
46477
|
-
const drizzleConfig = await
|
|
46162
|
+
const drizzleConfig = await validateMySqlPush(
|
|
46163
|
+
options
|
|
46164
|
+
);
|
|
46478
46165
|
const fileNames = prepareFilenames(drizzleConfig.schema);
|
|
46479
46166
|
if (fileNames.length === 0) {
|
|
46480
|
-
(0,
|
|
46167
|
+
(0, import_hanji8.render)(
|
|
46481
46168
|
`[${source_default.blue("i")}] No schema file in ${drizzleConfig.schema} was found`
|
|
46482
46169
|
);
|
|
46483
46170
|
process.exit(0);
|
|
@@ -46494,7 +46181,7 @@ var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
|
|
|
46494
46181
|
try {
|
|
46495
46182
|
if (typeof statements === "undefined") {
|
|
46496
46183
|
} else if (statements.sqlStatements.length === 0) {
|
|
46497
|
-
(0,
|
|
46184
|
+
(0, import_hanji8.render)(`[${source_default.blue("i")}] No changes detected`);
|
|
46498
46185
|
} else {
|
|
46499
46186
|
const filteredStatements = filterStatements(statements.statements);
|
|
46500
46187
|
const {
|
|
@@ -46503,27 +46190,52 @@ var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
|
|
|
46503
46190
|
columnsToRemove,
|
|
46504
46191
|
tablesToRemove,
|
|
46505
46192
|
tablesToTruncate,
|
|
46193
|
+
infoToPrint,
|
|
46506
46194
|
schemasToRemove
|
|
46507
46195
|
} = await logSuggestionsAndReturn({
|
|
46508
46196
|
connection: connection.client,
|
|
46509
46197
|
statements: filteredStatements
|
|
46510
46198
|
});
|
|
46199
|
+
if (drizzleConfig.verbose) {
|
|
46200
|
+
console.log();
|
|
46201
|
+
console.log(
|
|
46202
|
+
withStyle.warning("You are about to execute current statements:")
|
|
46203
|
+
);
|
|
46204
|
+
console.log();
|
|
46205
|
+
console.log(
|
|
46206
|
+
[...statementsToExecute, ...statements.sqlStatements].map((s) => source_default.blue(s)).join("\n")
|
|
46207
|
+
);
|
|
46208
|
+
console.log();
|
|
46209
|
+
}
|
|
46210
|
+
if (drizzleConfig.strict) {
|
|
46211
|
+
if (!shouldAskForApprove) {
|
|
46212
|
+
const { status, data } = await (0, import_hanji8.render)(
|
|
46213
|
+
new Select(["No, abort", `Yes, I want to execute all statements`])
|
|
46214
|
+
);
|
|
46215
|
+
if ((data == null ? void 0 : data.index) === 0) {
|
|
46216
|
+
(0, import_hanji8.render)(`[${source_default.red("x")}] All changes were aborted`);
|
|
46217
|
+
process.exit(0);
|
|
46218
|
+
}
|
|
46219
|
+
}
|
|
46220
|
+
}
|
|
46511
46221
|
if (shouldAskForApprove) {
|
|
46512
|
-
console.log("
|
|
46222
|
+
console.log(withStyle.warning("Found data-loss statements:"));
|
|
46223
|
+
console.log(infoToPrint.join("\n"));
|
|
46224
|
+
console.log();
|
|
46513
46225
|
console.log(
|
|
46514
46226
|
source_default.red.bold(
|
|
46515
46227
|
"THIS ACTION WILL CAUSE DATA LOSS AND CANNOT BE REVERTED\n"
|
|
46516
46228
|
)
|
|
46517
46229
|
);
|
|
46518
46230
|
console.log(source_default.white("Do you still want to push changes?"));
|
|
46519
|
-
const { status, data } = await (0,
|
|
46231
|
+
const { status, data } = await (0, import_hanji8.render)(
|
|
46520
46232
|
new Select([
|
|
46521
46233
|
"No, abort",
|
|
46522
46234
|
`Yes, I want to${tablesToRemove.length > 0 ? ` remove ${tablesToRemove.length} ${tablesToRemove.length > 1 ? "tables" : "table"},` : " "}${columnsToRemove.length > 0 ? ` remove ${columnsToRemove.length} ${columnsToRemove.length > 1 ? "columns" : "column"},` : " "}${tablesToTruncate.length > 0 ? ` truncate ${tablesToTruncate.length} ${tablesToTruncate.length > 1 ? "tables" : "table"}` : ""}`.replace(/(^,)|(,$)/g, "").replace(/ +(?= )/g, "")
|
|
46523
46235
|
])
|
|
46524
46236
|
);
|
|
46525
46237
|
if ((data == null ? void 0 : data.index) === 0) {
|
|
46526
|
-
(0,
|
|
46238
|
+
(0, import_hanji8.render)(`[${source_default.red("x")}] All changes were aborted`);
|
|
46527
46239
|
process.exit(0);
|
|
46528
46240
|
}
|
|
46529
46241
|
}
|
|
@@ -46534,9 +46246,9 @@ var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
|
|
|
46534
46246
|
await connection.client.query(statement);
|
|
46535
46247
|
}
|
|
46536
46248
|
if (filteredStatements.length > 0) {
|
|
46537
|
-
(0,
|
|
46249
|
+
(0, import_hanji8.render)(`[${source_default.green("\u2713")}] Changes applied`);
|
|
46538
46250
|
} else {
|
|
46539
|
-
(0,
|
|
46251
|
+
(0, import_hanji8.render)(`[${source_default.blue("i")}] No changes detected`);
|
|
46540
46252
|
}
|
|
46541
46253
|
}
|
|
46542
46254
|
} catch (e) {
|
|
@@ -46556,7 +46268,7 @@ var dbPushSqliteCommand = new import_commander.Command("push:sqlite").option(
|
|
|
46556
46268
|
const res = await validatePush(options);
|
|
46557
46269
|
const fileNames = prepareFilenames(res.schema);
|
|
46558
46270
|
if (fileNames.length === 0) {
|
|
46559
|
-
(0,
|
|
46271
|
+
(0, import_hanji8.render)(`[${source_default.blue("i")}] No schema file in ${res.schema} was found`);
|
|
46560
46272
|
process.exit(0);
|
|
46561
46273
|
}
|
|
46562
46274
|
const connection = await connectToSQLite2(res);
|
|
@@ -46571,7 +46283,7 @@ var dbPushSqliteCommand = new import_commander.Command("push:sqlite").option(
|
|
|
46571
46283
|
try {
|
|
46572
46284
|
if (typeof statements === "undefined") {
|
|
46573
46285
|
} else if (statements.sqlStatements.length === 0) {
|
|
46574
|
-
(0,
|
|
46286
|
+
(0, import_hanji8.render)(`
|
|
46575
46287
|
[${source_default.blue("i")}] No changes detected`);
|
|
46576
46288
|
} else {
|
|
46577
46289
|
const {
|
|
@@ -46599,11 +46311,11 @@ var dbPushSqliteCommand = new import_commander.Command("push:sqlite").option(
|
|
|
46599
46311
|
}
|
|
46600
46312
|
if (res.strict) {
|
|
46601
46313
|
if (!shouldAskForApprove) {
|
|
46602
|
-
const { status, data } = await (0,
|
|
46314
|
+
const { status, data } = await (0, import_hanji8.render)(
|
|
46603
46315
|
new Select(["No, abort", `Yes, I want to execute all statements`])
|
|
46604
46316
|
);
|
|
46605
46317
|
if ((data == null ? void 0 : data.index) === 0) {
|
|
46606
|
-
(0,
|
|
46318
|
+
(0, import_hanji8.render)(`[${source_default.red("x")}] All changes were aborted`);
|
|
46607
46319
|
process.exit(0);
|
|
46608
46320
|
}
|
|
46609
46321
|
}
|
|
@@ -46618,21 +46330,21 @@ var dbPushSqliteCommand = new import_commander.Command("push:sqlite").option(
|
|
|
46618
46330
|
)
|
|
46619
46331
|
);
|
|
46620
46332
|
console.log(source_default.white("Do you still want to push changes?"));
|
|
46621
|
-
const { status, data } = await (0,
|
|
46333
|
+
const { status, data } = await (0, import_hanji8.render)(
|
|
46622
46334
|
new Select([
|
|
46623
46335
|
"No, abort",
|
|
46624
46336
|
`Yes, I want to${tablesToRemove.length > 0 ? ` remove ${tablesToRemove.length} ${tablesToRemove.length > 1 ? "tables" : "table"},` : " "}${columnsToRemove.length > 0 ? ` remove ${columnsToRemove.length} ${columnsToRemove.length > 1 ? "columns" : "column"},` : " "}${tablesToTruncate.length > 0 ? ` truncate ${tablesToTruncate.length} ${tablesToTruncate.length > 1 ? "tables" : "table"}` : ""}`.trimEnd().replace(/(^,)|(,$)/g, "").replace(/ +(?= )/g, "")
|
|
46625
46337
|
])
|
|
46626
46338
|
);
|
|
46627
46339
|
if ((data == null ? void 0 : data.index) === 0) {
|
|
46628
|
-
(0,
|
|
46340
|
+
(0, import_hanji8.render)(`[${source_default.red("x")}] All changes were aborted`);
|
|
46629
46341
|
process.exit(0);
|
|
46630
46342
|
}
|
|
46631
46343
|
}
|
|
46632
46344
|
for (const dStmnt of statementsToExecute) {
|
|
46633
46345
|
await connection.client.run(dStmnt);
|
|
46634
46346
|
}
|
|
46635
|
-
(0,
|
|
46347
|
+
(0, import_hanji8.render)(`[${source_default.green("\u2713")}] Changes applied`);
|
|
46636
46348
|
}
|
|
46637
46349
|
} catch (e) {
|
|
46638
46350
|
console.log(e);
|
|
@@ -46645,6 +46357,15 @@ var generateSqliteCommand = new import_commander.Command("generate:sqlite").opti
|
|
|
46645
46357
|
).action(async (options) => {
|
|
46646
46358
|
await printVersions();
|
|
46647
46359
|
await assertOrmCoreVersion();
|
|
46360
|
+
const collisionRes = checkCollisions(
|
|
46361
|
+
options,
|
|
46362
|
+
"generate:sqlite",
|
|
46363
|
+
["custom"]
|
|
46364
|
+
);
|
|
46365
|
+
if (!collisionRes.success) {
|
|
46366
|
+
console.log(collisionRes.message);
|
|
46367
|
+
process.exit(1);
|
|
46368
|
+
}
|
|
46648
46369
|
const oprtionsParsed = optionsSchema.parse(options);
|
|
46649
46370
|
const result = await prepareGenerateConfig(oprtionsParsed);
|
|
46650
46371
|
await assertPackages("drizzle-orm");
|
|
@@ -46658,6 +46379,14 @@ var checkSchema = objectType({
|
|
|
46658
46379
|
var checkPgCommand = new import_commander.Command("check:pg").option("--out <out>", `Output folder`).option("--config <config>", `Config path [default=drizzle.config.json]`).action(async (options) => {
|
|
46659
46380
|
await printVersions();
|
|
46660
46381
|
await assertOrmCoreVersion();
|
|
46382
|
+
const collisionRes = checkCollisions(
|
|
46383
|
+
options,
|
|
46384
|
+
"check:pg"
|
|
46385
|
+
);
|
|
46386
|
+
if (!collisionRes.success) {
|
|
46387
|
+
console.log(collisionRes.message);
|
|
46388
|
+
process.exit(1);
|
|
46389
|
+
}
|
|
46661
46390
|
const params = checkSchema.parse(options);
|
|
46662
46391
|
const out = await assertOutFolder(params);
|
|
46663
46392
|
checkHandler(out, "pg");
|
|
@@ -46666,14 +46395,46 @@ var checkPgCommand = new import_commander.Command("check:pg").option("--out <out
|
|
|
46666
46395
|
var checkSqliteCommand = new import_commander.Command("check:sqlite").option("--out <out>", `Output folder`).option("--config <config>", `Config path [default=drizzle.config.json]`).action(async (options) => {
|
|
46667
46396
|
await printVersions();
|
|
46668
46397
|
await assertOrmCoreVersion();
|
|
46398
|
+
const collisionRes = checkCollisions(
|
|
46399
|
+
options,
|
|
46400
|
+
"check:sqlite"
|
|
46401
|
+
);
|
|
46402
|
+
if (!collisionRes.success) {
|
|
46403
|
+
console.log(collisionRes.message);
|
|
46404
|
+
process.exit(1);
|
|
46405
|
+
}
|
|
46669
46406
|
const params = checkSchema.parse(options);
|
|
46670
46407
|
const out = await assertOutFolder(params);
|
|
46671
46408
|
checkHandler(out, "sqlite");
|
|
46672
46409
|
console.log("Everything's fine \u{1F436}\u{1F525}");
|
|
46673
46410
|
});
|
|
46411
|
+
var checkMySqlCommand = new import_commander.Command("check:mysql").option("--out <out>", `Output folder`).option("--config <config>", `Config path [default=drizzle.config.json]`).action(async (options) => {
|
|
46412
|
+
await printVersions();
|
|
46413
|
+
await assertOrmCoreVersion();
|
|
46414
|
+
const collisionRes = checkCollisions(
|
|
46415
|
+
options,
|
|
46416
|
+
"check:mysql"
|
|
46417
|
+
);
|
|
46418
|
+
if (!collisionRes.success) {
|
|
46419
|
+
console.log(collisionRes.message);
|
|
46420
|
+
process.exit(1);
|
|
46421
|
+
}
|
|
46422
|
+
const params = checkSchema.parse(options);
|
|
46423
|
+
const out = await assertOutFolder(params);
|
|
46424
|
+
checkHandler(out, "mysql");
|
|
46425
|
+
console.log("Everything's fine \u{1F436}\u{1F525}");
|
|
46426
|
+
});
|
|
46674
46427
|
var upPgCommand = new import_commander.Command("up:pg").option("--out <out>", `Output folder`).option("--config <config>", `Config path [default=drizzle.config.json]`).action(async (options) => {
|
|
46675
46428
|
await printVersions();
|
|
46676
46429
|
await assertOrmCoreVersion();
|
|
46430
|
+
const collisionRes = checkCollisions(
|
|
46431
|
+
options,
|
|
46432
|
+
"up:pg"
|
|
46433
|
+
);
|
|
46434
|
+
if (!collisionRes.success) {
|
|
46435
|
+
console.log(collisionRes.message);
|
|
46436
|
+
process.exit(1);
|
|
46437
|
+
}
|
|
46677
46438
|
const params = checkSchema.parse(options);
|
|
46678
46439
|
const out = await assertOutFolder(params);
|
|
46679
46440
|
await assertPackages("drizzle-orm");
|
|
@@ -46684,6 +46445,14 @@ var upPgCommand = new import_commander.Command("up:pg").option("--out <out>", `O
|
|
|
46684
46445
|
var upMysqlCommand = new import_commander.Command("up:mysql").option("--out <out>", `Output folder`).option("--config <config>", `Config path [default=drizzle.config.json]`).action(async (options) => {
|
|
46685
46446
|
await printVersions();
|
|
46686
46447
|
await assertOrmCoreVersion();
|
|
46448
|
+
const collisionRes = checkCollisions(
|
|
46449
|
+
options,
|
|
46450
|
+
"up:mysql"
|
|
46451
|
+
);
|
|
46452
|
+
if (!collisionRes.success) {
|
|
46453
|
+
console.log(collisionRes.message);
|
|
46454
|
+
process.exit(1);
|
|
46455
|
+
}
|
|
46687
46456
|
const params = checkSchema.parse(options);
|
|
46688
46457
|
const out = await assertOutFolder(params);
|
|
46689
46458
|
await assertPackages("drizzle-orm");
|
|
@@ -46694,36 +46463,36 @@ var upMysqlCommand = new import_commander.Command("up:mysql").option("--out <out
|
|
|
46694
46463
|
var upSqliteCommand = new import_commander.Command("up:sqlite").option("--out <out>", `Output folder`).option("--config <config>", `Config path [default=drizzle.config.ts]`).action(async (options) => {
|
|
46695
46464
|
await printVersions();
|
|
46696
46465
|
await assertOrmCoreVersion();
|
|
46466
|
+
const collisionRes = checkCollisions(
|
|
46467
|
+
options,
|
|
46468
|
+
"up:sqlite"
|
|
46469
|
+
);
|
|
46470
|
+
if (!collisionRes.success) {
|
|
46471
|
+
console.log(collisionRes.message);
|
|
46472
|
+
process.exit(1);
|
|
46473
|
+
}
|
|
46697
46474
|
const params = checkSchema.parse(options);
|
|
46698
46475
|
const out = await assertOutFolder(params);
|
|
46699
46476
|
upSqliteHandlerV4(out);
|
|
46700
46477
|
upgradeFolders("sqlite", out);
|
|
46701
46478
|
upSqliteHandler(out);
|
|
46702
46479
|
});
|
|
46703
|
-
var
|
|
46704
|
-
|
|
46705
|
-
|
|
46706
|
-
|
|
46707
|
-
var introspectPgCommand = new import_commander.Command("introspect:pg").option("--out <out>", `Migrations folder`).option("--breakpoints", `Prepare SQL statements with breakpoints`).option("--introspect-casing <introspectCasing>", "Column object keys naming strategy").option("--connectionString <connectionString>", "Postgres connection string").option("--host <host>", "Postgres host").option("--port <port>", "Postgres port").option("--user <user>", "Postgres user").option("--password <password>", "Postgres password").option("--database <database>", "Postgres database name").option("--ssl <ssl>", "Postgres ssl").option("--config <config>", `Config path [default=drizzle.config.ts]`).action(async (options) => {
|
|
46480
|
+
var introspectPgCommand = new import_commander.Command("introspect:pg").option("--out <out>", `Migrations folder`).option("--breakpoints", `Prepare SQL statements with breakpoints`).option(
|
|
46481
|
+
"--introspect-casing <introspectCasing>",
|
|
46482
|
+
"Column object keys naming strategy"
|
|
46483
|
+
).option("--driver <driver>", "Postgres connection string").option("--connectionString <connectionString>", "Postgres connection string").option("--host <host>", "Postgres host").option("--port <port>", "Postgres port").option("--user <user>", "Postgres user").option("--password <password>", "Postgres password").option("--database <database>", "Postgres database name").option("--ssl <ssl>", "Postgres ssl").option("--config <config>", `Config path [default=drizzle.config.ts]`).action(async (options) => {
|
|
46708
46484
|
await printVersions();
|
|
46709
46485
|
await assertPackages("drizzle-orm");
|
|
46710
46486
|
await assertOrmCoreVersion();
|
|
46711
|
-
const { pgIntrospect: pgIntrospect2
|
|
46712
|
-
const
|
|
46713
|
-
|
|
46714
|
-
|
|
46715
|
-
|
|
46716
|
-
|
|
46717
|
-
const
|
|
46718
|
-
|
|
46719
|
-
|
|
46720
|
-
console.log(issue.message);
|
|
46721
|
-
}
|
|
46722
|
-
return;
|
|
46723
|
-
}
|
|
46724
|
-
const { snapshots, journal } = prepareOutFolder2(res.data.out, "pg");
|
|
46725
|
-
const { schema: schema4, ts } = await pgIntrospect2(res.data);
|
|
46726
|
-
const schemaFile = import_path7.default.join(res.data.out, "schema.ts");
|
|
46487
|
+
const { pgIntrospect: pgIntrospect2 } = await Promise.resolve().then(() => (init_pgIntrospect(), pgIntrospect_exports));
|
|
46488
|
+
const validatedConfig = await validatePgIntrospect(
|
|
46489
|
+
options
|
|
46490
|
+
);
|
|
46491
|
+
const { snapshots, journal } = prepareOutFolder2(validatedConfig.out, "pg");
|
|
46492
|
+
const filterConfig = validatedConfig.tablesFilter;
|
|
46493
|
+
const tablesFilter = filterConfig ? typeof filterConfig === "string" ? [filterConfig] : filterConfig : [];
|
|
46494
|
+
const { schema: schema4, ts } = await pgIntrospect2(validatedConfig, tablesFilter);
|
|
46495
|
+
const schemaFile = import_path7.default.join(validatedConfig.out, "schema.ts");
|
|
46727
46496
|
(0, import_fs11.writeFileSync)(schemaFile, ts);
|
|
46728
46497
|
console.log();
|
|
46729
46498
|
if (snapshots.length === 0) {
|
|
@@ -46739,18 +46508,18 @@ var introspectPgCommand = new import_commander.Command("introspect:pg").option("
|
|
|
46739
46508
|
sqlStatements,
|
|
46740
46509
|
journal,
|
|
46741
46510
|
_meta,
|
|
46742
|
-
|
|
46743
|
-
|
|
46511
|
+
validatedConfig.out,
|
|
46512
|
+
validatedConfig.breakpoints,
|
|
46744
46513
|
"introspect"
|
|
46745
46514
|
);
|
|
46746
46515
|
} else {
|
|
46747
|
-
(0,
|
|
46516
|
+
(0, import_hanji8.render)(
|
|
46748
46517
|
`[${source_default.blue(
|
|
46749
46518
|
"i"
|
|
46750
46519
|
)}] No SQL generated, you already have migrations in project`
|
|
46751
46520
|
);
|
|
46752
46521
|
}
|
|
46753
|
-
(0,
|
|
46522
|
+
(0, import_hanji8.render)(
|
|
46754
46523
|
`[${source_default.green(
|
|
46755
46524
|
"\u2713"
|
|
46756
46525
|
)}] You schema file is ready \u279C ${source_default.bold.underline.blue(
|
|
@@ -46762,22 +46531,20 @@ var introspectPgCommand = new import_commander.Command("introspect:pg").option("
|
|
|
46762
46531
|
var introspectMySqlCommand = new import_commander.Command("introspect:mysql").option(
|
|
46763
46532
|
"--config <config>",
|
|
46764
46533
|
"Path to a config.json file, drizzle.config.json by default"
|
|
46534
|
+
).option(
|
|
46535
|
+
"--introspect-casing <introspectCasing>",
|
|
46536
|
+
"Column object keys naming strategy"
|
|
46765
46537
|
).option("--out <out>", `Migrations folder`).option("--breakpoints", `Prepare SQL statements with breakpoints`).option("--connectionString <connectionString>", "MySQL connection string").option("--host <host>", "MySQL host").option("--port <port>", "MySQL port").option("--user <user>", "MySQL user").option("--password <password>", "MySQL password").option("--database <database>", "MySQL database name").action(async (options) => {
|
|
46766
46538
|
await printVersions();
|
|
46767
46539
|
await assertPackages("drizzle-orm");
|
|
46768
46540
|
await assertOrmCoreVersion();
|
|
46769
46541
|
const { mysqlIntrospect: mysqlIntrospect2 } = await Promise.resolve().then(() => (init_mysqlIntrospect(), mysqlIntrospect_exports));
|
|
46770
|
-
const
|
|
46771
|
-
const
|
|
46772
|
-
if (!res.success) {
|
|
46773
|
-
for (const issue of res.error.issues) {
|
|
46774
|
-
console.log(issue.message);
|
|
46775
|
-
}
|
|
46776
|
-
process.exit(1);
|
|
46777
|
-
}
|
|
46778
|
-
const out = res.data.out;
|
|
46542
|
+
const res = await validateMySqlIntrospect(options);
|
|
46543
|
+
const out = res.out;
|
|
46779
46544
|
const { snapshots, journal } = prepareOutFolder2(out, "mysql");
|
|
46780
|
-
const
|
|
46545
|
+
const filterConfig = res.tablesFilter;
|
|
46546
|
+
const tablesFilter = filterConfig ? typeof filterConfig === "string" ? [filterConfig] : filterConfig : [];
|
|
46547
|
+
const { schema: schema4, ts } = await mysqlIntrospect2(res, tablesFilter);
|
|
46781
46548
|
const schemaFile = import_path7.default.join(out, "schema.ts");
|
|
46782
46549
|
(0, import_fs11.writeFileSync)(schemaFile, ts);
|
|
46783
46550
|
console.log();
|
|
@@ -46795,17 +46562,17 @@ var introspectMySqlCommand = new import_commander.Command("introspect:mysql").op
|
|
|
46795
46562
|
journal,
|
|
46796
46563
|
_meta,
|
|
46797
46564
|
out,
|
|
46798
|
-
res.
|
|
46565
|
+
res.breakpoints ?? false,
|
|
46799
46566
|
"introspect"
|
|
46800
46567
|
);
|
|
46801
46568
|
} else {
|
|
46802
|
-
(0,
|
|
46569
|
+
(0, import_hanji8.render)(
|
|
46803
46570
|
`[${source_default.blue(
|
|
46804
46571
|
"i"
|
|
46805
46572
|
)}] No SQL generated, you already have migrations in project`
|
|
46806
46573
|
);
|
|
46807
46574
|
}
|
|
46808
|
-
(0,
|
|
46575
|
+
(0, import_hanji8.render)(
|
|
46809
46576
|
`[${source_default.green(
|
|
46810
46577
|
"\u2713"
|
|
46811
46578
|
)}] You schema file is ready \u279C ${source_default.bold.underline.blue(
|
|
@@ -46817,15 +46584,20 @@ var introspectMySqlCommand = new import_commander.Command("introspect:mysql").op
|
|
|
46817
46584
|
var introspectSQLiteCommand = new import_commander.Command("introspect:sqlite").option(
|
|
46818
46585
|
"--config <config>",
|
|
46819
46586
|
"Path to a config.json file, drizzle.config.json by default"
|
|
46587
|
+
).option(
|
|
46588
|
+
"--introspect-casing <introspectCasing>",
|
|
46589
|
+
"Column object keys naming strategy"
|
|
46820
46590
|
).option("--schema <schema>", `Migrations folder`).option("--out <out>", `Migrations folder`).option("--breakpoints", `Prepare SQL statements with breakpoints`).option("--driver <driver>", "SQLite database path").option("--url <url>", "SQLite database url").option("--auth-token <authToken>", "SQLite database path").action(async (options) => {
|
|
46821
46591
|
printVersions();
|
|
46822
46592
|
assertPackages("drizzle-orm");
|
|
46823
46593
|
assertOrmCoreVersion();
|
|
46824
46594
|
const { sqliteIntrospect: sqliteIntrospect2 } = await Promise.resolve().then(() => (init_sqliteIntrospect(), sqliteIntrospect_exports));
|
|
46825
|
-
const res = validateIntrospect(options);
|
|
46595
|
+
const res = await validateIntrospect(options);
|
|
46826
46596
|
const out = res.out;
|
|
46827
46597
|
const { snapshots, journal } = prepareOutFolder2(out, "sqlite");
|
|
46828
|
-
const
|
|
46598
|
+
const filterConfig = res.tablesFilter;
|
|
46599
|
+
const tablesFilter = filterConfig ? typeof filterConfig === "string" ? [filterConfig] : filterConfig : [];
|
|
46600
|
+
const { schema: schema4, ts } = await sqliteIntrospect2(res, tablesFilter);
|
|
46829
46601
|
const schemaFile = import_path7.default.join(out, "schema.ts");
|
|
46830
46602
|
(0, import_fs11.writeFileSync)(schemaFile, ts);
|
|
46831
46603
|
console.log();
|
|
@@ -46847,13 +46619,13 @@ var introspectSQLiteCommand = new import_commander.Command("introspect:sqlite").
|
|
|
46847
46619
|
"introspect"
|
|
46848
46620
|
);
|
|
46849
46621
|
} else {
|
|
46850
|
-
(0,
|
|
46622
|
+
(0, import_hanji8.render)(
|
|
46851
46623
|
`[${source_default.blue(
|
|
46852
46624
|
"i"
|
|
46853
46625
|
)}] No SQL generated, you already have migrations in project`
|
|
46854
46626
|
);
|
|
46855
46627
|
}
|
|
46856
|
-
(0,
|
|
46628
|
+
(0, import_hanji8.render)(
|
|
46857
46629
|
`[${source_default.green(
|
|
46858
46630
|
"\u2713"
|
|
46859
46631
|
)}] You schema file is ready \u279C ${source_default.bold.underline.blue(
|
|
@@ -46865,10 +46637,18 @@ var introspectSQLiteCommand = new import_commander.Command("introspect:sqlite").
|
|
|
46865
46637
|
var dropCommand = new import_commander.Command("drop").option("--out <out>", `Output folder`).option("--config <config>", `Config path [default=drizzle.config.json]`).action(async (options) => {
|
|
46866
46638
|
await printVersions();
|
|
46867
46639
|
await assertOrmCoreVersion();
|
|
46640
|
+
const collisionRes = checkCollisions(
|
|
46641
|
+
options,
|
|
46642
|
+
"drop"
|
|
46643
|
+
);
|
|
46644
|
+
if (!collisionRes.success) {
|
|
46645
|
+
console.log(collisionRes.message);
|
|
46646
|
+
process.exit(1);
|
|
46647
|
+
}
|
|
46868
46648
|
const params = checkSchema.parse(options);
|
|
46869
46649
|
const out = await assertOutFolder(params);
|
|
46870
46650
|
assertV1OutFolder(out, "{dialect}");
|
|
46871
|
-
dropMigration(out);
|
|
46651
|
+
await dropMigration(out);
|
|
46872
46652
|
});
|
|
46873
46653
|
var main = async () => {
|
|
46874
46654
|
const version2 = await versions();
|
|
@@ -46887,6 +46667,7 @@ var main = async () => {
|
|
|
46887
46667
|
import_commander.program.addCommand(dbPushMysqlCommand);
|
|
46888
46668
|
import_commander.program.addCommand(introspectSQLiteCommand);
|
|
46889
46669
|
import_commander.program.addCommand(dbPushSqliteCommand);
|
|
46670
|
+
import_commander.program.addCommand(checkMySqlCommand);
|
|
46890
46671
|
import_commander.program.parse();
|
|
46891
46672
|
};
|
|
46892
46673
|
main();
|