prisma-sql 1.2.0 → 1.4.0
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/generator.cjs +4657 -0
- package/dist/generator.cjs.map +1 -0
- package/dist/generator.d.mts +2 -0
- package/dist/generator.d.ts +2 -0
- package/dist/generator.js +4655 -0
- package/dist/generator.js.map +1 -0
- package/dist/index.cjs +21 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +18 -22
- package/dist/index.js.map +1 -1
- package/package.json +11 -3
- package/readme.md +111 -161
package/dist/index.cjs
CHANGED
|
@@ -4228,7 +4228,6 @@ function finalizeDirective(args) {
|
|
|
4228
4228
|
staticParams,
|
|
4229
4229
|
dynamicKeys,
|
|
4230
4230
|
paramMappings: normalizedMappings,
|
|
4231
|
-
cache: directive.cache,
|
|
4232
4231
|
originalDirective: directive
|
|
4233
4232
|
};
|
|
4234
4233
|
}
|
|
@@ -4297,8 +4296,6 @@ function transformQueryResults(method, results) {
|
|
|
4297
4296
|
const transformer = RESULT_TRANSFORMERS[method];
|
|
4298
4297
|
return transformer ? transformer(results) : results;
|
|
4299
4298
|
}
|
|
4300
|
-
|
|
4301
|
-
// src/index.ts
|
|
4302
4299
|
var ACCELERATED_METHODS = /* @__PURE__ */ new Set([
|
|
4303
4300
|
"findMany",
|
|
4304
4301
|
"findFirst",
|
|
@@ -4498,9 +4495,9 @@ function speedExtension(config) {
|
|
|
4498
4495
|
const {
|
|
4499
4496
|
postgres,
|
|
4500
4497
|
sqlite,
|
|
4501
|
-
|
|
4498
|
+
models,
|
|
4502
4499
|
debug = false,
|
|
4503
|
-
|
|
4500
|
+
allowedModels,
|
|
4504
4501
|
onQuery
|
|
4505
4502
|
} = config;
|
|
4506
4503
|
if (!postgres && !sqlite) {
|
|
@@ -4511,29 +4508,23 @@ function speedExtension(config) {
|
|
|
4511
4508
|
"speedExtension cannot use both postgres and sqlite clients"
|
|
4512
4509
|
);
|
|
4513
4510
|
}
|
|
4511
|
+
if (!models || !Array.isArray(models) || models.length === 0) {
|
|
4512
|
+
throw new Error(
|
|
4513
|
+
"speedExtension requires models parameter. Convert DMMF first: speedExtension({ models: convertDMMFToModels(Prisma.dmmf.datamodel) })"
|
|
4514
|
+
);
|
|
4515
|
+
}
|
|
4514
4516
|
const dialect = postgres ? "postgres" : "sqlite";
|
|
4515
4517
|
const client = postgres || sqlite;
|
|
4516
4518
|
setGlobalDialect(dialect);
|
|
4517
4519
|
return (prisma) => {
|
|
4518
|
-
|
|
4519
|
-
let dmmf = providedDmmf;
|
|
4520
|
-
if (!dmmf) {
|
|
4521
|
-
dmmf = prisma._dmmf || ((_a = prisma._engineConfig) == null ? void 0 : _a.document) || prisma._baseDmmf;
|
|
4522
|
-
if (!(dmmf == null ? void 0 : dmmf.datamodel)) {
|
|
4523
|
-
throw new Error(
|
|
4524
|
-
"Cannot access Prisma DMMF. Please provide dmmf in config: speedExtension({ postgres: sql, dmmf: Prisma.dmmf })"
|
|
4525
|
-
);
|
|
4526
|
-
}
|
|
4527
|
-
}
|
|
4528
|
-
const allModels = schemaParser.convertDMMFToModels(dmmf.datamodel);
|
|
4529
|
-
const modelMap = new Map(allModels.map((m) => [m.name, m]));
|
|
4520
|
+
const modelMap = new Map(models.map((m) => [m.name, m]));
|
|
4530
4521
|
const executeQuery = createExecuteQuery(client, dialect);
|
|
4531
4522
|
const deps = {
|
|
4532
4523
|
dialect,
|
|
4533
4524
|
debug,
|
|
4534
4525
|
onQuery,
|
|
4535
4526
|
allowedModels,
|
|
4536
|
-
allModels,
|
|
4527
|
+
allModels: models,
|
|
4537
4528
|
modelMap,
|
|
4538
4529
|
executeQuery
|
|
4539
4530
|
};
|
|
@@ -4560,6 +4551,9 @@ function speedExtension(config) {
|
|
|
4560
4551
|
};
|
|
4561
4552
|
}
|
|
4562
4553
|
function createToSQLFunction(models, dialect) {
|
|
4554
|
+
if (!models || !Array.isArray(models) || models.length === 0) {
|
|
4555
|
+
throw new Error("createToSQL requires non-empty models array");
|
|
4556
|
+
}
|
|
4563
4557
|
const modelMap = new Map(models.map((m) => [m.name, m]));
|
|
4564
4558
|
setGlobalDialect(dialect);
|
|
4565
4559
|
return function toSQL(model, method, args = {}) {
|
|
@@ -4572,13 +4566,14 @@ function createToSQLFunction(models, dialect) {
|
|
|
4572
4566
|
return buildSQL(m, models, method, args, dialect);
|
|
4573
4567
|
};
|
|
4574
4568
|
}
|
|
4575
|
-
function createToSQL(
|
|
4576
|
-
const models = schemaParser.convertDMMFToModels(dmmf.datamodel);
|
|
4569
|
+
function createToSQL(models, dialect) {
|
|
4577
4570
|
return createToSQLFunction(models, dialect);
|
|
4578
4571
|
}
|
|
4579
4572
|
function createPrismaSQL(config) {
|
|
4580
|
-
const { client,
|
|
4581
|
-
|
|
4573
|
+
const { client, models, dialect, execute } = config;
|
|
4574
|
+
if (!models || !Array.isArray(models) || models.length === 0) {
|
|
4575
|
+
throw new Error("createPrismaSQL requires non-empty models array");
|
|
4576
|
+
}
|
|
4582
4577
|
const toSQL = createToSQLFunction(models, dialect);
|
|
4583
4578
|
function query(_0, _1) {
|
|
4584
4579
|
return __async(this, arguments, function* (model, method, args = {}) {
|
|
@@ -4628,6 +4623,10 @@ function generateSQLByModel(directives) {
|
|
|
4628
4623
|
return byModel;
|
|
4629
4624
|
}
|
|
4630
4625
|
|
|
4626
|
+
Object.defineProperty(exports, "convertDMMFToModels", {
|
|
4627
|
+
enumerable: true,
|
|
4628
|
+
get: function () { return schemaParser.convertDMMFToModels; }
|
|
4629
|
+
});
|
|
4631
4630
|
exports.createPrismaSQL = createPrismaSQL;
|
|
4632
4631
|
exports.createToSQL = createToSQL;
|
|
4633
4632
|
exports.generateAllSQL = generateAllSQL;
|