prisma-sql 1.75.7 → 1.75.9
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/dist/collect-planner-stats.cjs +15 -25
- package/dist/collect-planner-stats.cjs.map +1 -1
- package/dist/collect-planner-stats.js +15 -25
- package/dist/collect-planner-stats.js.map +1 -1
- package/dist/generator.cjs +77 -83
- package/dist/generator.cjs.map +1 -1
- package/dist/generator.js +77 -83
- package/dist/generator.js.map +1 -1
- package/package.json +1 -1
package/dist/generator.js
CHANGED
|
@@ -68,7 +68,7 @@ var require_package = __commonJS({
|
|
|
68
68
|
"package.json"(exports$1, module) {
|
|
69
69
|
module.exports = {
|
|
70
70
|
name: "prisma-sql",
|
|
71
|
-
version: "1.75.
|
|
71
|
+
version: "1.75.9",
|
|
72
72
|
description: "Convert Prisma queries to optimized SQL with type safety. 2-7x faster than Prisma Client.",
|
|
73
73
|
main: "dist/index.cjs",
|
|
74
74
|
module: "dist/index.js",
|
|
@@ -7287,25 +7287,6 @@ function stableJson(value) {
|
|
|
7287
7287
|
2
|
|
7288
7288
|
);
|
|
7289
7289
|
}
|
|
7290
|
-
function cleanDatabaseUrl(url) {
|
|
7291
|
-
try {
|
|
7292
|
-
const parsed = new URL(url);
|
|
7293
|
-
parsed.search = "";
|
|
7294
|
-
if (parsed.password) {
|
|
7295
|
-
parsed.password = "***";
|
|
7296
|
-
}
|
|
7297
|
-
if (parsed.username && parsed.username.length > 0) {
|
|
7298
|
-
if (parsed.username.length <= 3) {
|
|
7299
|
-
parsed.username = "***";
|
|
7300
|
-
} else {
|
|
7301
|
-
parsed.username = parsed.username.slice(0, 3) + "***";
|
|
7302
|
-
}
|
|
7303
|
-
}
|
|
7304
|
-
return parsed.toString();
|
|
7305
|
-
} catch (error) {
|
|
7306
|
-
return "[invalid-url]";
|
|
7307
|
-
}
|
|
7308
|
-
}
|
|
7309
7290
|
function createQueryKey(processedQuery) {
|
|
7310
7291
|
return JSON.stringify(processedQuery, (key, value) => {
|
|
7311
7292
|
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
@@ -7332,17 +7313,19 @@ function countTotalQueries(queries) {
|
|
|
7332
7313
|
function quoteIdent(dialect, ident) {
|
|
7333
7314
|
return `"${ident.replace(/"/g, '""')}"`;
|
|
7334
7315
|
}
|
|
7335
|
-
function createDatabaseExecutor(
|
|
7316
|
+
function createDatabaseExecutor(options) {
|
|
7336
7317
|
return __async(this, null, function* () {
|
|
7337
|
-
const { databaseUrl, dialect } =
|
|
7318
|
+
const { databaseUrl, dialect, connectTimeoutMs = 3e4 } = options;
|
|
7338
7319
|
if (dialect === "postgres") {
|
|
7339
7320
|
const postgres = yield import('postgres');
|
|
7340
|
-
|
|
7341
|
-
|
|
7321
|
+
const sql = postgres.default(databaseUrl, {
|
|
7322
|
+
connect_timeout: Math.ceil(connectTimeoutMs / 1e3),
|
|
7323
|
+
max: 1
|
|
7324
|
+
});
|
|
7342
7325
|
return {
|
|
7343
7326
|
executor: {
|
|
7344
|
-
query: (
|
|
7345
|
-
return yield sql.unsafe(
|
|
7327
|
+
query: (q, params) => __async(null, null, function* () {
|
|
7328
|
+
return yield sql.unsafe(q, params != null ? params : []);
|
|
7346
7329
|
})
|
|
7347
7330
|
},
|
|
7348
7331
|
cleanup: () => __async(null, null, function* () {
|
|
@@ -7350,7 +7333,7 @@ function createDatabaseExecutor(params) {
|
|
|
7350
7333
|
})
|
|
7351
7334
|
};
|
|
7352
7335
|
}
|
|
7353
|
-
throw new Error(`
|
|
7336
|
+
throw new Error(`createDatabaseExecutor does not support dialect: ${dialect}`);
|
|
7354
7337
|
});
|
|
7355
7338
|
}
|
|
7356
7339
|
function extractMeasurableOneToManyEdges(datamodel) {
|
|
@@ -7821,6 +7804,7 @@ function emitPlannerGeneratedModule(artifacts) {
|
|
|
7821
7804
|
}
|
|
7822
7805
|
|
|
7823
7806
|
// src/code-emitter.ts
|
|
7807
|
+
var DB_CONNECT_TIMEOUT_MS = 5e3;
|
|
7824
7808
|
function extractEnumMappings(datamodel) {
|
|
7825
7809
|
const mappings = {};
|
|
7826
7810
|
const fieldTypes = {};
|
|
@@ -7891,7 +7875,6 @@ function processAllModelDirectives(directiveResults, config) {
|
|
|
7891
7875
|
}
|
|
7892
7876
|
return { queries, skippedCount };
|
|
7893
7877
|
}
|
|
7894
|
-
var DB_CONNECT_TIMEOUT_MS = 5e3;
|
|
7895
7878
|
function generateClient(options) {
|
|
7896
7879
|
return __async(this, null, function* () {
|
|
7897
7880
|
var _a3;
|
|
@@ -7912,61 +7895,17 @@ function generateClient(options) {
|
|
|
7912
7895
|
yield mkdir(absoluteOutputDir, { recursive: true });
|
|
7913
7896
|
let plannerArtifacts = options.plannerArtifacts;
|
|
7914
7897
|
if (!plannerArtifacts) {
|
|
7915
|
-
|
|
7916
|
-
|
|
7917
|
-
|
|
7918
|
-
|
|
7919
|
-
|
|
7920
|
-
|
|
7921
|
-
|
|
7922
|
-
|
|
7923
|
-
|
|
7924
|
-
|
|
7925
|
-
|
|
7926
|
-
)
|
|
7927
|
-
);
|
|
7928
|
-
}, DB_CONNECT_TIMEOUT_MS);
|
|
7929
|
-
(_a4 = id.unref) == null ? void 0 : _a4.call(id);
|
|
7930
|
-
});
|
|
7931
|
-
try {
|
|
7932
|
-
const dbConn = yield Promise.race([
|
|
7933
|
-
createDatabaseExecutor({
|
|
7934
|
-
databaseUrl: datasourceUrl,
|
|
7935
|
-
dialect: config.dialect
|
|
7936
|
-
}),
|
|
7937
|
-
timeoutHandle
|
|
7938
|
-
]);
|
|
7939
|
-
if (!timedOut) {
|
|
7940
|
-
executor = dbConn.executor;
|
|
7941
|
-
cleanup = dbConn.cleanup;
|
|
7942
|
-
}
|
|
7943
|
-
} catch (error) {
|
|
7944
|
-
console.warn(
|
|
7945
|
-
"\u26A0 Failed to connect:",
|
|
7946
|
-
error instanceof Error ? error.message : error
|
|
7947
|
-
);
|
|
7948
|
-
}
|
|
7949
|
-
}
|
|
7950
|
-
if (executor) {
|
|
7951
|
-
try {
|
|
7952
|
-
console.log(
|
|
7953
|
-
"\u{1F4CA} Collecting relation cardinalities and roundtrip cost..."
|
|
7954
|
-
);
|
|
7955
|
-
plannerArtifacts = yield collectPlannerArtifacts({
|
|
7956
|
-
executor,
|
|
7957
|
-
datamodel,
|
|
7958
|
-
dialect: config.dialect
|
|
7959
|
-
});
|
|
7960
|
-
} catch (error) {
|
|
7961
|
-
console.warn(
|
|
7962
|
-
"\u26A0 Failed to collect stats:",
|
|
7963
|
-
error instanceof Error ? error.message : error
|
|
7964
|
-
);
|
|
7965
|
-
} finally {
|
|
7966
|
-
if (cleanup) {
|
|
7967
|
-
yield cleanup();
|
|
7968
|
-
}
|
|
7969
|
-
}
|
|
7898
|
+
const skipPlanner = process.env.PRISMA_SQL_SKIP_PLANNER === "1" || process.env.PRISMA_SQL_SKIP_PLANNER === "true";
|
|
7899
|
+
if (skipPlanner) {
|
|
7900
|
+
console.log(
|
|
7901
|
+
"\u23ED Skipping planner stats collection (PRISMA_SQL_SKIP_PLANNER)"
|
|
7902
|
+
);
|
|
7903
|
+
} else {
|
|
7904
|
+
plannerArtifacts = yield collectPlannerWithTimeout(
|
|
7905
|
+
options,
|
|
7906
|
+
config,
|
|
7907
|
+
datasourceUrl
|
|
7908
|
+
);
|
|
7970
7909
|
}
|
|
7971
7910
|
}
|
|
7972
7911
|
if (!plannerArtifacts) {
|
|
@@ -7998,6 +7937,61 @@ function generateClient(options) {
|
|
|
7998
7937
|
console.log(`\u2713 Output: ${outputPath}`);
|
|
7999
7938
|
});
|
|
8000
7939
|
}
|
|
7940
|
+
var PLANNER_TOTAL_TIMEOUT_MS = 15e3;
|
|
7941
|
+
function collectPlannerWithTimeout(options, config, datasourceUrl) {
|
|
7942
|
+
return __async(this, null, function* () {
|
|
7943
|
+
const timeoutMs = Number(process.env.PRISMA_SQL_PLANNER_TIMEOUT_MS) || PLANNER_TOTAL_TIMEOUT_MS;
|
|
7944
|
+
let cleanup;
|
|
7945
|
+
let settled = false;
|
|
7946
|
+
const work = () => __async(null, null, function* () {
|
|
7947
|
+
let executor = options.executor;
|
|
7948
|
+
if (!executor && datasourceUrl) {
|
|
7949
|
+
const dbConn = yield createDatabaseExecutor({
|
|
7950
|
+
databaseUrl: datasourceUrl,
|
|
7951
|
+
dialect: config.dialect,
|
|
7952
|
+
connectTimeoutMs: DB_CONNECT_TIMEOUT_MS
|
|
7953
|
+
});
|
|
7954
|
+
executor = dbConn.executor;
|
|
7955
|
+
cleanup = dbConn.cleanup;
|
|
7956
|
+
}
|
|
7957
|
+
if (!executor) return void 0;
|
|
7958
|
+
console.log("\u{1F4CA} Collecting relation cardinalities and roundtrip cost...");
|
|
7959
|
+
return yield collectPlannerArtifacts({
|
|
7960
|
+
executor,
|
|
7961
|
+
datamodel: options.datamodel,
|
|
7962
|
+
dialect: config.dialect
|
|
7963
|
+
});
|
|
7964
|
+
});
|
|
7965
|
+
const timeout = new Promise((resolve3) => {
|
|
7966
|
+
const id = setTimeout(() => {
|
|
7967
|
+
settled = true;
|
|
7968
|
+
console.warn(
|
|
7969
|
+
`\u26A0 Planner stats collection timed out after ${timeoutMs}ms, using defaults`
|
|
7970
|
+
);
|
|
7971
|
+
resolve3(void 0);
|
|
7972
|
+
}, timeoutMs);
|
|
7973
|
+
if (typeof id === "object" && "unref" in id) id.unref();
|
|
7974
|
+
});
|
|
7975
|
+
try {
|
|
7976
|
+
const result = yield Promise.race([work(), timeout]);
|
|
7977
|
+
if (settled) return void 0;
|
|
7978
|
+
return result;
|
|
7979
|
+
} catch (error) {
|
|
7980
|
+
if (!settled) {
|
|
7981
|
+
console.warn(
|
|
7982
|
+
"\u26A0 Failed to collect planner stats:",
|
|
7983
|
+
error instanceof Error ? error.message : error
|
|
7984
|
+
);
|
|
7985
|
+
}
|
|
7986
|
+
return void 0;
|
|
7987
|
+
} finally {
|
|
7988
|
+
if (cleanup) {
|
|
7989
|
+
yield cleanup().catch(() => {
|
|
7990
|
+
});
|
|
7991
|
+
}
|
|
7992
|
+
}
|
|
7993
|
+
});
|
|
7994
|
+
}
|
|
8001
7995
|
function generateImports(runtimeImportPath) {
|
|
8002
7996
|
return `import {
|
|
8003
7997
|
buildSQL,
|