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