@@ -123,23 +123,23 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
123
123
callback ( null )
124
124
}
125
125
126
- function checkEncoding ( tx : Transaction ) {
127
- const res = tx . execute ( "SELECT HEX('a') AS hex" )
128
- const hex = res . rows ?. item ( 0 ) . hex
126
+ async function checkEncoding ( tx : Transaction ) {
127
+ const res = await tx . execute ( "SELECT HEX('a') AS hex" )
128
+ const hex = res . rows [ 0 ] ! . hex as string
129
129
encoding = hex . length === 2 ? 'UTF-8' : 'UTF-16'
130
130
}
131
131
132
- function fetchVersion ( tx : Transaction ) {
132
+ async function fetchVersion ( tx : Transaction ) {
133
133
const sql = 'SELECT sql FROM sqlite_master WHERE tbl_name = ' + META_STORE
134
- const result = tx . execute ( sql , [ ] )
134
+ const result = await tx . execute ( sql , [ ] )
135
135
if ( ! result . rows ?. length ) {
136
136
onGetVersion ( tx , 0 )
137
- } else if ( ! / d b _ v e r s i o n / . test ( result . rows . item ( 0 ) . sql ) ) {
137
+ } else if ( ! / d b _ v e r s i o n / . test ( result . rows [ 0 ] ! . sql as string ) ) {
138
138
tx . execute ( 'ALTER TABLE ' + META_STORE + ' ADD COLUMN db_version INTEGER' )
139
139
onGetVersion ( tx , 1 )
140
140
} else {
141
- const resDBVer = tx . execute ( 'SELECT db_version FROM ' + META_STORE )
142
- const dbVersion = resDBVer . rows ?. item ( 0 ) . db_version
141
+ const resDBVer = await tx . execute ( 'SELECT db_version FROM ' + META_STORE )
142
+ const dbVersion = resDBVer . rows [ 0 ] ! . db_version as number
143
143
onGetVersion ( tx , dbVersion )
144
144
}
145
145
}
@@ -152,7 +152,7 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
152
152
}
153
153
}
154
154
155
- function createInitialSchema ( tx : Transaction ) {
155
+ async function createInitialSchema ( tx : Transaction ) {
156
156
const meta =
157
157
'CREATE TABLE IF NOT EXISTS ' + META_STORE + ' (dbid, db_version INTEGER)'
158
158
const attach =
@@ -174,22 +174,22 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
174
174
const local =
175
175
'CREATE TABLE IF NOT EXISTS ' + LOCAL_STORE + ' (id UNIQUE, rev, json)'
176
176
177
- tx . execute ( attach )
178
- tx . execute ( local )
179
- tx . execute ( attachAndRev )
180
- tx . execute ( ATTACH_AND_SEQ_STORE_SEQ_INDEX_SQL )
181
- tx . execute ( ATTACH_AND_SEQ_STORE_ATTACH_INDEX_SQL )
182
- tx . execute ( doc )
183
- tx . execute ( DOC_STORE_WINNINGSEQ_INDEX_SQL )
184
- tx . execute ( seq )
185
- tx . execute ( BY_SEQ_STORE_DELETED_INDEX_SQL )
186
- tx . execute ( BY_SEQ_STORE_DOC_ID_REV_INDEX_SQL )
187
- tx . execute ( meta )
177
+ await tx . execute ( attach )
178
+ await tx . execute ( local )
179
+ await tx . execute ( attachAndRev )
180
+ await tx . execute ( ATTACH_AND_SEQ_STORE_SEQ_INDEX_SQL )
181
+ await tx . execute ( ATTACH_AND_SEQ_STORE_ATTACH_INDEX_SQL )
182
+ await tx . execute ( doc )
183
+ await tx . execute ( DOC_STORE_WINNINGSEQ_INDEX_SQL )
184
+ await tx . execute ( seq )
185
+ await tx . execute ( BY_SEQ_STORE_DELETED_INDEX_SQL )
186
+ await tx . execute ( BY_SEQ_STORE_DOC_ID_REV_INDEX_SQL )
187
+ await tx . execute ( meta )
188
188
const initSeq =
189
189
'INSERT INTO ' + META_STORE + ' (db_version, dbid) VALUES (?,?)'
190
190
instanceId = uuid ( )
191
191
const initSeqArgs = [ ADAPTER_VERSION , instanceId ]
192
- tx . execute ( initSeq , initSeqArgs )
192
+ await tx . execute ( initSeq , initSeqArgs )
193
193
onGetInstanceId ( )
194
194
}
195
195
@@ -205,12 +205,12 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
205
205
206
206
const migrated = dbVersion < ADAPTER_VERSION
207
207
if ( migrated ) {
208
- db . execute (
208
+ await db . execute (
209
209
'UPDATE ' + META_STORE + ' SET db_version = ' + ADAPTER_VERSION
210
210
)
211
211
}
212
- const result = db . execute ( 'SELECT dbid FROM ' + META_STORE )
213
- instanceId = result . rows ?. item ( 0 ) . dbid
212
+ const result = await db . execute ( 'SELECT dbid FROM ' + META_STORE )
213
+ instanceId = result . rows [ 0 ] ! . dbid as string
214
214
onGetInstanceId ( )
215
215
}
216
216
@@ -324,19 +324,23 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
324
324
sqlArgs = [ id , opts . rev ]
325
325
}
326
326
327
- tx . executeAsync ( sql , sqlArgs ) . then ( ( results ) => {
327
+ tx . execute ( sql , sqlArgs ) . then ( ( results ) => {
328
328
if ( ! results . rows ?. length ) {
329
329
const missingErr = createError ( MISSING_DOC , 'missing' )
330
330
return finish ( missingErr )
331
331
}
332
- const item = results . rows . item ( 0 )
332
+ const item = results . rows [ 0 ] !
333
333
metadata = safeJsonParse ( item . metadata )
334
334
if ( item . deleted && ! opts . rev ) {
335
335
const deletedErr = createError ( MISSING_DOC , 'deleted' )
336
336
return finish ( deletedErr )
337
337
}
338
- doc = unstringifyDoc ( item . data , metadata . id , item . rev )
338
+ doc = unstringifyDoc ( item . data as string , metadata . id , item . rev as string )
339
339
finish ( null )
340
+ } ) . catch ( e => {
341
+ // createError will throw in RN 0.76.3
342
+ // https://github.com/facebook/hermes/issues/1496
343
+ return finish ( e )
340
344
} )
341
345
}
342
346
@@ -481,11 +485,11 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
481
485
limit +
482
486
' OFFSET ' +
483
487
offset
484
- const result = await tx . executeAsync ( sql , sqlArgs )
488
+ const result = await tx . execute ( sql , sqlArgs )
485
489
finishedCount ++
486
490
if ( result . rows ) {
487
491
for ( let index = 0 ; index < result . rows . length ; index ++ ) {
488
- allRows . push ( result . rows ?. item ( index ) )
492
+ allRows . push ( result . rows [ index ] )
489
493
}
490
494
}
491
495
if ( finishedCount === keyChunks . length ) {
@@ -505,11 +509,11 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
505
509
limit +
506
510
' OFFSET ' +
507
511
offset
508
- const result = await tx . executeAsync ( sql , sqlArgs )
512
+ const result = await tx . execute ( sql , sqlArgs )
509
513
const rows : any [ ] = [ ]
510
514
if ( result . rows ) {
511
515
for ( let index = 0 ; index < result . rows . length ; index ++ ) {
512
- rows . push ( result . rows . item ( index ) )
516
+ rows . push ( result . rows [ index ] )
513
517
}
514
518
}
515
519
processResult ( rows , results , keys )
@@ -595,18 +599,18 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
595
599
let lastSeq = opts . since || 0
596
600
readTransaction ( async ( tx : Transaction ) => {
597
601
try {
598
- const result = await tx . executeAsync ( sql , sqlArgs )
602
+ const result = await tx . execute ( sql , sqlArgs )
599
603
600
604
if ( result . rows ) {
601
605
for ( let i = 0 , l = result . rows . length ; i < l ; i ++ ) {
602
- const item = result . rows . item ( i )
606
+ const item = result . rows [ i ] !
603
607
const metadata = safeJsonParse ( item . metadata )
604
608
lastSeq = item . maxSeq
605
609
606
610
const doc = unstringifyDoc (
607
- item . winningDoc ,
611
+ item . winningDoc as string ,
608
612
metadata . id ,
609
- item . winningRev
613
+ item . winningRev as string
610
614
)
611
615
const change = opts . processChange ( doc , metadata , opts )
612
616
change . seq = item . maxSeq
@@ -668,8 +672,8 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
668
672
const type = attachment . content_type
669
673
const sql =
670
674
'SELECT escaped, body AS body FROM ' + ATTACH_STORE + ' WHERE digest=?'
671
- tx . executeAsync ( sql , [ digest ] ) . then ( ( result ) => {
672
- const item = result . rows ?. item ( 0 )
675
+ tx . execute ( sql , [ digest ] ) . then ( ( result ) => {
676
+ const item = result . rows [ 0 ] !
673
677
const data = item . body
674
678
if ( opts . binary ) {
675
679
res = binStringToBlob ( data , type )
@@ -686,11 +690,11 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
686
690
) => {
687
691
readTransaction ( async ( tx : Transaction ) => {
688
692
const sql = 'SELECT json AS metadata FROM ' + DOC_STORE + ' WHERE id = ?'
689
- const result = await tx . executeAsync ( sql , [ docId ] )
693
+ const result = await tx . execute ( sql , [ docId ] )
690
694
if ( ! result . rows ?. length ) {
691
695
callback ( createError ( MISSING_DOC ) )
692
696
} else {
693
- const data = safeJsonParse ( result . rows ?. item ( 0 ) . metadata )
697
+ const data = safeJsonParse ( result . rows [ 0 ] ! . metadata )
694
698
callback ( null , data . rev_tree )
695
699
}
696
700
} )
@@ -707,8 +711,8 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
707
711
transaction ( async ( tx : Transaction ) => {
708
712
try {
709
713
let sql = 'SELECT json AS metadata FROM ' + DOC_STORE + ' WHERE id = ?'
710
- const result = await tx . executeAsync ( sql , [ docId ] )
711
- const metadata = safeJsonParse ( result . rows ?. item ( 0 ) . metadata )
714
+ const result = await tx . execute ( sql , [ docId ] )
715
+ const metadata = safeJsonParse ( result . rows [ 0 ] ! . metadata )
712
716
traverseRevTree (
713
717
metadata . rev_tree ,
714
718
(
@@ -725,7 +729,7 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
725
729
}
726
730
)
727
731
sql = 'UPDATE ' + DOC_STORE + ' SET json = ? WHERE id = ?'
728
- await tx . executeAsync ( sql , [ safeJsonStringify ( metadata ) , docId ] )
732
+ await tx . execute ( sql , [ safeJsonStringify ( metadata ) , docId ] )
729
733
730
734
compactRevs ( revs , docId , tx )
731
735
} catch ( e : any ) {
@@ -739,10 +743,10 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
739
743
readTransaction ( async ( tx : Transaction ) => {
740
744
try {
741
745
const sql = 'SELECT json, rev FROM ' + LOCAL_STORE + ' WHERE id=?'
742
- const res = await tx . executeAsync ( sql , [ id ] )
746
+ const res = await tx . execute ( sql , [ id ] )
743
747
if ( res . rows ?. length ) {
744
- const item = res . rows . item ( 0 )
745
- const doc = unstringifyDoc ( item . json , id , item . rev )
748
+ const item = res . rows [ 0 ] !
749
+ const doc = unstringifyDoc ( item . json as string , id , item . rev as string )
746
750
callback ( null , doc )
747
751
} else {
748
752
callback ( createError ( MISSING_DOC ) )
@@ -786,7 +790,7 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
786
790
sql = 'INSERT INTO ' + LOCAL_STORE + ' (id, rev, json) VALUES (?,?,?)'
787
791
values = [ id , newRev , json ]
788
792
}
789
- const res = await tx . executeAsync ( sql , values )
793
+ const res = await tx . execute ( sql , values )
790
794
if ( res . rowsAffected ) {
791
795
ret = { ok : true , id : id , rev : newRev }
792
796
callback ( null , ret )
@@ -820,7 +824,7 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
820
824
try {
821
825
const sql = 'DELETE FROM ' + LOCAL_STORE + ' WHERE id=? AND rev=?'
822
826
const params = [ doc . _id , doc . _rev ]
823
- const res = await tx . executeAsync ( sql , params )
827
+ const res = await tx . execute ( sql , params )
824
828
if ( ! res . rowsAffected ) {
825
829
return callback ( createError ( MISSING_DOC ) )
826
830
}
@@ -903,8 +907,8 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
903
907
904
908
async function getMaxSeq ( tx : Transaction ) : Promise < number > {
905
909
const sql = 'SELECT MAX(seq) AS seq FROM ' + BY_SEQ_STORE
906
- const res = await tx . executeAsync ( sql , [ ] )
907
- const updateSeq = res . rows ?. item ( 0 ) . seq || 0
910
+ const res = await tx . execute ( sql , [ ] )
911
+ const updateSeq = res . rows [ 0 ] ! . seq as number || 0
908
912
return updateSeq
909
913
}
910
914
@@ -915,8 +919,8 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
915
919
DOC_STORE_AND_BY_SEQ_JOINER ,
916
920
BY_SEQ_STORE + '.deleted=0'
917
921
)
918
- const result = await tx . executeAsync ( sql , [ ] )
919
- return result . rows ?. item ( 0 ) . num || 0
922
+ const result = await tx . execute ( sql , [ ] )
923
+ return result . rows [ 0 ] ! . num as number || 0
920
924
}
921
925
922
926
async function latest (
@@ -934,12 +938,12 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
934
938
)
935
939
const sqlArgs = [ id ]
936
940
937
- const results = await tx . executeAsync ( sql , sqlArgs )
941
+ const results = await tx . execute ( sql , sqlArgs )
938
942
if ( ! results . rows ?. length ) {
939
943
const err = createError ( MISSING_DOC , 'missing' )
940
944
return finish ( err )
941
945
}
942
- const item = results . rows . item ( 0 )
946
+ const item = results . rows [ 0 ] !
943
947
const metadata = safeJsonParse ( item . metadata )
944
948
callback ( getLatest ( rev , metadata ) )
945
949
}
0 commit comments