@@ -33,29 +33,29 @@ export class MemorySqlite {
33
33
)
34
34
35
35
static {
36
- this . pool . on ( " factoryCreateError" , function ( err ) {
37
- console . log ( 'factoryCreateError' , err ) ;
38
- } ) ;
39
-
40
- this . pool . on ( " factoryDestroyError" , function ( err ) {
41
- console . log ( 'factoryDestroyError' , err ) ;
42
- } ) ;
36
+ this . pool . on ( ' factoryCreateError' , function ( err ) {
37
+ console . log ( 'factoryCreateError' , err )
38
+ } )
39
+
40
+ this . pool . on ( ' factoryDestroyError' , function ( err ) {
41
+ console . log ( 'factoryDestroyError' , err )
42
+ } )
43
43
}
44
44
45
45
static async acquire ( ) : Promise < DB > {
46
46
const db = await this . pool . acquire ( )
47
47
48
48
// delete all tables
49
- // const tables = db
50
- // .prepare<
51
- // [],
52
- // { name: string }
53
- // >("SELECT name FROM sqlite_master WHERE type='table'")
54
- // .all()
49
+ const tables = db
50
+ . prepare <
51
+ [ ] ,
52
+ { name : string }
53
+ > ( "SELECT name FROM sqlite_master WHERE type='table'" )
54
+ . all ( )
55
55
56
- // for (const table of tables) {
57
- // db.prepare(`DELETE FROM ${table.name}`).run()
58
- // }
56
+ for ( const table of tables ) {
57
+ db . prepare ( `DELETE FROM ${ table . name } ` ) . run ( )
58
+ }
59
59
60
60
return db
61
61
}
@@ -64,9 +64,7 @@ export class MemorySqlite {
64
64
await this . pool . release ( db )
65
65
}
66
66
67
- static async withMemDb < T > (
68
- callback : ( db : DB ) => Promise < T >
69
- ) : Promise < T > {
67
+ static async withMemDb < T > ( callback : ( db : DB ) => Promise < T > ) : Promise < T > {
70
68
const db = await this . acquire ( )
71
69
try {
72
70
return await callback ( db )
0 commit comments