@prisma/adapter-planetscale 6.15.0-dev.3 → 6.15.0-dev.5

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.js CHANGED
@@ -120,6 +120,50 @@ var cast = (field, value) => {
120
120
  }
121
121
  return defaultValue;
122
122
  };
123
+ function mapArg(arg, argType) {
124
+ if (arg === null) {
125
+ return null;
126
+ }
127
+ if (typeof arg === "string" && argType.scalarType === "bigint") {
128
+ return BigInt(arg);
129
+ }
130
+ if (argType.scalarType === "datetime" && typeof arg === "string") {
131
+ arg = new Date(arg);
132
+ }
133
+ if (arg instanceof Date) {
134
+ switch (argType.dbType) {
135
+ case "TIME":
136
+ case "TIME2":
137
+ return formatTime(arg);
138
+ case "DATE":
139
+ case "NEWDATE":
140
+ return formatDate(arg);
141
+ default:
142
+ return formatDateTime(arg);
143
+ }
144
+ }
145
+ if (typeof arg === "string" && argType.scalarType === "bytes") {
146
+ return Buffer.from(arg, "base64");
147
+ }
148
+ if (Array.isArray(arg) && argType.scalarType === "bytes") {
149
+ return Buffer.from(arg);
150
+ }
151
+ return arg;
152
+ }
153
+ function formatDateTime(date) {
154
+ const pad = (n, z = 2) => String(n).padStart(z, "0");
155
+ const ms = date.getMilliseconds();
156
+ return date.getFullYear() + "-" + pad(date.getMonth() + 1) + "-" + pad(date.getDate()) + " " + pad(date.getHours()) + ":" + pad(date.getMinutes()) + ":" + pad(date.getSeconds()) + (ms ? "." + String(ms).padStart(3, "0") : "");
157
+ }
158
+ function formatDate(date) {
159
+ const pad = (n, z = 2) => String(n).padStart(z, "0");
160
+ return date.getFullYear() + "-" + pad(date.getMonth() + 1) + "-" + pad(date.getDate());
161
+ }
162
+ function formatTime(date) {
163
+ const pad = (n, z = 2) => String(n).padStart(z, "0");
164
+ const ms = date.getMilliseconds();
165
+ return pad(date.getHours()) + ":" + pad(date.getMinutes()) + ":" + pad(date.getSeconds()) + (ms ? "." + String(ms).padStart(3, "0") : "");
166
+ }
123
167
 
124
168
  // src/deferred.ts
125
169
  function createDeferred() {
@@ -299,12 +343,16 @@ var PlanetScaleQueryable = class {
299
343
  * marked as unhealthy.
300
344
  */
301
345
  async performIO(query) {
302
- const { sql, args: values } = query;
346
+ const { sql, args } = query;
303
347
  try {
304
- const result = await this.client.execute(sql, values, {
305
- as: "array",
306
- cast
307
- });
348
+ const result = await this.client.execute(
349
+ sql,
350
+ args.map((arg, i) => mapArg(arg, query.argTypes[i])),
351
+ {
352
+ as: "array",
353
+ cast
354
+ }
355
+ );
308
356
  return result;
309
357
  } catch (e) {
310
358
  const error = e;
package/dist/index.mjs CHANGED
@@ -84,6 +84,50 @@ var cast = (field, value) => {
84
84
  }
85
85
  return defaultValue;
86
86
  };
87
+ function mapArg(arg, argType) {
88
+ if (arg === null) {
89
+ return null;
90
+ }
91
+ if (typeof arg === "string" && argType.scalarType === "bigint") {
92
+ return BigInt(arg);
93
+ }
94
+ if (argType.scalarType === "datetime" && typeof arg === "string") {
95
+ arg = new Date(arg);
96
+ }
97
+ if (arg instanceof Date) {
98
+ switch (argType.dbType) {
99
+ case "TIME":
100
+ case "TIME2":
101
+ return formatTime(arg);
102
+ case "DATE":
103
+ case "NEWDATE":
104
+ return formatDate(arg);
105
+ default:
106
+ return formatDateTime(arg);
107
+ }
108
+ }
109
+ if (typeof arg === "string" && argType.scalarType === "bytes") {
110
+ return Buffer.from(arg, "base64");
111
+ }
112
+ if (Array.isArray(arg) && argType.scalarType === "bytes") {
113
+ return Buffer.from(arg);
114
+ }
115
+ return arg;
116
+ }
117
+ function formatDateTime(date) {
118
+ const pad = (n, z = 2) => String(n).padStart(z, "0");
119
+ const ms = date.getMilliseconds();
120
+ return date.getFullYear() + "-" + pad(date.getMonth() + 1) + "-" + pad(date.getDate()) + " " + pad(date.getHours()) + ":" + pad(date.getMinutes()) + ":" + pad(date.getSeconds()) + (ms ? "." + String(ms).padStart(3, "0") : "");
121
+ }
122
+ function formatDate(date) {
123
+ const pad = (n, z = 2) => String(n).padStart(z, "0");
124
+ return date.getFullYear() + "-" + pad(date.getMonth() + 1) + "-" + pad(date.getDate());
125
+ }
126
+ function formatTime(date) {
127
+ const pad = (n, z = 2) => String(n).padStart(z, "0");
128
+ const ms = date.getMilliseconds();
129
+ return pad(date.getHours()) + ":" + pad(date.getMinutes()) + ":" + pad(date.getSeconds()) + (ms ? "." + String(ms).padStart(3, "0") : "");
130
+ }
87
131
 
88
132
  // src/deferred.ts
89
133
  function createDeferred() {
@@ -263,12 +307,16 @@ var PlanetScaleQueryable = class {
263
307
  * marked as unhealthy.
264
308
  */
265
309
  async performIO(query) {
266
- const { sql, args: values } = query;
310
+ const { sql, args } = query;
267
311
  try {
268
- const result = await this.client.execute(sql, values, {
269
- as: "array",
270
- cast
271
- });
312
+ const result = await this.client.execute(
313
+ sql,
314
+ args.map((arg, i) => mapArg(arg, query.argTypes[i])),
315
+ {
316
+ as: "array",
317
+ cast
318
+ }
319
+ );
272
320
  return result;
273
321
  } catch (e) {
274
322
  const error = e;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/adapter-planetscale",
3
- "version": "6.15.0-dev.3",
3
+ "version": "6.15.0-dev.5",
4
4
  "description": "Prisma's driver adapter for \"@planetscale/database\"",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -33,7 +33,7 @@
33
33
  "dependencies": {
34
34
  "async-mutex": "0.5.0",
35
35
  "@planetscale/database": "^1.15.0",
36
- "@prisma/driver-adapter-utils": "6.15.0-dev.3"
36
+ "@prisma/driver-adapter-utils": "6.15.0-dev.5"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@swc/core": "1.11.5",