@prisma/client-engine-runtime 6.14.0-dev.2 → 6.14.0-dev.21
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/QueryPlan.d.ts +3 -0
- package/dist/UserFacingError.d.ts +1 -0
- package/dist/index.d.mts +15 -1
- package/dist/index.d.ts +15 -1
- package/dist/index.js +366 -94
- package/dist/index.mjs +365 -94
- package/dist/interpreter/QueryInterpreter.d.ts +4 -2
- package/dist/interpreter/renderQuery.d.ts +1 -1
- package/dist/raw-json-protocol.d.ts +6 -0
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -43,6 +43,7 @@ __export(index_exports, {
|
|
|
43
43
|
isPrismaValuePlaceholder: () => isPrismaValuePlaceholder,
|
|
44
44
|
noopTracingHelper: () => noopTracingHelper,
|
|
45
45
|
normalizeJsonProtocolValues: () => normalizeJsonProtocolValues,
|
|
46
|
+
normalizeRawJsonProtocolResponse: () => normalizeRawJsonProtocolResponse,
|
|
46
47
|
safeJsonStringify: () => safeJsonStringify
|
|
47
48
|
});
|
|
48
49
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -318,8 +319,10 @@ function mapValue(value, columnName, resultType, enums) {
|
|
|
318
319
|
return values.map((v, i) => mapValue(v, `${columnName}[${i}]`, resultType.inner, enums));
|
|
319
320
|
}
|
|
320
321
|
case "Object": {
|
|
321
|
-
|
|
322
|
-
|
|
322
|
+
return { $type: "Json", value: safeJsonStringify(value) };
|
|
323
|
+
}
|
|
324
|
+
case "Json": {
|
|
325
|
+
return { $type: "Json", value: `${value}` };
|
|
323
326
|
}
|
|
324
327
|
case "Bytes": {
|
|
325
328
|
if (typeof value === "string" && value.startsWith("\\x")) {
|
|
@@ -340,7 +343,7 @@ function mapValue(value, columnName, resultType, enums) {
|
|
|
340
343
|
}
|
|
341
344
|
const enumValue = enumDef[`${value}`];
|
|
342
345
|
if (enumValue === void 0) {
|
|
343
|
-
throw new DataMapperError(`
|
|
346
|
+
throw new DataMapperError(`Value '${value}' not found in enum '${resultType.inner}'`);
|
|
344
347
|
}
|
|
345
348
|
return enumValue;
|
|
346
349
|
}
|
|
@@ -450,6 +453,16 @@ function rethrowAsUserFacing(error) {
|
|
|
450
453
|
}
|
|
451
454
|
throw new UserFacingError(message, code, { driverAdapterError: error });
|
|
452
455
|
}
|
|
456
|
+
function rethrowAsUserFacingRawError(error) {
|
|
457
|
+
if (!(0, import_driver_adapter_utils.isDriverAdapterError)(error)) {
|
|
458
|
+
throw error;
|
|
459
|
+
}
|
|
460
|
+
throw new UserFacingError(
|
|
461
|
+
`Raw query failed. Code: ${error.cause.originalCode ?? "N/A"}. Message: ${error.cause.originalMessage ?? renderErrorMessage(error)}`,
|
|
462
|
+
"P2010",
|
|
463
|
+
{ driverAdapterError: error }
|
|
464
|
+
);
|
|
465
|
+
}
|
|
453
466
|
function getErrorCode(err) {
|
|
454
467
|
switch (err.cause.kind) {
|
|
455
468
|
case "AuthenticationFailed":
|
|
@@ -708,17 +721,21 @@ function isPrismaValueBigInt(value) {
|
|
|
708
721
|
}
|
|
709
722
|
|
|
710
723
|
// src/interpreter/renderQuery.ts
|
|
711
|
-
function renderQuery(dbQuery, scope, generators) {
|
|
724
|
+
function renderQuery(dbQuery, scope, generators, maxChunkSize) {
|
|
712
725
|
const queryType = dbQuery.type;
|
|
726
|
+
const params = evaluateParams(dbQuery.params, scope, generators);
|
|
713
727
|
switch (queryType) {
|
|
714
728
|
case "rawSql":
|
|
715
|
-
return renderRawSql(dbQuery.sql, evaluateParams(dbQuery.params, scope, generators));
|
|
716
|
-
case "templateSql":
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
729
|
+
return [renderRawSql(dbQuery.sql, evaluateParams(dbQuery.params, scope, generators))];
|
|
730
|
+
case "templateSql": {
|
|
731
|
+
const chunks = dbQuery.chunkable ? chunkParams(dbQuery.fragments, params, maxChunkSize) : [params];
|
|
732
|
+
return chunks.map((params2) => {
|
|
733
|
+
if (maxChunkSize !== void 0 && params2.length > maxChunkSize) {
|
|
734
|
+
throw new UserFacingError("The query parameter limit supported by your database is exceeded.", "P2029");
|
|
735
|
+
}
|
|
736
|
+
return renderTemplateSql(dbQuery.fragments, dbQuery.placeholderFormat, params2);
|
|
737
|
+
});
|
|
738
|
+
}
|
|
722
739
|
default:
|
|
723
740
|
assertNever(queryType, `Invalid query type`);
|
|
724
741
|
}
|
|
@@ -756,61 +773,36 @@ function evaluateParam(param, scope, generators) {
|
|
|
756
773
|
return value;
|
|
757
774
|
}
|
|
758
775
|
function renderTemplateSql(fragments, placeholderFormat, params) {
|
|
759
|
-
let
|
|
760
|
-
|
|
776
|
+
let sql = "";
|
|
777
|
+
const ctx = { placeholderNumber: 1 };
|
|
761
778
|
const flattenedParams = [];
|
|
762
|
-
const
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
if (paramIndex >= params.length) {
|
|
767
|
-
throw new Error(`Malformed query template. Fragments attempt to read over ${params.length} parameters.`);
|
|
768
|
-
}
|
|
769
|
-
flattenedParams.push(params[paramIndex++]);
|
|
770
|
-
return formatPlaceholder(placeholderFormat, placeholderNumber++);
|
|
771
|
-
case "stringChunk":
|
|
772
|
-
return fragment.chunk;
|
|
773
|
-
case "parameterTuple": {
|
|
774
|
-
if (paramIndex >= params.length) {
|
|
775
|
-
throw new Error(`Malformed query template. Fragments attempt to read over ${params.length} parameters.`);
|
|
776
|
-
}
|
|
777
|
-
const paramValue = params[paramIndex++];
|
|
778
|
-
const paramArray = Array.isArray(paramValue) ? paramValue : [paramValue];
|
|
779
|
-
const placeholders = paramArray.length == 0 ? "NULL" : paramArray.map((value) => {
|
|
780
|
-
flattenedParams.push(value);
|
|
781
|
-
return formatPlaceholder(placeholderFormat, placeholderNumber++);
|
|
782
|
-
}).join(",");
|
|
783
|
-
return `(${placeholders})`;
|
|
784
|
-
}
|
|
785
|
-
case "parameterTupleList": {
|
|
786
|
-
if (paramIndex >= params.length) {
|
|
787
|
-
throw new Error(`Malformed query template. Fragments attempt to read over ${params.length} parameters.`);
|
|
788
|
-
}
|
|
789
|
-
const paramValue = params[paramIndex++];
|
|
790
|
-
if (!Array.isArray(paramValue)) {
|
|
791
|
-
throw new Error(`Malformed query template. Tuple list expected.`);
|
|
792
|
-
}
|
|
793
|
-
if (paramValue.length === 0) {
|
|
794
|
-
throw new Error(`Malformed query template. Tuple list cannot be empty.`);
|
|
795
|
-
}
|
|
796
|
-
const tupleList = paramValue.map((tuple) => {
|
|
797
|
-
if (!Array.isArray(tuple)) {
|
|
798
|
-
throw new Error(`Malformed query template. Tuple expected.`);
|
|
799
|
-
}
|
|
800
|
-
const elements = tuple.map((value) => {
|
|
801
|
-
flattenedParams.push(value);
|
|
802
|
-
return formatPlaceholder(placeholderFormat, placeholderNumber++);
|
|
803
|
-
}).join(fragment.itemSeparator);
|
|
804
|
-
return `${fragment.itemPrefix}${elements}${fragment.itemSuffix}`;
|
|
805
|
-
}).join(fragment.groupSeparator);
|
|
806
|
-
return tupleList;
|
|
807
|
-
}
|
|
808
|
-
default:
|
|
809
|
-
assertNever(fragmentType, "Invalid fragment type");
|
|
810
|
-
}
|
|
811
|
-
}).join("");
|
|
779
|
+
for (const fragment of pairFragmentsWithParams(fragments, params)) {
|
|
780
|
+
flattenedParams.push(...flattenedFragmentParams(fragment));
|
|
781
|
+
sql += renderFragment(fragment, placeholderFormat, ctx);
|
|
782
|
+
}
|
|
812
783
|
return renderRawSql(sql, flattenedParams);
|
|
813
784
|
}
|
|
785
|
+
function renderFragment(fragment, placeholderFormat, ctx) {
|
|
786
|
+
const fragmentType = fragment.type;
|
|
787
|
+
switch (fragmentType) {
|
|
788
|
+
case "parameter":
|
|
789
|
+
return formatPlaceholder(placeholderFormat, ctx.placeholderNumber++);
|
|
790
|
+
case "stringChunk":
|
|
791
|
+
return fragment.chunk;
|
|
792
|
+
case "parameterTuple": {
|
|
793
|
+
const placeholders = fragment.value.length == 0 ? "NULL" : fragment.value.map(() => formatPlaceholder(placeholderFormat, ctx.placeholderNumber++)).join(",");
|
|
794
|
+
return `(${placeholders})`;
|
|
795
|
+
}
|
|
796
|
+
case "parameterTupleList": {
|
|
797
|
+
return fragment.value.map((tuple) => {
|
|
798
|
+
const elements = tuple.map(() => formatPlaceholder(placeholderFormat, ctx.placeholderNumber++)).join(fragment.itemSeparator);
|
|
799
|
+
return `${fragment.itemPrefix}${elements}${fragment.itemSuffix}`;
|
|
800
|
+
}).join(fragment.groupSeparator);
|
|
801
|
+
}
|
|
802
|
+
default:
|
|
803
|
+
assertNever(fragmentType, "Invalid fragment type");
|
|
804
|
+
}
|
|
805
|
+
}
|
|
814
806
|
function formatPlaceholder(placeholderFormat, placeholderNumber) {
|
|
815
807
|
return placeholderFormat.hasNumbering ? `${placeholderFormat.prefix}${placeholderNumber}` : placeholderFormat.prefix;
|
|
816
808
|
}
|
|
@@ -843,6 +835,143 @@ function toArgType(value) {
|
|
|
843
835
|
function doesRequireEvaluation(param) {
|
|
844
836
|
return isPrismaValuePlaceholder(param) || isPrismaValueGenerator(param);
|
|
845
837
|
}
|
|
838
|
+
function* pairFragmentsWithParams(fragments, params) {
|
|
839
|
+
let index = 0;
|
|
840
|
+
for (const fragment of fragments) {
|
|
841
|
+
switch (fragment.type) {
|
|
842
|
+
case "parameter": {
|
|
843
|
+
if (index >= params.length) {
|
|
844
|
+
throw new Error(`Malformed query template. Fragments attempt to read over ${params.length} parameters.`);
|
|
845
|
+
}
|
|
846
|
+
yield { ...fragment, value: params[index++] };
|
|
847
|
+
break;
|
|
848
|
+
}
|
|
849
|
+
case "stringChunk": {
|
|
850
|
+
yield fragment;
|
|
851
|
+
break;
|
|
852
|
+
}
|
|
853
|
+
case "parameterTuple": {
|
|
854
|
+
if (index >= params.length) {
|
|
855
|
+
throw new Error(`Malformed query template. Fragments attempt to read over ${params.length} parameters.`);
|
|
856
|
+
}
|
|
857
|
+
const value = params[index++];
|
|
858
|
+
yield { ...fragment, value: Array.isArray(value) ? value : [value] };
|
|
859
|
+
break;
|
|
860
|
+
}
|
|
861
|
+
case "parameterTupleList": {
|
|
862
|
+
if (index >= params.length) {
|
|
863
|
+
throw new Error(`Malformed query template. Fragments attempt to read over ${params.length} parameters.`);
|
|
864
|
+
}
|
|
865
|
+
const value = params[index++];
|
|
866
|
+
if (!Array.isArray(value)) {
|
|
867
|
+
throw new Error(`Malformed query template. Tuple list expected.`);
|
|
868
|
+
}
|
|
869
|
+
if (value.length === 0) {
|
|
870
|
+
throw new Error(`Malformed query template. Tuple list cannot be empty.`);
|
|
871
|
+
}
|
|
872
|
+
for (const tuple of value) {
|
|
873
|
+
if (!Array.isArray(tuple)) {
|
|
874
|
+
throw new Error(`Malformed query template. Tuple expected.`);
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
yield { ...fragment, value };
|
|
878
|
+
break;
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
function* flattenedFragmentParams(fragment) {
|
|
884
|
+
switch (fragment.type) {
|
|
885
|
+
case "parameter":
|
|
886
|
+
yield fragment.value;
|
|
887
|
+
break;
|
|
888
|
+
case "stringChunk":
|
|
889
|
+
break;
|
|
890
|
+
case "parameterTuple":
|
|
891
|
+
yield* fragment.value;
|
|
892
|
+
break;
|
|
893
|
+
case "parameterTupleList":
|
|
894
|
+
for (const tuple of fragment.value) {
|
|
895
|
+
yield* tuple;
|
|
896
|
+
}
|
|
897
|
+
break;
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
function chunkParams(fragments, params, maxChunkSize) {
|
|
901
|
+
let totalParamCount = 0;
|
|
902
|
+
let maxParamsPerFragment = 0;
|
|
903
|
+
for (const fragment of pairFragmentsWithParams(fragments, params)) {
|
|
904
|
+
let paramSize = 0;
|
|
905
|
+
for (const _ of flattenedFragmentParams(fragment)) {
|
|
906
|
+
void _;
|
|
907
|
+
paramSize++;
|
|
908
|
+
}
|
|
909
|
+
maxParamsPerFragment = Math.max(maxParamsPerFragment, paramSize);
|
|
910
|
+
totalParamCount += paramSize;
|
|
911
|
+
}
|
|
912
|
+
let chunkedParams = [[]];
|
|
913
|
+
for (const fragment of pairFragmentsWithParams(fragments, params)) {
|
|
914
|
+
switch (fragment.type) {
|
|
915
|
+
case "parameter": {
|
|
916
|
+
for (const params2 of chunkedParams) {
|
|
917
|
+
params2.push(fragment.value);
|
|
918
|
+
}
|
|
919
|
+
break;
|
|
920
|
+
}
|
|
921
|
+
case "stringChunk": {
|
|
922
|
+
break;
|
|
923
|
+
}
|
|
924
|
+
case "parameterTuple": {
|
|
925
|
+
const thisParamCount = fragment.value.length;
|
|
926
|
+
let chunks = [];
|
|
927
|
+
if (maxChunkSize && // Have we split the parameters into chunks already?
|
|
928
|
+
chunkedParams.length === 1 && // Is this the fragment that has the most parameters?
|
|
929
|
+
thisParamCount === maxParamsPerFragment && // Do we need chunking to fit the parameters?
|
|
930
|
+
totalParamCount > maxChunkSize && // Would chunking enable us to fit the parameters?
|
|
931
|
+
totalParamCount - thisParamCount < maxChunkSize) {
|
|
932
|
+
const availableSize = maxChunkSize - (totalParamCount - thisParamCount);
|
|
933
|
+
chunks = chunkArray(fragment.value, availableSize);
|
|
934
|
+
} else {
|
|
935
|
+
chunks = [fragment.value];
|
|
936
|
+
}
|
|
937
|
+
chunkedParams = chunkedParams.flatMap((params2) => chunks.map((chunk) => [...params2, chunk]));
|
|
938
|
+
break;
|
|
939
|
+
}
|
|
940
|
+
case "parameterTupleList": {
|
|
941
|
+
const thisParamCount = fragment.value.reduce((acc, tuple) => acc + tuple.length, 0);
|
|
942
|
+
const completeChunks = [];
|
|
943
|
+
let currentChunk = [];
|
|
944
|
+
let currentChunkParamCount = 0;
|
|
945
|
+
for (const tuple of fragment.value) {
|
|
946
|
+
if (maxChunkSize && // Have we split the parameters into chunks already?
|
|
947
|
+
chunkedParams.length === 1 && // Is this the fragment that has the most parameters?
|
|
948
|
+
thisParamCount === maxParamsPerFragment && // Is there anything in the current chunk?
|
|
949
|
+
currentChunk.length > 0 && // Will adding this tuple exceed the max chunk size?
|
|
950
|
+
totalParamCount - thisParamCount + currentChunkParamCount + tuple.length > maxChunkSize) {
|
|
951
|
+
completeChunks.push(currentChunk);
|
|
952
|
+
currentChunk = [];
|
|
953
|
+
currentChunkParamCount = 0;
|
|
954
|
+
}
|
|
955
|
+
currentChunk.push(tuple);
|
|
956
|
+
currentChunkParamCount += tuple.length;
|
|
957
|
+
}
|
|
958
|
+
if (currentChunk.length > 0) {
|
|
959
|
+
completeChunks.push(currentChunk);
|
|
960
|
+
}
|
|
961
|
+
chunkedParams = chunkedParams.flatMap((params2) => completeChunks.map((chunk) => [...params2, chunk]));
|
|
962
|
+
break;
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
return chunkedParams;
|
|
967
|
+
}
|
|
968
|
+
function chunkArray(array, chunkSize) {
|
|
969
|
+
const result = [];
|
|
970
|
+
for (let i = 0; i < array.length; i += chunkSize) {
|
|
971
|
+
result.push(array.slice(i, i + chunkSize));
|
|
972
|
+
}
|
|
973
|
+
return result;
|
|
974
|
+
}
|
|
846
975
|
|
|
847
976
|
// src/interpreter/serializeSql.ts
|
|
848
977
|
var import_driver_adapter_utils2 = require("@prisma/driver-adapter-utils");
|
|
@@ -875,29 +1004,90 @@ function serializeSql(resultSet) {
|
|
|
875
1004
|
);
|
|
876
1005
|
}
|
|
877
1006
|
function serializeRawSql(resultSet) {
|
|
878
|
-
const types = resultSet.columnTypes.map((type) => serializeColumnType(type));
|
|
879
|
-
const mappers = types.map((type) => {
|
|
880
|
-
switch (type) {
|
|
881
|
-
case "bytes":
|
|
882
|
-
return (value) => Array.isArray(value) ? new Uint8Array(value) : value;
|
|
883
|
-
case "int":
|
|
884
|
-
return (value) => value === null ? null : typeof value === "number" ? value : parseInt(`${value}`, 10);
|
|
885
|
-
case "bigint":
|
|
886
|
-
return (value) => value === null ? null : typeof value === "bigint" ? value : BigInt(`${value}`);
|
|
887
|
-
case "json":
|
|
888
|
-
return (value) => typeof value === "string" ? JSON.parse(value) : value;
|
|
889
|
-
case "bool":
|
|
890
|
-
return (value) => typeof value === "string" ? value === "true" || value === "1" : typeof value === "number" ? value === 1 : value;
|
|
891
|
-
default:
|
|
892
|
-
return (value) => value;
|
|
893
|
-
}
|
|
894
|
-
});
|
|
895
1007
|
return {
|
|
896
1008
|
columns: resultSet.columnNames,
|
|
897
1009
|
types: resultSet.columnTypes.map((type) => serializeColumnType(type)),
|
|
898
|
-
rows: resultSet.rows.map(
|
|
1010
|
+
rows: resultSet.rows.map(
|
|
1011
|
+
(row) => row.map((value, index) => serializeRawValue(value, resultSet.columnTypes[index]))
|
|
1012
|
+
)
|
|
899
1013
|
};
|
|
900
1014
|
}
|
|
1015
|
+
function serializeRawValue(value, type) {
|
|
1016
|
+
if (value === null) {
|
|
1017
|
+
return null;
|
|
1018
|
+
}
|
|
1019
|
+
switch (type) {
|
|
1020
|
+
case import_driver_adapter_utils2.ColumnTypeEnum.Int32:
|
|
1021
|
+
switch (typeof value) {
|
|
1022
|
+
case "number":
|
|
1023
|
+
return Math.trunc(value);
|
|
1024
|
+
case "string":
|
|
1025
|
+
return Math.trunc(Number(value));
|
|
1026
|
+
default:
|
|
1027
|
+
throw new Error(`Cannot serialize value of type ${typeof value} as Int32`);
|
|
1028
|
+
}
|
|
1029
|
+
case import_driver_adapter_utils2.ColumnTypeEnum.Int32Array:
|
|
1030
|
+
if (!Array.isArray(value)) {
|
|
1031
|
+
throw new Error(`Cannot serialize value of type ${typeof value} as Int32Array`);
|
|
1032
|
+
}
|
|
1033
|
+
return value.map((v) => serializeRawValue(v, import_driver_adapter_utils2.ColumnTypeEnum.Int32));
|
|
1034
|
+
case import_driver_adapter_utils2.ColumnTypeEnum.Int64:
|
|
1035
|
+
switch (typeof value) {
|
|
1036
|
+
case "number":
|
|
1037
|
+
return BigInt(Math.trunc(value));
|
|
1038
|
+
case "string":
|
|
1039
|
+
return value;
|
|
1040
|
+
default:
|
|
1041
|
+
throw new Error(`Cannot serialize value of type ${typeof value} as Int64`);
|
|
1042
|
+
}
|
|
1043
|
+
case import_driver_adapter_utils2.ColumnTypeEnum.Int64Array:
|
|
1044
|
+
if (!Array.isArray(value)) {
|
|
1045
|
+
throw new Error(`Cannot serialize value of type ${typeof value} as Int64Array`);
|
|
1046
|
+
}
|
|
1047
|
+
return value.map((v) => serializeRawValue(v, import_driver_adapter_utils2.ColumnTypeEnum.Int64));
|
|
1048
|
+
case import_driver_adapter_utils2.ColumnTypeEnum.Json:
|
|
1049
|
+
switch (typeof value) {
|
|
1050
|
+
case "string":
|
|
1051
|
+
return JSON.parse(value);
|
|
1052
|
+
default:
|
|
1053
|
+
throw new Error(`Cannot serialize value of type ${typeof value} as Json`);
|
|
1054
|
+
}
|
|
1055
|
+
case import_driver_adapter_utils2.ColumnTypeEnum.JsonArray:
|
|
1056
|
+
if (!Array.isArray(value)) {
|
|
1057
|
+
throw new Error(`Cannot serialize value of type ${typeof value} as JsonArray`);
|
|
1058
|
+
}
|
|
1059
|
+
return value.map((v) => serializeRawValue(v, import_driver_adapter_utils2.ColumnTypeEnum.Json));
|
|
1060
|
+
case import_driver_adapter_utils2.ColumnTypeEnum.Bytes:
|
|
1061
|
+
if (Array.isArray(value)) {
|
|
1062
|
+
return new Uint8Array(value);
|
|
1063
|
+
} else {
|
|
1064
|
+
throw new Error(`Cannot serialize value of type ${typeof value} as Bytes`);
|
|
1065
|
+
}
|
|
1066
|
+
case import_driver_adapter_utils2.ColumnTypeEnum.BytesArray:
|
|
1067
|
+
if (!Array.isArray(value)) {
|
|
1068
|
+
throw new Error(`Cannot serialize value of type ${typeof value} as BytesArray`);
|
|
1069
|
+
}
|
|
1070
|
+
return value.map((v) => serializeRawValue(v, import_driver_adapter_utils2.ColumnTypeEnum.Bytes));
|
|
1071
|
+
case import_driver_adapter_utils2.ColumnTypeEnum.Boolean:
|
|
1072
|
+
switch (typeof value) {
|
|
1073
|
+
case "boolean":
|
|
1074
|
+
return value;
|
|
1075
|
+
case "string":
|
|
1076
|
+
return value === "true" || value === "1";
|
|
1077
|
+
case "number":
|
|
1078
|
+
return value === 1;
|
|
1079
|
+
default:
|
|
1080
|
+
throw new Error(`Cannot serialize value of type ${typeof value} as Boolean`);
|
|
1081
|
+
}
|
|
1082
|
+
case import_driver_adapter_utils2.ColumnTypeEnum.BooleanArray:
|
|
1083
|
+
if (!Array.isArray(value)) {
|
|
1084
|
+
throw new Error(`Cannot serialize value of type ${typeof value} as BooleanArray`);
|
|
1085
|
+
}
|
|
1086
|
+
return value.map((v) => serializeRawValue(v, import_driver_adapter_utils2.ColumnTypeEnum.Boolean));
|
|
1087
|
+
default:
|
|
1088
|
+
return value;
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
901
1091
|
function serializeColumnType(columnType) {
|
|
902
1092
|
switch (columnType) {
|
|
903
1093
|
case import_driver_adapter_utils2.ColumnTypeEnum.Int32:
|
|
@@ -1052,6 +1242,7 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1052
1242
|
#serializer;
|
|
1053
1243
|
#rawSerializer;
|
|
1054
1244
|
#provider;
|
|
1245
|
+
#connectioInfo;
|
|
1055
1246
|
constructor({
|
|
1056
1247
|
transactionManager,
|
|
1057
1248
|
placeholderValues,
|
|
@@ -1059,7 +1250,8 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1059
1250
|
tracingHelper,
|
|
1060
1251
|
serializer,
|
|
1061
1252
|
rawSerializer,
|
|
1062
|
-
provider
|
|
1253
|
+
provider,
|
|
1254
|
+
connectionInfo
|
|
1063
1255
|
}) {
|
|
1064
1256
|
this.#transactionManager = transactionManager;
|
|
1065
1257
|
this.#placeholderValues = placeholderValues;
|
|
@@ -1068,6 +1260,7 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1068
1260
|
this.#serializer = serializer;
|
|
1069
1261
|
this.#rawSerializer = rawSerializer ?? serializer;
|
|
1070
1262
|
this.#provider = provider;
|
|
1263
|
+
this.#connectioInfo = connectionInfo;
|
|
1071
1264
|
}
|
|
1072
1265
|
static forSql(options) {
|
|
1073
1266
|
return new _QueryInterpreter({
|
|
@@ -1077,7 +1270,8 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1077
1270
|
tracingHelper: options.tracingHelper,
|
|
1078
1271
|
serializer: serializeSql,
|
|
1079
1272
|
rawSerializer: serializeRawSql,
|
|
1080
|
-
provider: options.provider
|
|
1273
|
+
provider: options.provider,
|
|
1274
|
+
connectionInfo: options.connectionInfo
|
|
1081
1275
|
});
|
|
1082
1276
|
}
|
|
1083
1277
|
async run(queryPlan, queryable) {
|
|
@@ -1138,21 +1332,41 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1138
1332
|
};
|
|
1139
1333
|
}
|
|
1140
1334
|
case "execute": {
|
|
1141
|
-
const
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1335
|
+
const queries = renderQuery(node.args, scope, generators, this.#maxChunkSize());
|
|
1336
|
+
let sum = 0;
|
|
1337
|
+
for (const query of queries) {
|
|
1338
|
+
sum += await this.#withQuerySpanAndEvent(
|
|
1339
|
+
query,
|
|
1340
|
+
queryable,
|
|
1341
|
+
() => queryable.executeRaw(query).catch(
|
|
1342
|
+
(err) => node.args.type === "rawSql" ? rethrowAsUserFacingRawError(err) : rethrowAsUserFacing(err)
|
|
1343
|
+
)
|
|
1344
|
+
);
|
|
1345
|
+
}
|
|
1346
|
+
return { value: sum };
|
|
1145
1347
|
}
|
|
1146
1348
|
case "query": {
|
|
1147
|
-
const
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1349
|
+
const queries = renderQuery(node.args, scope, generators, this.#maxChunkSize());
|
|
1350
|
+
let results;
|
|
1351
|
+
for (const query of queries) {
|
|
1352
|
+
const result = await this.#withQuerySpanAndEvent(
|
|
1353
|
+
query,
|
|
1354
|
+
queryable,
|
|
1355
|
+
() => queryable.queryRaw(query).catch(
|
|
1356
|
+
(err) => node.args.type === "rawSql" ? rethrowAsUserFacingRawError(err) : rethrowAsUserFacing(err)
|
|
1357
|
+
)
|
|
1358
|
+
);
|
|
1359
|
+
if (results === void 0) {
|
|
1360
|
+
results = result;
|
|
1152
1361
|
} else {
|
|
1153
|
-
|
|
1362
|
+
results.rows.push(...result.rows);
|
|
1363
|
+
results.lastInsertId = result.lastInsertId;
|
|
1154
1364
|
}
|
|
1155
|
-
}
|
|
1365
|
+
}
|
|
1366
|
+
return {
|
|
1367
|
+
value: node.args.type === "rawSql" ? this.#rawSerializer(results) : this.#serializer(results),
|
|
1368
|
+
lastInsertId: results?.lastInsertId
|
|
1369
|
+
};
|
|
1156
1370
|
}
|
|
1157
1371
|
case "reverse": {
|
|
1158
1372
|
const { value, lastInsertId } = await this.interpretNode(node.args, queryable, scope, generators);
|
|
@@ -1289,6 +1503,34 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1289
1503
|
assertNever(node, `Unexpected node type: ${node.type}`);
|
|
1290
1504
|
}
|
|
1291
1505
|
}
|
|
1506
|
+
#maxChunkSize() {
|
|
1507
|
+
if (this.#connectioInfo?.maxBindValues !== void 0) {
|
|
1508
|
+
return this.#connectioInfo.maxBindValues;
|
|
1509
|
+
}
|
|
1510
|
+
return this.#providerMaxChunkSize();
|
|
1511
|
+
}
|
|
1512
|
+
#providerMaxChunkSize() {
|
|
1513
|
+
if (this.#provider === void 0) {
|
|
1514
|
+
return void 0;
|
|
1515
|
+
}
|
|
1516
|
+
switch (this.#provider) {
|
|
1517
|
+
case "cockroachdb":
|
|
1518
|
+
case "postgres":
|
|
1519
|
+
case "postgresql":
|
|
1520
|
+
case "prisma+postgres":
|
|
1521
|
+
return 32766;
|
|
1522
|
+
case "mysql":
|
|
1523
|
+
return 65535;
|
|
1524
|
+
case "sqlite":
|
|
1525
|
+
return 999;
|
|
1526
|
+
case "sqlserver":
|
|
1527
|
+
return 2098;
|
|
1528
|
+
case "mongodb":
|
|
1529
|
+
return void 0;
|
|
1530
|
+
default:
|
|
1531
|
+
assertNever(this.#provider, `Unexpected provider: ${this.#provider}`);
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1292
1534
|
#withQuerySpanAndEvent(query, queryable, execute) {
|
|
1293
1535
|
return withQuerySpanAndEvent({
|
|
1294
1536
|
query,
|
|
@@ -1458,6 +1700,35 @@ function mapObjectValues(object, mapper) {
|
|
|
1458
1700
|
return result;
|
|
1459
1701
|
}
|
|
1460
1702
|
|
|
1703
|
+
// src/raw-json-protocol.ts
|
|
1704
|
+
var import_decimal4 = __toESM(require("decimal.js"));
|
|
1705
|
+
function normalizeRawJsonProtocolResponse(response) {
|
|
1706
|
+
for (let i = 0; i < response.rows.length; i++) {
|
|
1707
|
+
const row = response.rows[i];
|
|
1708
|
+
for (let j = 0; j < row.length; j++) {
|
|
1709
|
+
row[j] = normalizeValue(response.types[j], row[j]);
|
|
1710
|
+
}
|
|
1711
|
+
}
|
|
1712
|
+
return response;
|
|
1713
|
+
}
|
|
1714
|
+
function normalizeValue(type, value) {
|
|
1715
|
+
if (value === null) {
|
|
1716
|
+
return value;
|
|
1717
|
+
}
|
|
1718
|
+
switch (type) {
|
|
1719
|
+
case "bigint":
|
|
1720
|
+
return String(BigInt(value));
|
|
1721
|
+
case "decimal":
|
|
1722
|
+
return String(new import_decimal4.default(value));
|
|
1723
|
+
case "bigint-array":
|
|
1724
|
+
return value.map((v) => normalizeValue("bigint", v));
|
|
1725
|
+
case "decimal-array":
|
|
1726
|
+
return value.map((v) => normalizeValue("decimal", v));
|
|
1727
|
+
default:
|
|
1728
|
+
return value;
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
|
|
1461
1732
|
// src/transactionManager/TransactionManager.ts
|
|
1462
1733
|
var import_debug = require("@prisma/debug");
|
|
1463
1734
|
|
|
@@ -1734,5 +2005,6 @@ var TransactionManager = class {
|
|
|
1734
2005
|
isPrismaValuePlaceholder,
|
|
1735
2006
|
noopTracingHelper,
|
|
1736
2007
|
normalizeJsonProtocolValues,
|
|
2008
|
+
normalizeRawJsonProtocolResponse,
|
|
1737
2009
|
safeJsonStringify
|
|
1738
2010
|
});
|