File tree Expand file tree Collapse file tree 6 files changed +69
-12
lines changed Expand file tree Collapse file tree 6 files changed +69
-12
lines changed Original file line number Diff line number Diff line change @@ -210,18 +210,17 @@ function Postgres(a, b) {
210
210
const sql = Sql ( handler )
211
211
sql . savepoint = savepoint
212
212
let uncaughtError
213
+ , result
214
+
213
215
name && await sql `savepoint ${ sql ( name ) } `
214
216
try {
215
- const result = await new Promise ( ( resolve , reject ) => {
217
+ result = await new Promise ( ( resolve , reject ) => {
216
218
const x = fn ( sql )
217
219
Promise . resolve ( Array . isArray ( x ) ? Promise . all ( x ) : x ) . then ( resolve , reject )
218
220
} )
219
221
220
222
if ( uncaughtError )
221
223
throw uncaughtError
222
-
223
- ! name && await sql `commit`
224
- return result
225
224
} catch ( e ) {
226
225
await ( name
227
226
? sql `rollback to ${ sql ( name ) } `
@@ -230,6 +229,9 @@ function Postgres(a, b) {
230
229
throw e instanceof PostgresError && e . code === '25P02' && uncaughtError || e
231
230
}
232
231
232
+ ! name && await sql `commit`
233
+ return result
234
+
233
235
function savepoint ( name , fn ) {
234
236
if ( name && Array . isArray ( name . raw ) )
235
237
return savepoint ( sql => sql . apply ( sql , arguments ) )
Original file line number Diff line number Diff line change @@ -2123,3 +2123,20 @@ t('Supports arrays of fragments', async() => {
2123
2123
x
2124
2124
]
2125
2125
} )
2126
+
2127
+ t ( 'Does not try rollback when commit errors' , async ( ) => {
2128
+ let notice = null
2129
+ const sql = postgres ( { ...options , onnotice : x => notice = x } )
2130
+ await sql `create table test(x int constraint test_constraint unique deferrable initially deferred)`
2131
+
2132
+ await sql . begin ( 'isolation level serializable' , async sql => {
2133
+ await sql `insert into test values(1)`
2134
+ await sql `insert into test values(1)`
2135
+ } ) . catch ( e => e )
2136
+
2137
+ return [
2138
+ notice ,
2139
+ null ,
2140
+ await sql `drop table test`
2141
+ ]
2142
+ } )
Original file line number Diff line number Diff line change @@ -211,18 +211,17 @@ function Postgres(a, b) {
211
211
const sql = Sql ( handler )
212
212
sql . savepoint = savepoint
213
213
let uncaughtError
214
+ , result
215
+
214
216
name && await sql `savepoint ${ sql ( name ) } `
215
217
try {
216
- const result = await new Promise ( ( resolve , reject ) => {
218
+ result = await new Promise ( ( resolve , reject ) => {
217
219
const x = fn ( sql )
218
220
Promise . resolve ( Array . isArray ( x ) ? Promise . all ( x ) : x ) . then ( resolve , reject )
219
221
} )
220
222
221
223
if ( uncaughtError )
222
224
throw uncaughtError
223
-
224
- ! name && await sql `commit`
225
- return result
226
225
} catch ( e ) {
227
226
await ( name
228
227
? sql `rollback to ${ sql ( name ) } `
@@ -231,6 +230,9 @@ function Postgres(a, b) {
231
230
throw e instanceof PostgresError && e . code === '25P02' && uncaughtError || e
232
231
}
233
232
233
+ ! name && await sql `commit`
234
+ return result
235
+
234
236
function savepoint ( name , fn ) {
235
237
if ( name && Array . isArray ( name . raw ) )
236
238
return savepoint ( sql => sql . apply ( sql , arguments ) )
Original file line number Diff line number Diff line change @@ -2126,4 +2126,21 @@ t('Supports arrays of fragments', async() => {
2126
2126
]
2127
2127
} )
2128
2128
2129
+ t ( 'Does not try rollback when commit errors' , async ( ) => {
2130
+ let notice = null
2131
+ const sql = postgres ( { ...options , onnotice : x => notice = x } )
2132
+ await sql `create table test(x int constraint test_constraint unique deferrable initially deferred)`
2133
+
2134
+ await sql . begin ( 'isolation level serializable' , async sql => {
2135
+ await sql `insert into test values(1)`
2136
+ await sql `insert into test values(1)`
2137
+ } ) . catch ( e => e )
2138
+
2139
+ return [
2140
+ notice ,
2141
+ null ,
2142
+ await sql `drop table test`
2143
+ ]
2144
+ } )
2145
+
2129
2146
; window . addEventListener ( "unload" , ( ) => Deno . exit ( process . exitCode ) )
Original file line number Diff line number Diff line change @@ -210,18 +210,17 @@ function Postgres(a, b) {
210
210
const sql = Sql ( handler )
211
211
sql . savepoint = savepoint
212
212
let uncaughtError
213
+ , result
214
+
213
215
name && await sql `savepoint ${ sql ( name ) } `
214
216
try {
215
- const result = await new Promise ( ( resolve , reject ) => {
217
+ result = await new Promise ( ( resolve , reject ) => {
216
218
const x = fn ( sql )
217
219
Promise . resolve ( Array . isArray ( x ) ? Promise . all ( x ) : x ) . then ( resolve , reject )
218
220
} )
219
221
220
222
if ( uncaughtError )
221
223
throw uncaughtError
222
-
223
- ! name && await sql `commit`
224
- return result
225
224
} catch ( e ) {
226
225
await ( name
227
226
? sql `rollback to ${ sql ( name ) } `
@@ -230,6 +229,9 @@ function Postgres(a, b) {
230
229
throw e instanceof PostgresError && e . code === '25P02' && uncaughtError || e
231
230
}
232
231
232
+ ! name && await sql `commit`
233
+ return result
234
+
233
235
function savepoint ( name , fn ) {
234
236
if ( name && Array . isArray ( name . raw ) )
235
237
return savepoint ( sql => sql . apply ( sql , arguments ) )
Original file line number Diff line number Diff line change @@ -2123,3 +2123,20 @@ t('Supports arrays of fragments', async() => {
2123
2123
x
2124
2124
]
2125
2125
} )
2126
+
2127
+ t ( 'Does not try rollback when commit errors' , async ( ) => {
2128
+ let notice = null
2129
+ const sql = postgres ( { ...options , onnotice : x => notice = x } )
2130
+ await sql `create table test(x int constraint test_constraint unique deferrable initially deferred)`
2131
+
2132
+ await sql . begin ( 'isolation level serializable' , async sql => {
2133
+ await sql `insert into test values(1)`
2134
+ await sql `insert into test values(1)`
2135
+ } ) . catch ( e => e )
2136
+
2137
+ return [
2138
+ notice ,
2139
+ null ,
2140
+ await sql `drop table test`
2141
+ ]
2142
+ } )
You can’t perform that action at this time.
0 commit comments