@avelonjs/postgres 0.8.6 → 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 +3 -3
- package/src/driver.ts +24 -21
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@avelonjs/postgres",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.7",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Postgres database driver that compiles Avelon QueryIR to SQL.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,10 +39,10 @@
|
|
|
39
39
|
"fixtures:reset": "bun ./scripts/reset-fixtures.ts"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@avelonjs/core": "
|
|
42
|
+
"@avelonjs/core": "0.8.7"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@avelonjs/conformance": "
|
|
45
|
+
"@avelonjs/conformance": "0.8.7",
|
|
46
46
|
"@types/bun": "1.3.14",
|
|
47
47
|
"typescript": "5.9.3"
|
|
48
48
|
},
|
package/src/driver.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SQL } from 'bun'
|
|
2
2
|
import {
|
|
3
3
|
Invalid,
|
|
4
|
+
runInTransaction,
|
|
4
5
|
type DatabaseDriver,
|
|
5
6
|
type DatabaseTransaction,
|
|
6
7
|
type MigrationPlan,
|
|
@@ -145,29 +146,31 @@ export class PostgresDatabase
|
|
|
145
146
|
async transaction<TResult>(
|
|
146
147
|
callback: (transaction: DatabaseTransaction) => Promise<TResult>,
|
|
147
148
|
): Promise<TResult> {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
149
|
+
return runInTransaction(async () => {
|
|
150
|
+
try {
|
|
151
|
+
return await this.#sql.begin(async (tx) => {
|
|
152
|
+
const runner = bunSqlRunner(tx as SQL)
|
|
153
|
+
const transaction: DatabaseTransaction = {
|
|
154
|
+
execute: <TRow = Record<string, unknown>>(query: QueryIR) =>
|
|
155
|
+
this.#execute(runner, query) as Promise<QueryResult<TRow>>,
|
|
156
|
+
rpc: <TResultRpc = unknown>(routine: string, args: Readonly<Record<string, unknown>>) =>
|
|
157
|
+
executeRpc(runner, routine, args, this.#countRoundTrip) as Promise<TResultRpc>,
|
|
158
|
+
}
|
|
159
|
+
return callback(transaction)
|
|
160
|
+
})
|
|
161
|
+
} catch (error) {
|
|
162
|
+
if (
|
|
163
|
+
error instanceof Invalid ||
|
|
164
|
+
(error instanceof Error &&
|
|
165
|
+
(error.name === 'Conflict' ||
|
|
166
|
+
error.name === 'DriverFault' ||
|
|
167
|
+
error.name === 'Unavailable'))
|
|
168
|
+
) {
|
|
169
|
+
throw error
|
|
156
170
|
}
|
|
157
|
-
|
|
158
|
-
})
|
|
159
|
-
} catch (error) {
|
|
160
|
-
if (
|
|
161
|
-
error instanceof Invalid ||
|
|
162
|
-
(error instanceof Error &&
|
|
163
|
-
(error.name === 'Conflict' ||
|
|
164
|
-
error.name === 'DriverFault' ||
|
|
165
|
-
error.name === 'Unavailable'))
|
|
166
|
-
) {
|
|
167
|
-
throw error
|
|
171
|
+
mapPostgresError(error, 'transaction')
|
|
168
172
|
}
|
|
169
|
-
|
|
170
|
-
}
|
|
173
|
+
})
|
|
171
174
|
}
|
|
172
175
|
|
|
173
176
|
readonly #countRoundTrip = (): void => {
|