@@ -17,20 +17,33 @@ let knexInstance;
1717function configure ( dbConfig ) {
1818 const client = dbConfig . client ;
1919
20- if ( client === 'sqlite3' ) {
20+ if ( client === 'sqlite3' || client === 'node-sqlite' ) {
2121 // Backwards compatibility with old knex behaviour
2222 dbConfig . useNullAsDefault = Object . prototype . hasOwnProperty . call ( dbConfig , 'useNullAsDefault' ) ? dbConfig . useNullAsDefault : true ;
2323
2424 // Enables foreign key checks and delete on cascade
2525 dbConfig . pool = {
2626 afterCreate ( conn , cb ) {
27- conn . run ( 'PRAGMA foreign_keys = ON' , cb ) ;
27+ if ( client === 'sqlite3' ) {
28+ conn . run ( 'PRAGMA foreign_keys = ON' , cb ) ;
2829
29- // These two are meant to improve performance at the cost of reliability
30- // Should be safe for tests. We add them here and leave them on
31- if ( config . get ( 'env' ) . startsWith ( 'testing' ) ) {
32- conn . run ( 'PRAGMA synchronous = OFF;' ) ;
33- conn . run ( 'PRAGMA journal_mode = TRUNCATE;' ) ;
30+ // These two are meant to improve performance at the cost of reliability
31+ // Should be safe for tests. We add them here and leave them on
32+ if ( config . get ( 'env' ) . startsWith ( 'testing' ) ) {
33+ conn . run ( 'PRAGMA synchronous = OFF;' ) ;
34+ conn . run ( 'PRAGMA journal_mode = TRUNCATE;' ) ;
35+ }
36+ } else if ( client === 'node-sqlite' ) {
37+ // node-sqlite uses exec for PRAGMA statements
38+ conn . exec ( 'PRAGMA foreign_keys = ON' ) ;
39+
40+ // These two are meant to improve performance at the cost of reliability
41+ // Should be safe for tests. We add them here and leave them on
42+ if ( config . get ( 'env' ) . startsWith ( 'testing' ) ) {
43+ conn . exec ( 'PRAGMA synchronous = OFF' ) ;
44+ conn . exec ( 'PRAGMA journal_mode = TRUNCATE' ) ;
45+ }
46+ cb ( ) ;
3447 }
3548 }
3649 } ;
0 commit comments