@vibeorm/adapter-bun 1.1.0 → 1.1.1
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/package.json +2 -2
- package/src/index.ts +19 -32
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vibeorm/adapter-bun",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Bun-native database adapter for VibeORM using bun:sql",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"bun": ">=1.1.0"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@vibeorm/runtime": "1.1.
|
|
36
|
+
"@vibeorm/runtime": "1.1.1"
|
|
37
37
|
},
|
|
38
38
|
"publishConfig": {
|
|
39
39
|
"access": "public"
|
package/src/index.ts
CHANGED
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import type { DatabaseAdapter, QueryResult, TransactionOptions } from "@vibeorm/runtime";
|
|
10
|
-
import { normalizeError } from "@vibeorm/runtime";
|
|
11
10
|
|
|
12
11
|
export type BunAdapterOptions = {
|
|
13
12
|
/** PostgreSQL connection URL. Falls back to DATABASE_URL env var if not provided. */
|
|
@@ -241,45 +240,33 @@ export function bunAdapter(options?: BunAdapterOptions): DatabaseAdapter {
|
|
|
241
240
|
function createAdapter(sql: SqlInstance): DatabaseAdapter {
|
|
242
241
|
return {
|
|
243
242
|
async execute(params) {
|
|
244
|
-
|
|
245
|
-
return await executeQuery(sql, params);
|
|
246
|
-
} catch (err) {
|
|
247
|
-
throw normalizeError({ error: err });
|
|
248
|
-
}
|
|
243
|
+
return executeQuery(sql, params);
|
|
249
244
|
},
|
|
250
245
|
|
|
251
246
|
async executeUnsafe(params) {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
affectedRows = (result as unknown[]).length;
|
|
262
|
-
}
|
|
263
|
-
return {
|
|
264
|
-
rows: result as Record<string, unknown>[],
|
|
265
|
-
affectedRows,
|
|
266
|
-
};
|
|
267
|
-
} catch (err) {
|
|
268
|
-
throw normalizeError({ error: err });
|
|
247
|
+
const result = await sql.unsafe(params.text, params.values);
|
|
248
|
+
const resultAny = result as unknown as Record<string, unknown>;
|
|
249
|
+
let affectedRows: number;
|
|
250
|
+
if (typeof resultAny.count === "number") {
|
|
251
|
+
affectedRows = resultAny.count;
|
|
252
|
+
} else if (typeof resultAny.affectedRows === "number") {
|
|
253
|
+
affectedRows = resultAny.affectedRows;
|
|
254
|
+
} else {
|
|
255
|
+
affectedRows = (result as unknown[]).length;
|
|
269
256
|
}
|
|
257
|
+
return {
|
|
258
|
+
rows: result as Record<string, unknown>[],
|
|
259
|
+
affectedRows,
|
|
260
|
+
};
|
|
270
261
|
},
|
|
271
262
|
|
|
272
263
|
async transaction<T>(fn: (txAdapter: DatabaseAdapter) => Promise<T>, options?: TransactionOptions): Promise<T> {
|
|
273
264
|
// Fast path: no custom options — use native sql.begin() for best performance
|
|
274
265
|
if (!options?.isolationLevel && !options?.timeout) {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
});
|
|
280
|
-
} catch (err) {
|
|
281
|
-
throw normalizeError({ error: err });
|
|
282
|
-
}
|
|
266
|
+
return sql.begin(async (txSql: SqlInstance) => {
|
|
267
|
+
const txAdapter = createAdapter(txSql);
|
|
268
|
+
return fn(txAdapter);
|
|
269
|
+
});
|
|
283
270
|
}
|
|
284
271
|
|
|
285
272
|
// Manual path: reserve a connection for custom BEGIN options
|
|
@@ -300,7 +287,7 @@ export function bunAdapter(options?: BunAdapterOptions): DatabaseAdapter {
|
|
|
300
287
|
return result;
|
|
301
288
|
} catch (err) {
|
|
302
289
|
try { await reserved.unsafe("ROLLBACK"); } catch { /* rollback best-effort */ }
|
|
303
|
-
throw
|
|
290
|
+
throw err;
|
|
304
291
|
} finally {
|
|
305
292
|
reserved.release();
|
|
306
293
|
}
|