@@ -123,23 +123,23 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
123123 callback ( null )
124124 }
125125
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
129129 encoding = hex . length === 2 ? 'UTF-8' : 'UTF-16'
130130 }
131131
132- function fetchVersion ( tx : Transaction ) {
132+ async function fetchVersion ( tx : Transaction ) {
133133 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 , [ ] )
135135 if ( ! result . rows ?. length ) {
136136 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 ) ) {
138138 tx . execute ( 'ALTER TABLE ' + META_STORE + ' ADD COLUMN db_version INTEGER' )
139139 onGetVersion ( tx , 1 )
140140 } 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
143143 onGetVersion ( tx , dbVersion )
144144 }
145145 }
@@ -152,7 +152,7 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
152152 }
153153 }
154154
155- function createInitialSchema ( tx : Transaction ) {
155+ async function createInitialSchema ( tx : Transaction ) {
156156 const meta =
157157 'CREATE TABLE IF NOT EXISTS ' + META_STORE + ' (dbid, db_version INTEGER)'
158158 const attach =
@@ -174,22 +174,22 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
174174 const local =
175175 'CREATE TABLE IF NOT EXISTS ' + LOCAL_STORE + ' (id UNIQUE, rev, json)'
176176
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 )
188188 const initSeq =
189189 'INSERT INTO ' + META_STORE + ' (db_version, dbid) VALUES (?,?)'
190190 instanceId = uuid ( )
191191 const initSeqArgs = [ ADAPTER_VERSION , instanceId ]
192- tx . execute ( initSeq , initSeqArgs )
192+ await tx . execute ( initSeq , initSeqArgs )
193193 onGetInstanceId ( )
194194 }
195195
@@ -205,12 +205,12 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
205205
206206 const migrated = dbVersion < ADAPTER_VERSION
207207 if ( migrated ) {
208- db . execute (
208+ await db . execute (
209209 'UPDATE ' + META_STORE + ' SET db_version = ' + ADAPTER_VERSION
210210 )
211211 }
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
214214 onGetInstanceId ( )
215215 }
216216
@@ -324,19 +324,23 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
324324 sqlArgs = [ id , opts . rev ]
325325 }
326326
327- tx . executeAsync ( sql , sqlArgs ) . then ( ( results ) => {
327+ tx . execute ( sql , sqlArgs ) . then ( ( results ) => {
328328 if ( ! results . rows ?. length ) {
329329 const missingErr = createError ( MISSING_DOC , 'missing' )
330330 return finish ( missingErr )
331331 }
332- const item = results . rows . item ( 0 )
332+ const item = results . rows [ 0 ] !
333333 metadata = safeJsonParse ( item . metadata )
334334 if ( item . deleted && ! opts . rev ) {
335335 const deletedErr = createError ( MISSING_DOC , 'deleted' )
336336 return finish ( deletedErr )
337337 }
338- doc = unstringifyDoc ( item . data , metadata . id , item . rev )
338+ doc = unstringifyDoc ( item . data as string , metadata . id , item . rev as string )
339339 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 )
340344 } )
341345 }
342346
@@ -481,11 +485,11 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
481485 limit +
482486 ' OFFSET ' +
483487 offset
484- const result = await tx . executeAsync ( sql , sqlArgs )
488+ const result = await tx . execute ( sql , sqlArgs )
485489 finishedCount ++
486490 if ( result . rows ) {
487491 for ( let index = 0 ; index < result . rows . length ; index ++ ) {
488- allRows . push ( result . rows ?. item ( index ) )
492+ allRows . push ( result . rows [ index ] )
489493 }
490494 }
491495 if ( finishedCount === keyChunks . length ) {
@@ -505,11 +509,11 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
505509 limit +
506510 ' OFFSET ' +
507511 offset
508- const result = await tx . executeAsync ( sql , sqlArgs )
512+ const result = await tx . execute ( sql , sqlArgs )
509513 const rows : any [ ] = [ ]
510514 if ( result . rows ) {
511515 for ( let index = 0 ; index < result . rows . length ; index ++ ) {
512- rows . push ( result . rows . item ( index ) )
516+ rows . push ( result . rows [ index ] )
513517 }
514518 }
515519 processResult ( rows , results , keys )
@@ -595,18 +599,18 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
595599 let lastSeq = opts . since || 0
596600 readTransaction ( async ( tx : Transaction ) => {
597601 try {
598- const result = await tx . executeAsync ( sql , sqlArgs )
602+ const result = await tx . execute ( sql , sqlArgs )
599603
600604 if ( result . rows ) {
601605 for ( let i = 0 , l = result . rows . length ; i < l ; i ++ ) {
602- const item = result . rows . item ( i )
606+ const item = result . rows [ i ] !
603607 const metadata = safeJsonParse ( item . metadata )
604608 lastSeq = item . maxSeq
605609
606610 const doc = unstringifyDoc (
607- item . winningDoc ,
611+ item . winningDoc as string ,
608612 metadata . id ,
609- item . winningRev
613+ item . winningRev as string
610614 )
611615 const change = opts . processChange ( doc , metadata , opts )
612616 change . seq = item . maxSeq
@@ -668,8 +672,8 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
668672 const type = attachment . content_type
669673 const sql =
670674 '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 ] !
673677 const data = item . body
674678 if ( opts . binary ) {
675679 res = binStringToBlob ( data , type )
@@ -686,11 +690,11 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
686690 ) => {
687691 readTransaction ( async ( tx : Transaction ) => {
688692 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 ] )
690694 if ( ! result . rows ?. length ) {
691695 callback ( createError ( MISSING_DOC ) )
692696 } else {
693- const data = safeJsonParse ( result . rows ?. item ( 0 ) . metadata )
697+ const data = safeJsonParse ( result . rows [ 0 ] ! . metadata )
694698 callback ( null , data . rev_tree )
695699 }
696700 } )
@@ -707,8 +711,8 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
707711 transaction ( async ( tx : Transaction ) => {
708712 try {
709713 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 )
712716 traverseRevTree (
713717 metadata . rev_tree ,
714718 (
@@ -725,7 +729,7 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
725729 }
726730 )
727731 sql = 'UPDATE ' + DOC_STORE + ' SET json = ? WHERE id = ?'
728- await tx . executeAsync ( sql , [ safeJsonStringify ( metadata ) , docId ] )
732+ await tx . execute ( sql , [ safeJsonStringify ( metadata ) , docId ] )
729733
730734 compactRevs ( revs , docId , tx )
731735 } catch ( e : any ) {
@@ -739,10 +743,10 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
739743 readTransaction ( async ( tx : Transaction ) => {
740744 try {
741745 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 ] )
743747 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 )
746750 callback ( null , doc )
747751 } else {
748752 callback ( createError ( MISSING_DOC ) )
@@ -786,7 +790,7 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
786790 sql = 'INSERT INTO ' + LOCAL_STORE + ' (id, rev, json) VALUES (?,?,?)'
787791 values = [ id , newRev , json ]
788792 }
789- const res = await tx . executeAsync ( sql , values )
793+ const res = await tx . execute ( sql , values )
790794 if ( res . rowsAffected ) {
791795 ret = { ok : true , id : id , rev : newRev }
792796 callback ( null , ret )
@@ -820,7 +824,7 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
820824 try {
821825 const sql = 'DELETE FROM ' + LOCAL_STORE + ' WHERE id=? AND rev=?'
822826 const params = [ doc . _id , doc . _rev ]
823- const res = await tx . executeAsync ( sql , params )
827+ const res = await tx . execute ( sql , params )
824828 if ( ! res . rowsAffected ) {
825829 return callback ( createError ( MISSING_DOC ) )
826830 }
@@ -903,8 +907,8 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
903907
904908 async function getMaxSeq ( tx : Transaction ) : Promise < number > {
905909 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
908912 return updateSeq
909913 }
910914
@@ -915,8 +919,8 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
915919 DOC_STORE_AND_BY_SEQ_JOINER ,
916920 BY_SEQ_STORE + '.deleted=0'
917921 )
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
920924 }
921925
922926 async function latest (
@@ -934,12 +938,12 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
934938 )
935939 const sqlArgs = [ id ]
936940
937- const results = await tx . executeAsync ( sql , sqlArgs )
941+ const results = await tx . execute ( sql , sqlArgs )
938942 if ( ! results . rows ?. length ) {
939943 const err = createError ( MISSING_DOC , 'missing' )
940944 return finish ( err )
941945 }
942- const item = results . rows . item ( 0 )
946+ const item = results . rows [ 0 ] !
943947 const metadata = safeJsonParse ( item . metadata )
944948 callback ( getLatest ( rev , metadata ) )
945949 }
0 commit comments