@@ -140,13 +140,15 @@ export abstract class SqlProviderBase extends NoSqlProvider.DbProvider {
140140 // Get Index metadatas
141141 let indexMetadata : IndexMetadata [ ] =
142142 _ . map ( fullMeta , meta => {
143- let metaObj : IndexMetadata | undefined ;
144- _ . attempt ( ( ) => {
145- metaObj = JSON . parse ( meta . value ) ;
143+ const metaObj = _ . attempt ( ( ) => {
144+ return JSON . parse ( meta . value ) ;
146145 } ) ;
146+ if ( _ . isError ( metaObj ) ) {
147+ return undefined ;
148+ }
147149 return metaObj ;
148150 } )
149- . filter ( meta => ! ! meta && ! ! meta . storeName ) as IndexMetadata [ ] ;
151+ . filter ( meta => ! ! meta && ! ! meta . storeName ) ;
150152
151153 return trans . runQuery ( 'SELECT type, name, tbl_name, sql from sqlite_master' , [ ] )
152154 . then ( rows => {
@@ -747,12 +749,11 @@ class SqlStore implements NoSqlProvider.DbStore {
747749 }
748750
749751 get ( key : KeyType ) : SyncTasks . Promise < ItemType | undefined > {
750- let joinedKey : string ;
751- const err = _ . attempt ( ( ) => {
752- joinedKey = NoSqlProviderUtils . serializeKeyToString ( key , this . _schema . primaryKeyPath ) ;
752+ const joinedKey = _ . attempt ( ( ) => {
753+ return NoSqlProviderUtils . serializeKeyToString ( key , this . _schema . primaryKeyPath ) ;
753754 } ) ;
754- if ( err ) {
755- return SyncTasks . Rejected ( err ) ;
755+ if ( _ . isError ( joinedKey ) ) {
756+ return SyncTasks . Rejected ( joinedKey ) ;
756757 }
757758
758759 let startTime : number ;
@@ -761,7 +762,7 @@ class SqlStore implements NoSqlProvider.DbStore {
761762 }
762763
763764 let promise = this . _trans . internal_getResultFromQuery ( 'SELECT nsp_data FROM ' + this . _schema . name +
764- ' WHERE nsp_pk = ?' , [ joinedKey ! ! ! ] ) ;
765+ ' WHERE nsp_pk = ?' , [ joinedKey ] ) ;
765766 if ( this . _verbose ) {
766767 promise = promise . finally ( ( ) => {
767768 console . log ( 'SqlStore (' + this . _schema . name + ') get: (' + ( Date . now ( ) - startTime ) + 'ms)' ) ;
@@ -771,15 +772,14 @@ class SqlStore implements NoSqlProvider.DbStore {
771772 }
772773
773774 getMultiple ( keyOrKeys : KeyType | KeyType [ ] ) : SyncTasks . Promise < ItemType [ ] > {
774- let joinedKeys : string [ ] ;
775- const err = _ . attempt ( ( ) => {
776- joinedKeys = NoSqlProviderUtils . formListOfSerializedKeys ( keyOrKeys , this . _schema . primaryKeyPath ) ;
775+ const joinedKeys = _ . attempt ( ( ) => {
776+ return NoSqlProviderUtils . formListOfSerializedKeys ( keyOrKeys , this . _schema . primaryKeyPath ) ;
777777 } ) ;
778- if ( err ) {
779- return SyncTasks . Rejected ( err ) ;
778+ if ( _ . isError ( joinedKeys ) ) {
779+ return SyncTasks . Rejected ( joinedKeys ) ;
780780 }
781781
782- if ( joinedKeys ! ! ! . length === 0 ) {
782+ if ( joinedKeys . length === 0 ) {
783783 return SyncTasks . Resolved ( [ ] ) ;
784784 }
785785
@@ -871,12 +871,11 @@ class SqlStore implements NoSqlProvider.DbStore {
871871 // Also prepare mulltiEntry and FullText indexes
872872 if ( _ . some ( this . _schema . indexes , index => indexUsesSeparateTable ( index , this . _supportsFTS3 ) ) ) {
873873 _ . each ( items , ( item , itemIndex ) => {
874- let key : string ;
875- const err = _ . attempt ( ( ) => {
876- key = NoSqlProviderUtils . getSerializedKeyForKeypath ( item , this . _schema . primaryKeyPath ) ! ! ! ;
874+ const key = _ . attempt ( ( ) => {
875+ return NoSqlProviderUtils . getSerializedKeyForKeypath ( item , this . _schema . primaryKeyPath ) ! ! ! ;
877876 } ) ;
878- if ( err ) {
879- queries . push ( SyncTasks . Rejected < void > ( err ) ) ;
877+ if ( _ . isError ( key ) ) {
878+ queries . push ( SyncTasks . Rejected < void > ( key ) ) ;
880879 return ;
881880 }
882881
@@ -936,12 +935,11 @@ class SqlStore implements NoSqlProvider.DbStore {
936935 }
937936
938937 remove ( keyOrKeys : KeyType | KeyType [ ] ) : SyncTasks . Promise < void > {
939- let joinedKeys : string [ ] = [ ] ;
940- const err = _ . attempt ( ( ) => {
941- joinedKeys = NoSqlProviderUtils . formListOfSerializedKeys ( keyOrKeys , this . _schema . primaryKeyPath ) ;
938+ const joinedKeys = _ . attempt ( ( ) => {
939+ return NoSqlProviderUtils . formListOfSerializedKeys ( keyOrKeys , this . _schema . primaryKeyPath ) ;
942940 } ) ;
943- if ( err ) {
944- return SyncTasks . Rejected < void > ( err ) ;
941+ if ( _ . isError ( joinedKeys ) ) {
942+ return SyncTasks . Rejected < void > ( joinedKeys ) ;
945943 }
946944
947945 let startTime : number ;
@@ -1114,12 +1112,11 @@ class SqlStoreIndex implements NoSqlProvider.DbIndex {
11141112 }
11151113
11161114 getOnly ( key : KeyType , reverse ?: boolean , limit ?: number , offset ?: number ) : SyncTasks . Promise < ItemType [ ] > {
1117- let joinedKey : string ;
1118- const err = _ . attempt ( ( ) => {
1119- joinedKey = NoSqlProviderUtils . serializeKeyToString ( key , this . _keyPath ) ;
1115+ const joinedKey = _ . attempt ( ( ) => {
1116+ return NoSqlProviderUtils . serializeKeyToString ( key , this . _keyPath ) ;
11201117 } ) ;
1121- if ( err ) {
1122- return SyncTasks . Rejected ( err ) ;
1118+ if ( _ . isError ( joinedKey ) ) {
1119+ return SyncTasks . Rejected ( joinedKey ) ;
11231120 }
11241121
11251122 let startTime : number ;
@@ -1128,7 +1125,7 @@ class SqlStoreIndex implements NoSqlProvider.DbIndex {
11281125 }
11291126
11301127 let promise = this . _handleQuery ( 'SELECT nsp_data FROM ' + this . _tableName + ' WHERE ' + this . _queryColumn + ' = ?' ,
1131- [ joinedKey ! ! ! ] ,
1128+ [ joinedKey ] ,
11321129 reverse , limit , offset ) ;
11331130 if ( this . _verbose ) {
11341131 promise = promise . finally ( ( ) => {
@@ -1201,12 +1198,11 @@ class SqlStoreIndex implements NoSqlProvider.DbIndex {
12011198 }
12021199
12031200 countOnly ( key : KeyType ) : SyncTasks . Promise < number > {
1204- let joinedKey : string ;
1205- const err = _ . attempt ( ( ) => {
1206- joinedKey = NoSqlProviderUtils . serializeKeyToString ( key , this . _keyPath ) ;
1201+ const joinedKey = _ . attempt ( ( ) => {
1202+ return NoSqlProviderUtils . serializeKeyToString ( key , this . _keyPath ) ;
12071203 } ) ;
1208- if ( err ) {
1209- return SyncTasks . Rejected ( err ) ;
1204+ if ( _ . isError ( joinedKey ) ) {
1205+ return SyncTasks . Rejected ( joinedKey ) ;
12101206 }
12111207
12121208 let startTime : number ;
@@ -1215,7 +1211,7 @@ class SqlStoreIndex implements NoSqlProvider.DbIndex {
12151211 }
12161212
12171213 let promise = this . _trans . runQuery ( 'SELECT COUNT(*) cnt FROM ' + this . _tableName + ' WHERE ' + this . _queryColumn
1218- + ' = ?' , [ joinedKey ! ! ! ] ) . then ( result => result [ 0 ] [ 'cnt' ] ) ;
1214+ + ' = ?' , [ joinedKey ] ) . then ( result => result [ 0 ] [ 'cnt' ] ) ;
12191215 if ( this . _verbose ) {
12201216 promise = promise . finally ( ( ) => {
12211217 console . log ( 'SqlStoreIndex (' + this . _rawTableName + '/' + this . _indexTableName + ') countOnly: (' +
0 commit comments