@avelonjs/neon 0.8.5 → 0.8.7
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 +4 -4
- package/src/database/driver.ts +32 -29
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@avelonjs/neon",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.7",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Neon drivers for Avelon's database, identity, social, tokens, storage, and queue contracts.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,14 +39,14 @@
|
|
|
39
39
|
"typecheck": "tsc --noEmit"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@avelonjs/core": "
|
|
43
|
-
"@avelonjs/postgres": "
|
|
42
|
+
"@avelonjs/core": "0.8.7",
|
|
43
|
+
"@avelonjs/postgres": "0.8.7",
|
|
44
44
|
"@aws-sdk/client-s3": "3.899.0",
|
|
45
45
|
"@aws-sdk/s3-request-presigner": "3.899.0",
|
|
46
46
|
"@neondatabase/serverless": "1.0.2"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@avelonjs/conformance": "
|
|
49
|
+
"@avelonjs/conformance": "0.8.7",
|
|
50
50
|
"@types/bun": "1.3.14",
|
|
51
51
|
"typescript": "5.9.3"
|
|
52
52
|
},
|
package/src/database/driver.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { neon, Pool, type PoolClient } from '@neondatabase/serverless'
|
|
2
2
|
import {
|
|
3
3
|
Invalid,
|
|
4
|
+
runInTransaction,
|
|
4
5
|
type DatabaseDriver,
|
|
5
6
|
type DatabaseTransaction,
|
|
6
7
|
type MigrationPlan,
|
|
@@ -191,36 +192,38 @@ export class NeonDatabase
|
|
|
191
192
|
async transaction<TResult>(
|
|
192
193
|
callback: (transaction: DatabaseTransaction) => Promise<TResult>,
|
|
193
194
|
): Promise<TResult> {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
try {
|
|
200
|
-
await client.query('BEGIN')
|
|
201
|
-
const result = await callback({
|
|
202
|
-
execute: <TRow = Record<string, unknown>>(query: QueryIR) =>
|
|
203
|
-
this.#execute(runner, query) as Promise<QueryResult<TRow>>,
|
|
204
|
-
rpc: <TResultRpc = unknown>(routine: string, args: Readonly<Record<string, unknown>>) =>
|
|
205
|
-
executeRpc(runner, routine, args, this.#countRoundTrip) as Promise<TResultRpc>,
|
|
206
|
-
})
|
|
207
|
-
await client.query('COMMIT')
|
|
208
|
-
return result
|
|
209
|
-
} catch (error) {
|
|
210
|
-
await client.query('ROLLBACK').catch(() => undefined)
|
|
211
|
-
if (
|
|
212
|
-
error instanceof Invalid ||
|
|
213
|
-
(error instanceof Error &&
|
|
214
|
-
(error.name === 'Conflict' ||
|
|
215
|
-
error.name === 'DriverFault' ||
|
|
216
|
-
error.name === 'Unavailable'))
|
|
217
|
-
) {
|
|
218
|
-
throw error
|
|
195
|
+
return runInTransaction(async () => {
|
|
196
|
+
const client = await this.#connect()
|
|
197
|
+
const runner: SqlRunner = {
|
|
198
|
+
unsafe: async (text, parameters) =>
|
|
199
|
+
toSqlRows(await client.query(text, parameters === undefined ? [] : [...parameters])),
|
|
219
200
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
201
|
+
try {
|
|
202
|
+
await client.query('BEGIN')
|
|
203
|
+
const result = await callback({
|
|
204
|
+
execute: <TRow = Record<string, unknown>>(query: QueryIR) =>
|
|
205
|
+
this.#execute(runner, query) as Promise<QueryResult<TRow>>,
|
|
206
|
+
rpc: <TResultRpc = unknown>(routine: string, args: Readonly<Record<string, unknown>>) =>
|
|
207
|
+
executeRpc(runner, routine, args, this.#countRoundTrip) as Promise<TResultRpc>,
|
|
208
|
+
})
|
|
209
|
+
await client.query('COMMIT')
|
|
210
|
+
return result
|
|
211
|
+
} catch (error) {
|
|
212
|
+
await client.query('ROLLBACK').catch(() => undefined)
|
|
213
|
+
if (
|
|
214
|
+
error instanceof Invalid ||
|
|
215
|
+
(error instanceof Error &&
|
|
216
|
+
(error.name === 'Conflict' ||
|
|
217
|
+
error.name === 'DriverFault' ||
|
|
218
|
+
error.name === 'Unavailable'))
|
|
219
|
+
) {
|
|
220
|
+
throw error
|
|
221
|
+
}
|
|
222
|
+
mapPostgresError(error, 'transaction')
|
|
223
|
+
} finally {
|
|
224
|
+
client.release()
|
|
225
|
+
}
|
|
226
|
+
})
|
|
224
227
|
}
|
|
225
228
|
|
|
226
229
|
readonly #countRoundTrip = (): void => {
|