@@ -589,7 +589,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
589
589
590
590
handleShutdown ( ) {
591
591
if ( ! this . _client ) {
592
- return
592
+ return ;
593
593
}
594
594
this . _client . $pool . end ( ) ;
595
595
}
@@ -818,9 +818,10 @@ export class PostgresStorageAdapter implements StorageAdapter {
818
818
}
819
819
// No _SCHEMA collection. Don't delete anything.
820
820
}
821
- } ) . then ( ( ) => {
822
- debug ( `deleteAllClasses done in ${ new Date ( ) . getTime ( ) - now } ` ) ;
823
- } ) ;
821
+ } )
822
+ . then ( ( ) => {
823
+ debug ( `deleteAllClasses done in ${ new Date ( ) . getTime ( ) - now } ` ) ;
824
+ } ) ;
824
825
}
825
826
826
827
// Remove the column and all the data. For Relations, the _Join collection is handled
@@ -878,12 +879,12 @@ export class PostgresStorageAdapter implements StorageAdapter {
878
879
debug ( 'getClass' , className ) ;
879
880
return this . _client . any ( 'SELECT * FROM "_SCHEMA" WHERE "className"=$<className>' , { className } )
880
881
. then ( result => {
881
- if ( result . length === 1 ) {
882
- return result [ 0 ] . schema ;
883
- } else {
884
- throw undefined ;
882
+ if ( result . length !== 1 ) {
883
+ throw undefined ;
885
884
}
886
- } ) . then ( toParseSchema ) ;
885
+ return result [ 0 ] . schema ;
886
+ } )
887
+ . then ( toParseSchema ) ;
887
888
}
888
889
889
890
// TODO: remove the mongo format dependency in the return value
@@ -1018,11 +1019,10 @@ export class PostgresStorageAdapter implements StorageAdapter {
1018
1019
err . userInfo = { duplicated_field : matches [ 1 ] } ;
1019
1020
}
1020
1021
}
1021
- throw err ;
1022
- } else {
1023
- throw error ;
1022
+ error = err ;
1024
1023
}
1025
- } )
1024
+ throw error ;
1025
+ } ) ;
1026
1026
}
1027
1027
1028
1028
// Remove all objects that match the given Parse Query.
@@ -1046,18 +1046,19 @@ export class PostgresStorageAdapter implements StorageAdapter {
1046
1046
} else {
1047
1047
return count ;
1048
1048
}
1049
- } ) . catch ( ( error ) => {
1050
- if ( error . code === PostgresRelationDoesNotExistError ) {
1051
- // Don't delete anything if doesn't exist
1052
- } else {
1049
+ } )
1050
+ . catch ( error => {
1051
+ if ( error . code !== PostgresRelationDoesNotExistError ) {
1053
1052
throw error ;
1054
1053
}
1054
+ // ELSE: Don't delete anything if doesn't exist
1055
1055
} ) ;
1056
1056
}
1057
1057
// Return value not currently well specified.
1058
1058
findOneAndUpdate ( className : string , schema : SchemaType , query : QueryType , update : any ) : Promise < any > {
1059
1059
debug ( 'findOneAndUpdate' , className , query , update ) ;
1060
- return this . updateObjectsByQuery ( className , schema , query , update ) . then ( ( val ) => val [ 0 ] ) ;
1060
+ return this . updateObjectsByQuery ( className , schema , query , update )
1061
+ . then ( ( val ) => val [ 0 ] ) ;
1061
1062
}
1062
1063
1063
1064
// Apply the update to all objects that match the given Parse Query.
@@ -1248,12 +1249,13 @@ export class PostgresStorageAdapter implements StorageAdapter {
1248
1249
upsertOneObject ( className : string , schema : SchemaType , query : QueryType , update : any ) {
1249
1250
debug ( 'upsertOneObject' , { className, query, update} ) ;
1250
1251
const createValue = Object . assign ( { } , query , update ) ;
1251
- return this . createObject ( className , schema , createValue ) . catch ( ( err ) => {
1252
+ return this . createObject ( className , schema , createValue )
1253
+ . catch ( error => {
1252
1254
// ignore duplicate value errors as it's upsert
1253
- if ( err . code = == Parse . Error . DUPLICATE_VALUE ) {
1254
- return this . findOneAndUpdate ( className , schema , query , update ) ;
1255
+ if ( error . code ! == Parse . Error . DUPLICATE_VALUE ) {
1256
+ throw error ;
1255
1257
}
1256
- throw err ;
1258
+ return this . findOneAndUpdate ( className , schema , query , update ) ;
1257
1259
} ) ;
1258
1260
}
1259
1261
@@ -1309,12 +1311,12 @@ export class PostgresStorageAdapter implements StorageAdapter {
1309
1311
const qs = `SELECT ${ columns } FROM $1:name ${ wherePattern } ${ sortPattern } ${ limitPattern } ${ skipPattern } ` ;
1310
1312
debug ( qs , values ) ;
1311
1313
return this . _client . any ( qs , values )
1312
- . catch ( ( err ) => {
1313
- // Query on non existing table, don't crash
1314
- if ( err . code = == PostgresRelationDoesNotExistError ) {
1315
- return [ ] ;
1314
+ . catch ( error => {
1315
+ // Query on non existing table, don't crash
1316
+ if ( error . code ! == PostgresRelationDoesNotExistError ) {
1317
+ throw error ;
1316
1318
}
1317
- throw err ;
1319
+ return [ ] ;
1318
1320
} )
1319
1321
. then ( results => results . map ( object => this . postgresObjectToParseObject ( className , object , schema ) ) ) ;
1320
1322
}
@@ -1428,11 +1430,12 @@ export class PostgresStorageAdapter implements StorageAdapter {
1428
1430
1429
1431
const wherePattern = where . pattern . length > 0 ? `WHERE ${ where . pattern } ` : '' ;
1430
1432
const qs = `SELECT count(*) FROM $1:name ${ wherePattern } ` ;
1431
- return this . _client . one ( qs , values , a => + a . count ) . catch ( ( err ) => {
1432
- if ( err . code === PostgresRelationDoesNotExistError ) {
1433
+ return this . _client . one ( qs , values , a => + a . count )
1434
+ . catch ( error => {
1435
+ if ( error . code !== PostgresRelationDoesNotExistError ) {
1436
+ throw error ;
1437
+ }
1433
1438
return 0 ;
1434
- }
1435
- throw err ;
1436
1439
} ) ;
1437
1440
}
1438
1441
@@ -1481,7 +1484,8 @@ export class PostgresStorageAdapter implements StorageAdapter {
1481
1484
}
1482
1485
const child = fieldName . split ( '.' ) [ 1 ] ;
1483
1486
return results . map ( object => object [ column ] [ child ] ) ;
1484
- } ) . then ( results => results . map ( object => this . postgresObjectToParseObject ( className , object , schema ) ) ) ;
1487
+ } )
1488
+ . then ( results => results . map ( object => this . postgresObjectToParseObject ( className , object , schema ) ) ) ;
1485
1489
}
1486
1490
1487
1491
aggregate ( className : string , schema : any , pipeline : any ) {
0 commit comments