prisma-sql 1.76.2 → 1.78.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 +61 -4
- package/dist/generator.cjs.map +1 -1
- package/dist/generator.js +61 -4
- package/dist/generator.js.map +1 -1
- package/dist/index.cjs +38 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +38 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/readme.md +59 -76
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.
|
|
71
|
+
version: "1.78.0",
|
|
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",
|
|
@@ -6285,6 +6285,31 @@ function normalizeArgsForDialect(dialect, args) {
|
|
|
6285
6285
|
if (dialect !== "postgres") return args;
|
|
6286
6286
|
return applyPostgresDistinctOrderBy(args);
|
|
6287
6287
|
}
|
|
6288
|
+
function normalizeCompoundCursor(cursor, model) {
|
|
6289
|
+
const keys = Object.keys(cursor);
|
|
6290
|
+
if (keys.length !== 1) return cursor;
|
|
6291
|
+
const key = keys[0];
|
|
6292
|
+
const value = cursor[key];
|
|
6293
|
+
const scalarSet = getScalarFieldSet(model);
|
|
6294
|
+
if (scalarSet.has(key)) return cursor;
|
|
6295
|
+
if (!isPlainObject(value)) return cursor;
|
|
6296
|
+
const nested = value;
|
|
6297
|
+
const nestedKeys = Object.keys(nested);
|
|
6298
|
+
if (nestedKeys.length === 0) return cursor;
|
|
6299
|
+
for (const nk of nestedKeys) {
|
|
6300
|
+
if (!scalarSet.has(nk)) return cursor;
|
|
6301
|
+
}
|
|
6302
|
+
return nested;
|
|
6303
|
+
}
|
|
6304
|
+
function normalizeArgsCompoundCursor(args, model) {
|
|
6305
|
+
if (!isNotNullish(args.cursor) || !isPlainObject(args.cursor)) return args;
|
|
6306
|
+
const flat = normalizeCompoundCursor(
|
|
6307
|
+
args.cursor,
|
|
6308
|
+
model
|
|
6309
|
+
);
|
|
6310
|
+
if (flat === args.cursor) return args;
|
|
6311
|
+
return __spreadProps(__spreadValues({}, args), { cursor: flat });
|
|
6312
|
+
}
|
|
6288
6313
|
function buildCursorClauseIfAny(input) {
|
|
6289
6314
|
const { cursor, orderBy, tableName, alias, params, skip, dialect, model } = input;
|
|
6290
6315
|
if (!isNotNullish(cursor)) return {};
|
|
@@ -6382,7 +6407,8 @@ function buildSelectSql(input) {
|
|
|
6382
6407
|
assertSafeTableRef(from.tableName);
|
|
6383
6408
|
const dialectToUse = resolveDialect(dialect);
|
|
6384
6409
|
const argsForSql = normalizeArgsForNegativeTake(method, args);
|
|
6385
|
-
const
|
|
6410
|
+
const argsWithDialect = normalizeArgsForDialect(dialectToUse, argsForSql);
|
|
6411
|
+
const normalizedArgs = normalizeArgsCompoundCursor(argsWithDialect, model);
|
|
6386
6412
|
validateDistinct(model, normalizedArgs.distinct);
|
|
6387
6413
|
validateOrderBy(model, normalizedArgs.orderBy);
|
|
6388
6414
|
validateCursor(model, normalizedArgs.cursor, normalizedArgs.distinct);
|
|
@@ -7833,6 +7859,23 @@ function resolveParamsFromMappings(args: any, paramMappings: any[]): unknown[] {
|
|
|
7833
7859
|
params.push(normalizeValue(value))
|
|
7834
7860
|
}
|
|
7835
7861
|
return params
|
|
7862
|
+
}
|
|
7863
|
+
|
|
7864
|
+
function normalizeCompoundCursor(cursor: any, model: any): any {
|
|
7865
|
+
if (!cursor || typeof cursor !== 'object' || Array.isArray(cursor) || cursor instanceof Date) return cursor
|
|
7866
|
+
const keys = Object.keys(cursor)
|
|
7867
|
+
if (keys.length !== 1) return cursor
|
|
7868
|
+
const key = keys[0]
|
|
7869
|
+
const value = cursor[key]
|
|
7870
|
+
if (!value || typeof value !== 'object' || Array.isArray(value) || value instanceof Date) return cursor
|
|
7871
|
+
const scalarSet = new Set(model.fields.filter((f: any) => !f.isRelation).map((f: any) => f.name))
|
|
7872
|
+
if (scalarSet.has(key)) return cursor
|
|
7873
|
+
const nestedKeys = Object.keys(value)
|
|
7874
|
+
if (nestedKeys.length === 0) return cursor
|
|
7875
|
+
for (const nk of nestedKeys) {
|
|
7876
|
+
if (!scalarSet.has(nk)) return cursor
|
|
7877
|
+
}
|
|
7878
|
+
return value
|
|
7836
7879
|
}`;
|
|
7837
7880
|
}
|
|
7838
7881
|
function generateDataConstants(cleanModels, mappings, fieldTypes, queries, dialect) {
|
|
@@ -8157,7 +8200,7 @@ function generateExtension(runtimeImportPath) {
|
|
|
8157
8200
|
)
|
|
8158
8201
|
}
|
|
8159
8202
|
|
|
8160
|
-
|
|
8203
|
+
let transformedArgs = transformEnumValuesByModel(modelName, args || {})
|
|
8161
8204
|
|
|
8162
8205
|
const model = MODEL_MAP.get(modelName)
|
|
8163
8206
|
if (!model) {
|
|
@@ -8167,6 +8210,13 @@ function generateExtension(runtimeImportPath) {
|
|
|
8167
8210
|
return this.$parent[modelName][method](args)
|
|
8168
8211
|
}
|
|
8169
8212
|
|
|
8213
|
+
if (transformedArgs.cursor) {
|
|
8214
|
+
const flatCursor = normalizeCompoundCursor(transformedArgs.cursor, model)
|
|
8215
|
+
if (flatCursor !== transformedArgs.cursor) {
|
|
8216
|
+
transformedArgs = { ...transformedArgs, cursor: flatCursor }
|
|
8217
|
+
}
|
|
8218
|
+
}
|
|
8219
|
+
|
|
8170
8220
|
const plan = planQueryStrategy({
|
|
8171
8221
|
model,
|
|
8172
8222
|
method,
|
|
@@ -8330,12 +8380,19 @@ function generateExtension(runtimeImportPath) {
|
|
|
8330
8380
|
throw new Error('Streaming requires postgres.js client')
|
|
8331
8381
|
}
|
|
8332
8382
|
|
|
8333
|
-
|
|
8383
|
+
let transformedArgs = transformEnumValuesByModel(modelName, args || {})
|
|
8334
8384
|
const model = MODEL_MAP.get(modelName)
|
|
8335
8385
|
if (!model) {
|
|
8336
8386
|
throw new Error(\`Model '\${modelName}' not found\`)
|
|
8337
8387
|
}
|
|
8338
8388
|
|
|
8389
|
+
if (transformedArgs.cursor) {
|
|
8390
|
+
const flatCursor = normalizeCompoundCursor(transformedArgs.cursor, model)
|
|
8391
|
+
if (flatCursor !== transformedArgs.cursor) {
|
|
8392
|
+
transformedArgs = { ...transformedArgs, cursor: flatCursor }
|
|
8393
|
+
}
|
|
8394
|
+
}
|
|
8395
|
+
|
|
8339
8396
|
const plan = planQueryStrategy({
|
|
8340
8397
|
model,
|
|
8341
8398
|
method: 'findMany',
|