@prisma/adapter-libsql 6.15.0-dev.2 → 6.15.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.
@@ -148,9 +148,9 @@ var UnexpectedTypeError = class extends Error {
148
148
  }
149
149
  };
150
150
  function mapRow(row, columnTypes) {
151
- const result = Array.from(row);
152
- for (let i = 0; i < result.length; i++) {
153
- const value = result[i];
151
+ const result = [];
152
+ for (let i = 0; i < row.length; i++) {
153
+ const value = row[i];
154
154
  if (value instanceof ArrayBuffer) {
155
155
  result[i] = Array.from(new Uint8Array(value));
156
156
  continue;
@@ -167,9 +167,34 @@ function mapRow(row, columnTypes) {
167
167
  result[i] = value.toString();
168
168
  continue;
169
169
  }
170
+ result[i] = value;
170
171
  }
171
172
  return result;
172
173
  }
174
+ function mapArg(arg, argType) {
175
+ if (arg === null) {
176
+ return null;
177
+ }
178
+ if (typeof arg === "string" && argType.scalarType === "bigint") {
179
+ return BigInt(arg);
180
+ }
181
+ if (typeof arg === "string" && argType.scalarType === "decimal") {
182
+ return Number.parseFloat(arg);
183
+ }
184
+ if (typeof arg === "string" && argType.scalarType === "datetime") {
185
+ arg = new Date(arg);
186
+ }
187
+ if (arg instanceof Date) {
188
+ return arg.toISOString().replace("Z", "+00:00");
189
+ }
190
+ if (typeof arg === "string" && argType.scalarType === "bytes") {
191
+ return Buffer.from(arg, "base64");
192
+ }
193
+ if (Array.isArray(arg) && argType.scalarType === "bytes") {
194
+ return new Uint8Array(arg);
195
+ }
196
+ return arg;
197
+ }
173
198
 
174
199
  // src/errors.ts
175
200
  var SQLITE_BUSY = 5;
@@ -281,11 +306,11 @@ var LibSqlQueryable = class {
281
306
  */
282
307
  async performIO(query) {
283
308
  const release = await this[LOCK_TAG].acquire();
284
- if (query.args.some((arg) => Array.isArray(arg))) {
285
- throw new Error("Attempted to pass an array argument to the LibSQL client, which is not supported");
286
- }
287
309
  try {
288
- const result = await this.client.execute(query);
310
+ const result = await this.client.execute({
311
+ sql: query.sql,
312
+ args: query.args.map((arg, i) => mapArg(arg, query.argTypes[i]))
313
+ });
289
314
  return result;
290
315
  } catch (e) {
291
316
  this.onError(e);
@@ -122,9 +122,9 @@ var UnexpectedTypeError = class extends Error {
122
122
  }
123
123
  };
124
124
  function mapRow(row, columnTypes) {
125
- const result = Array.from(row);
126
- for (let i = 0; i < result.length; i++) {
127
- const value = result[i];
125
+ const result = [];
126
+ for (let i = 0; i < row.length; i++) {
127
+ const value = row[i];
128
128
  if (value instanceof ArrayBuffer) {
129
129
  result[i] = Array.from(new Uint8Array(value));
130
130
  continue;
@@ -141,9 +141,34 @@ function mapRow(row, columnTypes) {
141
141
  result[i] = value.toString();
142
142
  continue;
143
143
  }
144
+ result[i] = value;
144
145
  }
145
146
  return result;
146
147
  }
148
+ function mapArg(arg, argType) {
149
+ if (arg === null) {
150
+ return null;
151
+ }
152
+ if (typeof arg === "string" && argType.scalarType === "bigint") {
153
+ return BigInt(arg);
154
+ }
155
+ if (typeof arg === "string" && argType.scalarType === "decimal") {
156
+ return Number.parseFloat(arg);
157
+ }
158
+ if (typeof arg === "string" && argType.scalarType === "datetime") {
159
+ arg = new Date(arg);
160
+ }
161
+ if (arg instanceof Date) {
162
+ return arg.toISOString().replace("Z", "+00:00");
163
+ }
164
+ if (typeof arg === "string" && argType.scalarType === "bytes") {
165
+ return Buffer.from(arg, "base64");
166
+ }
167
+ if (Array.isArray(arg) && argType.scalarType === "bytes") {
168
+ return new Uint8Array(arg);
169
+ }
170
+ return arg;
171
+ }
147
172
 
148
173
  // src/errors.ts
149
174
  var SQLITE_BUSY = 5;
@@ -255,11 +280,11 @@ var LibSqlQueryable = class {
255
280
  */
256
281
  async performIO(query) {
257
282
  const release = await this[LOCK_TAG].acquire();
258
- if (query.args.some((arg) => Array.isArray(arg))) {
259
- throw new Error("Attempted to pass an array argument to the LibSQL client, which is not supported");
260
- }
261
283
  try {
262
- const result = await this.client.execute(query);
284
+ const result = await this.client.execute({
285
+ sql: query.sql,
286
+ args: query.args.map((arg, i) => mapArg(arg, query.argTypes[i]))
287
+ });
263
288
  return result;
264
289
  } catch (e) {
265
290
  this.onError(e);
package/dist/index-web.js CHANGED
@@ -148,9 +148,9 @@ var UnexpectedTypeError = class extends Error {
148
148
  }
149
149
  };
150
150
  function mapRow(row, columnTypes) {
151
- const result = Array.from(row);
152
- for (let i = 0; i < result.length; i++) {
153
- const value = result[i];
151
+ const result = [];
152
+ for (let i = 0; i < row.length; i++) {
153
+ const value = row[i];
154
154
  if (value instanceof ArrayBuffer) {
155
155
  result[i] = Array.from(new Uint8Array(value));
156
156
  continue;
@@ -167,9 +167,34 @@ function mapRow(row, columnTypes) {
167
167
  result[i] = value.toString();
168
168
  continue;
169
169
  }
170
+ result[i] = value;
170
171
  }
171
172
  return result;
172
173
  }
174
+ function mapArg(arg, argType) {
175
+ if (arg === null) {
176
+ return null;
177
+ }
178
+ if (typeof arg === "string" && argType.scalarType === "bigint") {
179
+ return BigInt(arg);
180
+ }
181
+ if (typeof arg === "string" && argType.scalarType === "decimal") {
182
+ return Number.parseFloat(arg);
183
+ }
184
+ if (typeof arg === "string" && argType.scalarType === "datetime") {
185
+ arg = new Date(arg);
186
+ }
187
+ if (arg instanceof Date) {
188
+ return arg.toISOString().replace("Z", "+00:00");
189
+ }
190
+ if (typeof arg === "string" && argType.scalarType === "bytes") {
191
+ return Buffer.from(arg, "base64");
192
+ }
193
+ if (Array.isArray(arg) && argType.scalarType === "bytes") {
194
+ return new Uint8Array(arg);
195
+ }
196
+ return arg;
197
+ }
173
198
 
174
199
  // src/errors.ts
175
200
  var SQLITE_BUSY = 5;
@@ -281,11 +306,11 @@ var LibSqlQueryable = class {
281
306
  */
282
307
  async performIO(query) {
283
308
  const release = await this[LOCK_TAG].acquire();
284
- if (query.args.some((arg) => Array.isArray(arg))) {
285
- throw new Error("Attempted to pass an array argument to the LibSQL client, which is not supported");
286
- }
287
309
  try {
288
- const result = await this.client.execute(query);
310
+ const result = await this.client.execute({
311
+ sql: query.sql,
312
+ args: query.args.map((arg, i) => mapArg(arg, query.argTypes[i]))
313
+ });
289
314
  return result;
290
315
  } catch (e) {
291
316
  this.onError(e);
@@ -122,9 +122,9 @@ var UnexpectedTypeError = class extends Error {
122
122
  }
123
123
  };
124
124
  function mapRow(row, columnTypes) {
125
- const result = Array.from(row);
126
- for (let i = 0; i < result.length; i++) {
127
- const value = result[i];
125
+ const result = [];
126
+ for (let i = 0; i < row.length; i++) {
127
+ const value = row[i];
128
128
  if (value instanceof ArrayBuffer) {
129
129
  result[i] = Array.from(new Uint8Array(value));
130
130
  continue;
@@ -141,9 +141,34 @@ function mapRow(row, columnTypes) {
141
141
  result[i] = value.toString();
142
142
  continue;
143
143
  }
144
+ result[i] = value;
144
145
  }
145
146
  return result;
146
147
  }
148
+ function mapArg(arg, argType) {
149
+ if (arg === null) {
150
+ return null;
151
+ }
152
+ if (typeof arg === "string" && argType.scalarType === "bigint") {
153
+ return BigInt(arg);
154
+ }
155
+ if (typeof arg === "string" && argType.scalarType === "decimal") {
156
+ return Number.parseFloat(arg);
157
+ }
158
+ if (typeof arg === "string" && argType.scalarType === "datetime") {
159
+ arg = new Date(arg);
160
+ }
161
+ if (arg instanceof Date) {
162
+ return arg.toISOString().replace("Z", "+00:00");
163
+ }
164
+ if (typeof arg === "string" && argType.scalarType === "bytes") {
165
+ return Buffer.from(arg, "base64");
166
+ }
167
+ if (Array.isArray(arg) && argType.scalarType === "bytes") {
168
+ return new Uint8Array(arg);
169
+ }
170
+ return arg;
171
+ }
147
172
 
148
173
  // src/errors.ts
149
174
  var SQLITE_BUSY = 5;
@@ -255,11 +280,11 @@ var LibSqlQueryable = class {
255
280
  */
256
281
  async performIO(query) {
257
282
  const release = await this[LOCK_TAG].acquire();
258
- if (query.args.some((arg) => Array.isArray(arg))) {
259
- throw new Error("Attempted to pass an array argument to the LibSQL client, which is not supported");
260
- }
261
283
  try {
262
- const result = await this.client.execute(query);
284
+ const result = await this.client.execute({
285
+ sql: query.sql,
286
+ args: query.args.map((arg, i) => mapArg(arg, query.argTypes[i]))
287
+ });
263
288
  return result;
264
289
  } catch (e) {
265
290
  this.onError(e);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/adapter-libsql",
3
- "version": "6.15.0-dev.2",
3
+ "version": "6.15.0-dev.21",
4
4
  "description": "Prisma's driver adapter for libSQL and Turso",
5
5
  "main": "dist/index-node.js",
6
6
  "module": "dist/index-node.mjs",
@@ -43,7 +43,7 @@
43
43
  "dependencies": {
44
44
  "@libsql/client": "^0.3.5 || ^0.4.0 || ^0.5.0 || ^0.6.0 || ^0.7.0 || ^0.8.0",
45
45
  "async-mutex": "0.5.0",
46
- "@prisma/driver-adapter-utils": "6.15.0-dev.2"
46
+ "@prisma/driver-adapter-utils": "6.15.0-dev.21"
47
47
  },
48
48
  "devDependencies": {
49
49
  "jest": "29.7.0",