@prisma/client-engine-runtime 7.1.0-dev.33 → 7.1.0-dev.35
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.d.mts +17 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +67 -6
- package/dist/index.mjs +66 -6
- package/dist/interpreter/query-interpreter.d.ts +8 -1
- package/dist/sql-commenter.d.ts +28 -0
- package/dist/sql-commenter.test.d.ts +1 -0
- package/package.json +5 -4
package/dist/index.d.mts
CHANGED
|
@@ -6,11 +6,20 @@ import { Decimal } from '@prisma/client-runtime-utils';
|
|
|
6
6
|
import type { IsolationLevel } from '@prisma/driver-adapter-utils';
|
|
7
7
|
import { Span } from '@opentelemetry/api';
|
|
8
8
|
import { SpanOptions } from '@opentelemetry/api';
|
|
9
|
+
import type { SqlCommenterContext } from '@prisma/sqlcommenter';
|
|
10
|
+
import type { SqlCommenterPlugin } from '@prisma/sqlcommenter';
|
|
11
|
+
import type { SqlCommenterQueryInfo } from '@prisma/sqlcommenter';
|
|
9
12
|
import { SqlDriverAdapter } from '@prisma/driver-adapter-utils';
|
|
10
13
|
import { SqlQueryable } from '@prisma/driver-adapter-utils';
|
|
11
14
|
import { SqlResultSet } from '@prisma/driver-adapter-utils';
|
|
12
15
|
import { Transaction } from '@prisma/driver-adapter-utils';
|
|
13
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Applies SQL commenter plugins and returns the merged key-value pairs.
|
|
19
|
+
* Keys with undefined values are filtered out.
|
|
20
|
+
*/
|
|
21
|
+
export declare function applySqlCommenters(plugins: SqlCommenterPlugin[], context: SqlCommenterContext): Record<string, string>;
|
|
22
|
+
|
|
14
23
|
export declare type BatchResponse = MultiBatchResponse | CompactedBatchResponse;
|
|
15
24
|
|
|
16
25
|
export declare type BigIntTaggedValue = {
|
|
@@ -234,7 +243,7 @@ export declare type QueryEvent = {
|
|
|
234
243
|
|
|
235
244
|
export declare class QueryInterpreter {
|
|
236
245
|
#private;
|
|
237
|
-
constructor({ transactionManager, placeholderValues, onQuery, tracingHelper, serializer, rawSerializer, provider, connectionInfo, }: QueryInterpreterOptions);
|
|
246
|
+
constructor({ transactionManager, placeholderValues, onQuery, tracingHelper, serializer, rawSerializer, provider, connectionInfo, sqlCommenter, }: QueryInterpreterOptions);
|
|
238
247
|
static forSql(options: {
|
|
239
248
|
transactionManager: QueryInterpreterTransactionManager;
|
|
240
249
|
placeholderValues: Record<string, unknown>;
|
|
@@ -242,6 +251,7 @@ export declare class QueryInterpreter {
|
|
|
242
251
|
tracingHelper: TracingHelper;
|
|
243
252
|
provider?: SchemaProvider;
|
|
244
253
|
connectionInfo?: ConnectionInfo;
|
|
254
|
+
sqlCommenter?: QueryInterpreterSqlCommenter;
|
|
245
255
|
}): QueryInterpreter;
|
|
246
256
|
run(queryPlan: QueryPlanNode, queryable: SqlQueryable): Promise<unknown>;
|
|
247
257
|
private interpretNode;
|
|
@@ -256,6 +266,12 @@ export declare type QueryInterpreterOptions = {
|
|
|
256
266
|
rawSerializer?: (results: SqlResultSet) => Value;
|
|
257
267
|
provider?: SchemaProvider;
|
|
258
268
|
connectionInfo?: ConnectionInfo;
|
|
269
|
+
sqlCommenter?: QueryInterpreterSqlCommenter;
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
export declare type QueryInterpreterSqlCommenter = {
|
|
273
|
+
plugins: SqlCommenterPlugin[];
|
|
274
|
+
queryInfo: SqlCommenterQueryInfo;
|
|
259
275
|
};
|
|
260
276
|
|
|
261
277
|
export declare type QueryInterpreterTransactionManager = {
|
package/dist/index.d.ts
CHANGED
|
@@ -6,11 +6,20 @@ import { Decimal } from '@prisma/client-runtime-utils';
|
|
|
6
6
|
import type { IsolationLevel } from '@prisma/driver-adapter-utils';
|
|
7
7
|
import { Span } from '@opentelemetry/api';
|
|
8
8
|
import { SpanOptions } from '@opentelemetry/api';
|
|
9
|
+
import type { SqlCommenterContext } from '@prisma/sqlcommenter';
|
|
10
|
+
import type { SqlCommenterPlugin } from '@prisma/sqlcommenter';
|
|
11
|
+
import type { SqlCommenterQueryInfo } from '@prisma/sqlcommenter';
|
|
9
12
|
import { SqlDriverAdapter } from '@prisma/driver-adapter-utils';
|
|
10
13
|
import { SqlQueryable } from '@prisma/driver-adapter-utils';
|
|
11
14
|
import { SqlResultSet } from '@prisma/driver-adapter-utils';
|
|
12
15
|
import { Transaction } from '@prisma/driver-adapter-utils';
|
|
13
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Applies SQL commenter plugins and returns the merged key-value pairs.
|
|
19
|
+
* Keys with undefined values are filtered out.
|
|
20
|
+
*/
|
|
21
|
+
export declare function applySqlCommenters(plugins: SqlCommenterPlugin[], context: SqlCommenterContext): Record<string, string>;
|
|
22
|
+
|
|
14
23
|
export declare type BatchResponse = MultiBatchResponse | CompactedBatchResponse;
|
|
15
24
|
|
|
16
25
|
export declare type BigIntTaggedValue = {
|
|
@@ -234,7 +243,7 @@ export declare type QueryEvent = {
|
|
|
234
243
|
|
|
235
244
|
export declare class QueryInterpreter {
|
|
236
245
|
#private;
|
|
237
|
-
constructor({ transactionManager, placeholderValues, onQuery, tracingHelper, serializer, rawSerializer, provider, connectionInfo, }: QueryInterpreterOptions);
|
|
246
|
+
constructor({ transactionManager, placeholderValues, onQuery, tracingHelper, serializer, rawSerializer, provider, connectionInfo, sqlCommenter, }: QueryInterpreterOptions);
|
|
238
247
|
static forSql(options: {
|
|
239
248
|
transactionManager: QueryInterpreterTransactionManager;
|
|
240
249
|
placeholderValues: Record<string, unknown>;
|
|
@@ -242,6 +251,7 @@ export declare class QueryInterpreter {
|
|
|
242
251
|
tracingHelper: TracingHelper;
|
|
243
252
|
provider?: SchemaProvider;
|
|
244
253
|
connectionInfo?: ConnectionInfo;
|
|
254
|
+
sqlCommenter?: QueryInterpreterSqlCommenter;
|
|
245
255
|
}): QueryInterpreter;
|
|
246
256
|
run(queryPlan: QueryPlanNode, queryable: SqlQueryable): Promise<unknown>;
|
|
247
257
|
private interpretNode;
|
|
@@ -256,6 +266,12 @@ export declare type QueryInterpreterOptions = {
|
|
|
256
266
|
rawSerializer?: (results: SqlResultSet) => Value;
|
|
257
267
|
provider?: SchemaProvider;
|
|
258
268
|
connectionInfo?: ConnectionInfo;
|
|
269
|
+
sqlCommenter?: QueryInterpreterSqlCommenter;
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
export declare type QueryInterpreterSqlCommenter = {
|
|
273
|
+
plugins: SqlCommenterPlugin[];
|
|
274
|
+
queryInfo: SqlCommenterQueryInfo;
|
|
259
275
|
};
|
|
260
276
|
|
|
261
277
|
export declare type QueryInterpreterTransactionManager = {
|
package/dist/index.js
CHANGED
|
@@ -35,6 +35,7 @@ __export(index_exports, {
|
|
|
35
35
|
TransactionManager: () => TransactionManager,
|
|
36
36
|
TransactionManagerError: () => TransactionManagerError,
|
|
37
37
|
UserFacingError: () => UserFacingError,
|
|
38
|
+
applySqlCommenters: () => applySqlCommenters,
|
|
38
39
|
convertCompactedRows: () => convertCompactedRows,
|
|
39
40
|
deserializeJsonResponse: () => deserializeJsonResponse,
|
|
40
41
|
doKeysMatch: () => doKeysMatch,
|
|
@@ -691,6 +692,43 @@ function normalizeDateTime(dt) {
|
|
|
691
692
|
return dtWithTz;
|
|
692
693
|
}
|
|
693
694
|
|
|
695
|
+
// src/sql-commenter.ts
|
|
696
|
+
function formatSqlComment(tags) {
|
|
697
|
+
const entries = Object.entries(tags);
|
|
698
|
+
if (entries.length === 0) {
|
|
699
|
+
return "";
|
|
700
|
+
}
|
|
701
|
+
entries.sort(([a], [b]) => a.localeCompare(b));
|
|
702
|
+
const parts = entries.map(([key, value]) => {
|
|
703
|
+
const encodedKey = encodeURIComponent(key);
|
|
704
|
+
const encodedValue = encodeURIComponent(value).replace(/'/g, "\\'");
|
|
705
|
+
return `${encodedKey}='${encodedValue}'`;
|
|
706
|
+
});
|
|
707
|
+
return `/*${parts.join(",")}*/`;
|
|
708
|
+
}
|
|
709
|
+
function applySqlCommenters(plugins, context) {
|
|
710
|
+
const merged = {};
|
|
711
|
+
for (const plugin of plugins) {
|
|
712
|
+
const tags = plugin(context);
|
|
713
|
+
for (const [key, value] of Object.entries(tags)) {
|
|
714
|
+
if (value !== void 0) {
|
|
715
|
+
merged[key] = value;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
return merged;
|
|
720
|
+
}
|
|
721
|
+
function buildSqlComment(plugins, context) {
|
|
722
|
+
const tags = applySqlCommenters(plugins, context);
|
|
723
|
+
return formatSqlComment(tags);
|
|
724
|
+
}
|
|
725
|
+
function appendSqlComment(sql, comment) {
|
|
726
|
+
if (!comment) {
|
|
727
|
+
return sql;
|
|
728
|
+
}
|
|
729
|
+
return `${sql} ${comment}`;
|
|
730
|
+
}
|
|
731
|
+
|
|
694
732
|
// src/tracing.ts
|
|
695
733
|
var import_api = require("@opentelemetry/api");
|
|
696
734
|
var noopTracingHelper = {
|
|
@@ -1442,6 +1480,7 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1442
1480
|
#rawSerializer;
|
|
1443
1481
|
#provider;
|
|
1444
1482
|
#connectionInfo;
|
|
1483
|
+
#sqlCommenter;
|
|
1445
1484
|
constructor({
|
|
1446
1485
|
transactionManager,
|
|
1447
1486
|
placeholderValues,
|
|
@@ -1450,7 +1489,8 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1450
1489
|
serializer,
|
|
1451
1490
|
rawSerializer,
|
|
1452
1491
|
provider,
|
|
1453
|
-
connectionInfo
|
|
1492
|
+
connectionInfo,
|
|
1493
|
+
sqlCommenter
|
|
1454
1494
|
}) {
|
|
1455
1495
|
this.#transactionManager = transactionManager;
|
|
1456
1496
|
this.#placeholderValues = placeholderValues;
|
|
@@ -1460,6 +1500,7 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1460
1500
|
this.#rawSerializer = rawSerializer ?? serializer;
|
|
1461
1501
|
this.#provider = provider;
|
|
1462
1502
|
this.#connectionInfo = connectionInfo;
|
|
1503
|
+
this.#sqlCommenter = sqlCommenter;
|
|
1463
1504
|
}
|
|
1464
1505
|
static forSql(options) {
|
|
1465
1506
|
return new _QueryInterpreter({
|
|
@@ -1470,7 +1511,8 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1470
1511
|
serializer: serializeSql,
|
|
1471
1512
|
rawSerializer: serializeRawSql,
|
|
1472
1513
|
provider: options.provider,
|
|
1473
|
-
connectionInfo: options.connectionInfo
|
|
1514
|
+
connectionInfo: options.connectionInfo,
|
|
1515
|
+
sqlCommenter: options.sqlCommenter
|
|
1474
1516
|
});
|
|
1475
1517
|
}
|
|
1476
1518
|
async run(queryPlan, queryable) {
|
|
@@ -1534,10 +1576,11 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1534
1576
|
const queries = renderQuery(node.args, scope, generators, this.#maxChunkSize());
|
|
1535
1577
|
let sum = 0;
|
|
1536
1578
|
for (const query of queries) {
|
|
1579
|
+
const commentedQuery = this.#applyComments(query);
|
|
1537
1580
|
sum += await this.#withQuerySpanAndEvent(
|
|
1538
|
-
|
|
1581
|
+
commentedQuery,
|
|
1539
1582
|
queryable,
|
|
1540
|
-
() => queryable.executeRaw(
|
|
1583
|
+
() => queryable.executeRaw(commentedQuery).catch(
|
|
1541
1584
|
(err) => node.args.type === "rawSql" ? rethrowAsUserFacingRawError(err) : rethrowAsUserFacing(err)
|
|
1542
1585
|
)
|
|
1543
1586
|
);
|
|
@@ -1548,10 +1591,11 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1548
1591
|
const queries = renderQuery(node.args, scope, generators, this.#maxChunkSize());
|
|
1549
1592
|
let results;
|
|
1550
1593
|
for (const query of queries) {
|
|
1594
|
+
const commentedQuery = this.#applyComments(query);
|
|
1551
1595
|
const result = await this.#withQuerySpanAndEvent(
|
|
1552
|
-
|
|
1596
|
+
commentedQuery,
|
|
1553
1597
|
queryable,
|
|
1554
|
-
() => queryable.queryRaw(
|
|
1598
|
+
() => queryable.queryRaw(commentedQuery).catch(
|
|
1555
1599
|
(err) => node.args.type === "rawSql" ? rethrowAsUserFacingRawError(err) : rethrowAsUserFacing(err)
|
|
1556
1600
|
)
|
|
1557
1601
|
);
|
|
@@ -1709,6 +1753,22 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1709
1753
|
onQuery: this.#onQuery
|
|
1710
1754
|
});
|
|
1711
1755
|
}
|
|
1756
|
+
#applyComments(query) {
|
|
1757
|
+
if (!this.#sqlCommenter || this.#sqlCommenter.plugins.length === 0) {
|
|
1758
|
+
return query;
|
|
1759
|
+
}
|
|
1760
|
+
const comment = buildSqlComment(this.#sqlCommenter.plugins, {
|
|
1761
|
+
query: this.#sqlCommenter.queryInfo,
|
|
1762
|
+
sql: query.sql
|
|
1763
|
+
});
|
|
1764
|
+
if (!comment) {
|
|
1765
|
+
return query;
|
|
1766
|
+
}
|
|
1767
|
+
return {
|
|
1768
|
+
...query,
|
|
1769
|
+
sql: appendSqlComment(query.sql, comment)
|
|
1770
|
+
};
|
|
1771
|
+
}
|
|
1712
1772
|
};
|
|
1713
1773
|
function isEmpty(value) {
|
|
1714
1774
|
if (Array.isArray(value)) {
|
|
@@ -2155,6 +2215,7 @@ function createTimeoutIfDefined(cb, ms) {
|
|
|
2155
2215
|
TransactionManager,
|
|
2156
2216
|
TransactionManagerError,
|
|
2157
2217
|
UserFacingError,
|
|
2218
|
+
applySqlCommenters,
|
|
2158
2219
|
convertCompactedRows,
|
|
2159
2220
|
deserializeJsonResponse,
|
|
2160
2221
|
doKeysMatch,
|
package/dist/index.mjs
CHANGED
|
@@ -641,6 +641,43 @@ function normalizeDateTime(dt) {
|
|
|
641
641
|
return dtWithTz;
|
|
642
642
|
}
|
|
643
643
|
|
|
644
|
+
// src/sql-commenter.ts
|
|
645
|
+
function formatSqlComment(tags) {
|
|
646
|
+
const entries = Object.entries(tags);
|
|
647
|
+
if (entries.length === 0) {
|
|
648
|
+
return "";
|
|
649
|
+
}
|
|
650
|
+
entries.sort(([a], [b]) => a.localeCompare(b));
|
|
651
|
+
const parts = entries.map(([key, value]) => {
|
|
652
|
+
const encodedKey = encodeURIComponent(key);
|
|
653
|
+
const encodedValue = encodeURIComponent(value).replace(/'/g, "\\'");
|
|
654
|
+
return `${encodedKey}='${encodedValue}'`;
|
|
655
|
+
});
|
|
656
|
+
return `/*${parts.join(",")}*/`;
|
|
657
|
+
}
|
|
658
|
+
function applySqlCommenters(plugins, context) {
|
|
659
|
+
const merged = {};
|
|
660
|
+
for (const plugin of plugins) {
|
|
661
|
+
const tags = plugin(context);
|
|
662
|
+
for (const [key, value] of Object.entries(tags)) {
|
|
663
|
+
if (value !== void 0) {
|
|
664
|
+
merged[key] = value;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
return merged;
|
|
669
|
+
}
|
|
670
|
+
function buildSqlComment(plugins, context) {
|
|
671
|
+
const tags = applySqlCommenters(plugins, context);
|
|
672
|
+
return formatSqlComment(tags);
|
|
673
|
+
}
|
|
674
|
+
function appendSqlComment(sql, comment) {
|
|
675
|
+
if (!comment) {
|
|
676
|
+
return sql;
|
|
677
|
+
}
|
|
678
|
+
return `${sql} ${comment}`;
|
|
679
|
+
}
|
|
680
|
+
|
|
644
681
|
// src/tracing.ts
|
|
645
682
|
import { SpanKind } from "@opentelemetry/api";
|
|
646
683
|
var noopTracingHelper = {
|
|
@@ -1392,6 +1429,7 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1392
1429
|
#rawSerializer;
|
|
1393
1430
|
#provider;
|
|
1394
1431
|
#connectionInfo;
|
|
1432
|
+
#sqlCommenter;
|
|
1395
1433
|
constructor({
|
|
1396
1434
|
transactionManager,
|
|
1397
1435
|
placeholderValues,
|
|
@@ -1400,7 +1438,8 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1400
1438
|
serializer,
|
|
1401
1439
|
rawSerializer,
|
|
1402
1440
|
provider,
|
|
1403
|
-
connectionInfo
|
|
1441
|
+
connectionInfo,
|
|
1442
|
+
sqlCommenter
|
|
1404
1443
|
}) {
|
|
1405
1444
|
this.#transactionManager = transactionManager;
|
|
1406
1445
|
this.#placeholderValues = placeholderValues;
|
|
@@ -1410,6 +1449,7 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1410
1449
|
this.#rawSerializer = rawSerializer ?? serializer;
|
|
1411
1450
|
this.#provider = provider;
|
|
1412
1451
|
this.#connectionInfo = connectionInfo;
|
|
1452
|
+
this.#sqlCommenter = sqlCommenter;
|
|
1413
1453
|
}
|
|
1414
1454
|
static forSql(options) {
|
|
1415
1455
|
return new _QueryInterpreter({
|
|
@@ -1420,7 +1460,8 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1420
1460
|
serializer: serializeSql,
|
|
1421
1461
|
rawSerializer: serializeRawSql,
|
|
1422
1462
|
provider: options.provider,
|
|
1423
|
-
connectionInfo: options.connectionInfo
|
|
1463
|
+
connectionInfo: options.connectionInfo,
|
|
1464
|
+
sqlCommenter: options.sqlCommenter
|
|
1424
1465
|
});
|
|
1425
1466
|
}
|
|
1426
1467
|
async run(queryPlan, queryable) {
|
|
@@ -1484,10 +1525,11 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1484
1525
|
const queries = renderQuery(node.args, scope, generators, this.#maxChunkSize());
|
|
1485
1526
|
let sum = 0;
|
|
1486
1527
|
for (const query of queries) {
|
|
1528
|
+
const commentedQuery = this.#applyComments(query);
|
|
1487
1529
|
sum += await this.#withQuerySpanAndEvent(
|
|
1488
|
-
|
|
1530
|
+
commentedQuery,
|
|
1489
1531
|
queryable,
|
|
1490
|
-
() => queryable.executeRaw(
|
|
1532
|
+
() => queryable.executeRaw(commentedQuery).catch(
|
|
1491
1533
|
(err) => node.args.type === "rawSql" ? rethrowAsUserFacingRawError(err) : rethrowAsUserFacing(err)
|
|
1492
1534
|
)
|
|
1493
1535
|
);
|
|
@@ -1498,10 +1540,11 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1498
1540
|
const queries = renderQuery(node.args, scope, generators, this.#maxChunkSize());
|
|
1499
1541
|
let results;
|
|
1500
1542
|
for (const query of queries) {
|
|
1543
|
+
const commentedQuery = this.#applyComments(query);
|
|
1501
1544
|
const result = await this.#withQuerySpanAndEvent(
|
|
1502
|
-
|
|
1545
|
+
commentedQuery,
|
|
1503
1546
|
queryable,
|
|
1504
|
-
() => queryable.queryRaw(
|
|
1547
|
+
() => queryable.queryRaw(commentedQuery).catch(
|
|
1505
1548
|
(err) => node.args.type === "rawSql" ? rethrowAsUserFacingRawError(err) : rethrowAsUserFacing(err)
|
|
1506
1549
|
)
|
|
1507
1550
|
);
|
|
@@ -1659,6 +1702,22 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1659
1702
|
onQuery: this.#onQuery
|
|
1660
1703
|
});
|
|
1661
1704
|
}
|
|
1705
|
+
#applyComments(query) {
|
|
1706
|
+
if (!this.#sqlCommenter || this.#sqlCommenter.plugins.length === 0) {
|
|
1707
|
+
return query;
|
|
1708
|
+
}
|
|
1709
|
+
const comment = buildSqlComment(this.#sqlCommenter.plugins, {
|
|
1710
|
+
query: this.#sqlCommenter.queryInfo,
|
|
1711
|
+
sql: query.sql
|
|
1712
|
+
});
|
|
1713
|
+
if (!comment) {
|
|
1714
|
+
return query;
|
|
1715
|
+
}
|
|
1716
|
+
return {
|
|
1717
|
+
...query,
|
|
1718
|
+
sql: appendSqlComment(query.sql, comment)
|
|
1719
|
+
};
|
|
1720
|
+
}
|
|
1662
1721
|
};
|
|
1663
1722
|
function isEmpty(value) {
|
|
1664
1723
|
if (Array.isArray(value)) {
|
|
@@ -2104,6 +2163,7 @@ export {
|
|
|
2104
2163
|
TransactionManager,
|
|
2105
2164
|
TransactionManagerError,
|
|
2106
2165
|
UserFacingError,
|
|
2166
|
+
applySqlCommenters,
|
|
2107
2167
|
convertCompactedRows,
|
|
2108
2168
|
deserializeJsonResponse,
|
|
2109
2169
|
doKeysMatch,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ConnectionInfo, SqlQueryable, SqlResultSet } from '@prisma/driver-adapter-utils';
|
|
2
|
+
import type { SqlCommenterPlugin, SqlCommenterQueryInfo } from '@prisma/sqlcommenter';
|
|
2
3
|
import { QueryEvent } from '../events';
|
|
3
4
|
import { QueryPlanNode } from '../query-plan';
|
|
4
5
|
import { type SchemaProvider } from '../schema';
|
|
@@ -20,10 +21,15 @@ export type QueryInterpreterOptions = {
|
|
|
20
21
|
rawSerializer?: (results: SqlResultSet) => Value;
|
|
21
22
|
provider?: SchemaProvider;
|
|
22
23
|
connectionInfo?: ConnectionInfo;
|
|
24
|
+
sqlCommenter?: QueryInterpreterSqlCommenter;
|
|
25
|
+
};
|
|
26
|
+
export type QueryInterpreterSqlCommenter = {
|
|
27
|
+
plugins: SqlCommenterPlugin[];
|
|
28
|
+
queryInfo: SqlCommenterQueryInfo;
|
|
23
29
|
};
|
|
24
30
|
export declare class QueryInterpreter {
|
|
25
31
|
#private;
|
|
26
|
-
constructor({ transactionManager, placeholderValues, onQuery, tracingHelper, serializer, rawSerializer, provider, connectionInfo, }: QueryInterpreterOptions);
|
|
32
|
+
constructor({ transactionManager, placeholderValues, onQuery, tracingHelper, serializer, rawSerializer, provider, connectionInfo, sqlCommenter, }: QueryInterpreterOptions);
|
|
27
33
|
static forSql(options: {
|
|
28
34
|
transactionManager: QueryInterpreterTransactionManager;
|
|
29
35
|
placeholderValues: Record<string, unknown>;
|
|
@@ -31,6 +37,7 @@ export declare class QueryInterpreter {
|
|
|
31
37
|
tracingHelper: TracingHelper;
|
|
32
38
|
provider?: SchemaProvider;
|
|
33
39
|
connectionInfo?: ConnectionInfo;
|
|
40
|
+
sqlCommenter?: QueryInterpreterSqlCommenter;
|
|
34
41
|
}): QueryInterpreter;
|
|
35
42
|
run(queryPlan: QueryPlanNode, queryable: SqlQueryable): Promise<unknown>;
|
|
36
43
|
private interpretNode;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { SqlCommenterContext, SqlCommenterPlugin } from '@prisma/sqlcommenter';
|
|
2
|
+
/**
|
|
3
|
+
* Formats key-value pairs into a sqlcommenter-compatible comment string.
|
|
4
|
+
*
|
|
5
|
+
* Algorithm per https://google.github.io/sqlcommenter/spec/:
|
|
6
|
+
* 1. If the map is empty, return empty string
|
|
7
|
+
* 2. Sort keys lexicographically
|
|
8
|
+
* 3. URL-encode keys
|
|
9
|
+
* 4. URL-encode values
|
|
10
|
+
* 5. Replace ' with \' in values (after URL encoding)
|
|
11
|
+
* 6. Wrap values in single quotes
|
|
12
|
+
* 7. Join key='value' pairs with commas
|
|
13
|
+
* 8. Wrap in /* *\/
|
|
14
|
+
*/
|
|
15
|
+
export declare function formatSqlComment(tags: Record<string, string>): string;
|
|
16
|
+
/**
|
|
17
|
+
* Applies SQL commenter plugins and returns the merged key-value pairs.
|
|
18
|
+
* Keys with undefined values are filtered out.
|
|
19
|
+
*/
|
|
20
|
+
export declare function applySqlCommenters(plugins: SqlCommenterPlugin[], context: SqlCommenterContext): Record<string, string>;
|
|
21
|
+
/**
|
|
22
|
+
* Applies SQL commenter plugins and returns the formatted comment.
|
|
23
|
+
*/
|
|
24
|
+
export declare function buildSqlComment(plugins: SqlCommenterPlugin[], context: SqlCommenterContext): string;
|
|
25
|
+
/**
|
|
26
|
+
* Appends a sqlcommenter comment to a SQL query.
|
|
27
|
+
*/
|
|
28
|
+
export declare function appendSqlComment(sql: string, comment: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/client-engine-runtime",
|
|
3
|
-
"version": "7.1.0-dev.
|
|
3
|
+
"version": "7.1.0-dev.35",
|
|
4
4
|
"description": "This package is intended for Prisma's internal use",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -30,9 +30,10 @@
|
|
|
30
30
|
"nanoid": "5.1.5",
|
|
31
31
|
"ulid": "3.0.0",
|
|
32
32
|
"uuid": "11.1.0",
|
|
33
|
-
"@prisma/client-runtime-utils": "7.1.0-dev.
|
|
34
|
-
"@prisma/debug": "7.1.0-dev.
|
|
35
|
-
"@prisma/driver-adapter-utils": "7.1.0-dev.
|
|
33
|
+
"@prisma/client-runtime-utils": "7.1.0-dev.35",
|
|
34
|
+
"@prisma/debug": "7.1.0-dev.35",
|
|
35
|
+
"@prisma/driver-adapter-utils": "7.1.0-dev.35",
|
|
36
|
+
"@prisma/sqlcommenter": "7.1.0-dev.35"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
39
|
"@types/jest": "29.5.14",
|