@@ -11,6 +11,9 @@ import type {
11
11
12
12
import {
13
13
CompiledQuery ,
14
+ createQueryId ,
15
+ IdentifierNode ,
16
+ RawNode ,
14
17
SqliteAdapter ,
15
18
SqliteIntrospector ,
16
19
SqliteQueryCompiler ,
@@ -64,6 +67,13 @@ class ConnectionMutex {
64
67
}
65
68
}
66
69
70
+ export function parseSavepointCommand ( command : string , savepointName : string ) {
71
+ return RawNode . createWithChildren ( [
72
+ RawNode . createWithSql ( `${ command } ` ) ,
73
+ IdentifierNode . create ( savepointName ) , // ensures savepointName gets sanitized
74
+ ] )
75
+ }
76
+
67
77
export abstract class BaseSqliteDriver implements Driver {
68
78
private mutex = new ConnectionMutex ( )
69
79
public conn ?: DatabaseConnection
@@ -97,6 +107,30 @@ export abstract class BaseSqliteDriver implements Driver {
97
107
await connection . executeQuery ( CompiledQuery . raw ( 'rollback' ) )
98
108
}
99
109
110
+ async savepoint (
111
+ connection : DatabaseConnection ,
112
+ savepointName : string ,
113
+ compileQuery : QueryCompiler [ 'compileQuery' ] ,
114
+ ) : Promise < void > {
115
+ await connection . executeQuery ( compileQuery ( parseSavepointCommand ( 'savepoint' , savepointName ) , createQueryId ( ) ) )
116
+ }
117
+
118
+ async rollbackToSavepoint (
119
+ connection : DatabaseConnection ,
120
+ savepointName : string ,
121
+ compileQuery : QueryCompiler [ 'compileQuery' ] ,
122
+ ) : Promise < void > {
123
+ await connection . executeQuery ( compileQuery ( parseSavepointCommand ( 'rollback to' , savepointName ) , createQueryId ( ) ) )
124
+ }
125
+
126
+ async releaseSavepoint (
127
+ connection : DatabaseConnection ,
128
+ savepointName : string ,
129
+ compileQuery : QueryCompiler [ 'compileQuery' ] ,
130
+ ) : Promise < void > {
131
+ await connection . executeQuery ( compileQuery ( parseSavepointCommand ( 'release' , savepointName ) , createQueryId ( ) ) )
132
+ }
133
+
100
134
async releaseConnection ( ) : Promise < void > {
101
135
this . mutex . unlock ( )
102
136
}
0 commit comments