@@ -11,13 +11,16 @@ try {
1111}
1212
1313import { DB_LOCATION , DB_NAME } from './constants' ;
14+ import { QuickSqliteClient_v4 } from './QuickSqliteClient_v4' ;
1415import { tables } from './schema' ;
1516import { createCreateTableQuery } from './sqlite-utils/createCreateTableQuery' ;
1617import type { PreparedQueries , Table } from './types' ;
1718
1819/**
1920 * QuickSqliteClient takes care of any direct interaction with sqlite.
2021 * This way usage react-native-quick-sqlite package is scoped to a single class/file.
22+ *
23+ * TODO: Drop the support for v4 of react-native-quick-sqlite in the next major release.
2124 */
2225export class QuickSqliteClient {
2326 static dbVersion = 3 ;
@@ -29,7 +32,16 @@ export class QuickSqliteClient {
2932 // Force a specific db version. This is mainly useful for testsuit.
3033 static setDbVersion = ( version : number ) => ( this . dbVersion = version ) ;
3134
35+ // @ts -ignore
36+ static isQuickSqliteV4 = sqlite . executeSql ? true : false ;
37+
38+ // print if legacy version
3239 static openDB = ( ) => {
40+ if ( this . isQuickSqliteV4 ) {
41+ QuickSqliteClient_v4 . openDB ( ) ;
42+ return ;
43+ }
44+
3345 try {
3446 sqlite . open ( this . dbName , this . dbLocation ) ;
3547 sqlite . execute ( this . dbName , `PRAGMA foreign_keys = ON` , [ ] ) ;
@@ -39,6 +51,11 @@ export class QuickSqliteClient {
3951 } ;
4052
4153 static closeDB = ( ) => {
54+ if ( this . isQuickSqliteV4 ) {
55+ QuickSqliteClient_v4 . closeDB ( ) ;
56+ return ;
57+ }
58+
4259 try {
4360 sqlite . close ( this . dbName ) ;
4461 } catch ( e ) {
@@ -48,10 +65,16 @@ export class QuickSqliteClient {
4865
4966 static executeSqlBatch = ( queries : PreparedQueries [ ] ) => {
5067 if ( ! queries || ! queries . length ) return ;
51- this . openDB ( ) ;
5268
69+ if ( this . isQuickSqliteV4 ) {
70+ QuickSqliteClient_v4 . executeSqlBatch ( queries ) ;
71+ return ;
72+ }
73+
74+ this . openDB ( ) ;
5375 try {
5476 sqlite . executeBatch ( DB_NAME , queries ) ;
77+
5578 this . closeDB ( ) ;
5679 } catch ( e ) {
5780 this . closeDB ( ) ;
@@ -62,6 +85,10 @@ export class QuickSqliteClient {
6285 static executeSql = ( query : string , params ?: string [ ] ) => {
6386 this . openDB ( ) ;
6487
88+ if ( this . isQuickSqliteV4 ) {
89+ return QuickSqliteClient_v4 . executeSql ( query , params ) ;
90+ }
91+
6592 try {
6693 const { rows } = sqlite . execute ( DB_NAME , query , params ) ;
6794 this . closeDB ( ) ;
@@ -83,6 +110,10 @@ export class QuickSqliteClient {
83110 } ;
84111
85112 static deleteDatabase = ( ) => {
113+ if ( this . isQuickSqliteV4 ) {
114+ return QuickSqliteClient_v4 . deleteDatabase ( ) ;
115+ }
116+
86117 try {
87118 sqlite . delete ( this . dbName , this . dbLocation ) ;
88119 } catch ( e ) {
@@ -100,6 +131,14 @@ export class QuickSqliteClient {
100131 ) ;
101132 }
102133
134+ if ( this . isQuickSqliteV4 ) {
135+ console . warn (
136+ 'You seem to be using an older version of "react-native-quick-sqlite" dependency,' ,
137+ 'and we are going to drop support for it in the next major release.' ,
138+ 'Please upgrade to the version v5 of "react-native-quick-sqlite" to avoid any issues.' ,
139+ ) ;
140+ }
141+
103142 const version = this . getUserPragmaVersion ( ) ;
104143
105144 if ( version !== this . dbVersion ) {
@@ -118,16 +157,22 @@ export class QuickSqliteClient {
118157 } ;
119158
120159 static updateUserPragmaVersion = ( version : number ) => {
121- this . openDB ( ) ;
160+ if ( this . isQuickSqliteV4 ) {
161+ QuickSqliteClient_v4 . updateUserPragmaVersion ( version ) ;
162+ return ;
163+ }
122164
165+ this . openDB ( ) ;
123166 sqlite . execute ( DB_NAME , `PRAGMA user_version = ${ version } ` , [ ] ) ;
124-
125167 this . closeDB ( ) ;
126168 } ;
127169
128170 static getUserPragmaVersion = ( ) => {
129- this . openDB ( ) ;
171+ if ( this . isQuickSqliteV4 ) {
172+ return QuickSqliteClient_v4 . getUserPragmaVersion ( ) ;
173+ }
130174
175+ this . openDB ( ) ;
131176 try {
132177 const { rows } = sqlite . execute ( DB_NAME , `PRAGMA user_version` , [ ] ) ;
133178 const result = rows ? rows . _array : [ ] ;
0 commit comments