@@ -829,9 +829,9 @@ export class PostgresStorageAdapter implements StorageAdapter {
829
829
this . _client . $pool . end ( ) ;
830
830
}
831
831
832
- _ensureSchemaCollectionExists ( conn : any ) {
832
+ async _ensureSchemaCollectionExists ( conn : any ) {
833
833
conn = conn || this . _client ;
834
- return conn
834
+ await conn
835
835
. none (
836
836
'CREATE TABLE IF NOT EXISTS "_SCHEMA" ( "className" varChar(120), "schema" jsonb, "isParseClass" bool, PRIMARY KEY ("className") )'
837
837
)
@@ -848,17 +848,17 @@ export class PostgresStorageAdapter implements StorageAdapter {
848
848
} ) ;
849
849
}
850
850
851
- classExists ( name : string ) {
851
+ async classExists ( name : string ) {
852
852
return this . _client . one (
853
853
'SELECT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = $1)' ,
854
854
[ name ] ,
855
855
a => a . exists
856
856
) ;
857
857
}
858
858
859
- setClassLevelPermissions ( className : string , CLPs : any ) {
859
+ async setClassLevelPermissions ( className : string , CLPs : any ) {
860
860
const self = this ;
861
- return this . _client . task ( 'set-class-level-permissions' , async t => {
861
+ await this . _client . task ( 'set-class-level-permissions' , async t => {
862
862
await self . _ensureSchemaCollectionExists ( t ) ;
863
863
const values = [
864
864
className ,
@@ -867,13 +867,13 @@ export class PostgresStorageAdapter implements StorageAdapter {
867
867
JSON . stringify ( CLPs ) ,
868
868
] ;
869
869
await t . none (
870
- `UPDATE "_SCHEMA" SET $2:name = json_object_set_key($2:name, $3::text, $4::jsonb) WHERE "className"= $1` ,
870
+ `UPDATE "_SCHEMA" SET $2:name = json_object_set_key($2:name, $3::text, $4::jsonb) WHERE "className" = $1` ,
871
871
values
872
872
) ;
873
873
} ) ;
874
874
}
875
875
876
- setIndexesWithSchemaFormat (
876
+ async setIndexesWithSchemaFormat (
877
877
className : string ,
878
878
submittedIndexes : any ,
879
879
existingIndexes : any = { } ,
@@ -923,7 +923,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
923
923
} ) ;
924
924
}
925
925
} ) ;
926
- return conn . tx ( 'set-indexes-with-schema-format' , async t => {
926
+ await conn . tx ( 'set-indexes-with-schema-format' , async t => {
927
927
if ( insertedIndexes . length > 0 ) {
928
928
await self . createIndexes ( className , insertedIndexes , t ) ;
929
929
}
@@ -932,16 +932,16 @@ export class PostgresStorageAdapter implements StorageAdapter {
932
932
}
933
933
await self . _ensureSchemaCollectionExists ( t ) ;
934
934
await t . none (
935
- 'UPDATE "_SCHEMA" SET $2:name = json_object_set_key($2:name, $3::text, $4::jsonb) WHERE "className"= $1' ,
935
+ 'UPDATE "_SCHEMA" SET $2:name = json_object_set_key($2:name, $3::text, $4::jsonb) WHERE "className" = $1' ,
936
936
[ className , 'schema' , 'indexes' , JSON . stringify ( existingIndexes ) ]
937
937
) ;
938
938
} ) ;
939
939
}
940
940
941
- createClass ( className : string , schema : SchemaType , conn : ?any ) {
941
+ async createClass ( className : string , schema : SchemaType , conn : ?any ) {
942
942
conn = conn || this . _client ;
943
943
return conn
944
- . tx ( 'create-class' , t => {
944
+ . tx ( 'create-class' , async t => {
945
945
const q1 = this . createTable ( className , schema , t ) ;
946
946
const q2 = t . none (
947
947
'INSERT INTO "_SCHEMA" ("className", "schema", "isParseClass") VALUES ($<className>, $<schema>, true)' ,
@@ -954,6 +954,8 @@ export class PostgresStorageAdapter implements StorageAdapter {
954
954
schema . fields ,
955
955
t
956
956
) ;
957
+ // TODO: The test should not verify the returned value, and then
958
+ // the method can be simplified, to avoid returning useless stuff.
957
959
return t . batch ( [ q1 , q2 , q3 ] ) ;
958
960
} )
959
961
. then ( ( ) => {
@@ -977,7 +979,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
977
979
}
978
980
979
981
// Just create a table, do not insert in schema
980
- createTable ( className : string , schema : SchemaType , conn : any ) {
982
+ async createTable ( className : string , schema : SchemaType , conn : any ) {
981
983
conn = conn || this . _client ;
982
984
const self = this ;
983
985
debug ( 'createTable' , className , schema ) ;
@@ -1042,12 +1044,12 @@ export class PostgresStorageAdapter implements StorageAdapter {
1042
1044
} ) ;
1043
1045
}
1044
1046
1045
- schemaUpgrade ( className : string , schema : SchemaType , conn : any ) {
1047
+ async schemaUpgrade ( className : string , schema : SchemaType , conn : any ) {
1046
1048
debug ( 'schemaUpgrade' , { className, schema } ) ;
1047
1049
conn = conn || this . _client ;
1048
1050
const self = this ;
1049
1051
1050
- return conn . tx ( 'schema-upgrade' , async t => {
1052
+ await conn . tx ( 'schema-upgrade' , async t => {
1051
1053
const columns = await t . map (
1052
1054
'SELECT column_name FROM information_schema.columns WHERE table_name = $<className>' ,
1053
1055
{ className } ,
@@ -1068,7 +1070,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
1068
1070
} ) ;
1069
1071
}
1070
1072
1071
- addFieldIfNotExists (
1073
+ async addFieldIfNotExists (
1072
1074
className : string ,
1073
1075
fieldName : string ,
1074
1076
type : any ,
@@ -1078,7 +1080,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
1078
1080
debug ( 'addFieldIfNotExists' , { className, fieldName, type } ) ;
1079
1081
conn = conn || this . _client ;
1080
1082
const self = this ;
1081
- return conn . tx ( 'add-field-if-not-exists' , async t => {
1083
+ await conn . tx ( 'add-field-if-not-exists' , async t => {
1082
1084
if ( type . type !== 'Relation' ) {
1083
1085
try {
1084
1086
await t . none (
@@ -1091,7 +1093,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
1091
1093
) ;
1092
1094
} catch ( error ) {
1093
1095
if ( error . code === PostgresRelationDoesNotExistError ) {
1094
- return await self . createClass (
1096
+ return self . createClass (
1095
1097
className ,
1096
1098
{ fields : { [ fieldName ] : type } } ,
1097
1099
t
@@ -1128,7 +1130,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
1128
1130
1129
1131
// Drops a collection. Resolves with true if it was a Parse Schema (eg. _User, Custom, etc.)
1130
1132
// and resolves with false if it wasn't (eg. a join table). Rejects if deletion was impossible.
1131
- deleteClass ( className : string ) {
1133
+ async deleteClass ( className : string ) {
1132
1134
const operations = [
1133
1135
{ query : `DROP TABLE IF EXISTS $1:name` , values : [ className ] } ,
1134
1136
{
@@ -1142,12 +1144,12 @@ export class PostgresStorageAdapter implements StorageAdapter {
1142
1144
}
1143
1145
1144
1146
// Delete all data known to this adapter. Used for testing.
1145
- deleteAllClasses ( ) {
1147
+ async deleteAllClasses ( ) {
1146
1148
const now = new Date ( ) . getTime ( ) ;
1147
1149
const helpers = this . _pgp . helpers ;
1148
1150
debug ( 'deleteAllClasses' ) ;
1149
1151
1150
- return this . _client
1152
+ await this . _client
1151
1153
. task ( 'delete-all-classes' , async t => {
1152
1154
try {
1153
1155
const results = await t . any ( 'SELECT * FROM "_SCHEMA"' ) ;
@@ -1196,7 +1198,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
1196
1198
// may do so.
1197
1199
1198
1200
// Returns a Promise.
1199
- deleteFields (
1201
+ async deleteFields (
1200
1202
className : string ,
1201
1203
schema : SchemaType ,
1202
1204
fieldNames : string [ ]
@@ -1218,9 +1220,9 @@ export class PostgresStorageAdapter implements StorageAdapter {
1218
1220
} )
1219
1221
. join ( ', DROP COLUMN' ) ;
1220
1222
1221
- return this . _client . tx ( 'delete-fields' , async t => {
1223
+ await this . _client . tx ( 'delete-fields' , async t => {
1222
1224
await t . none (
1223
- 'UPDATE "_SCHEMA" SET "schema"= $<schema> WHERE "className"= $<className>' ,
1225
+ 'UPDATE "_SCHEMA" SET "schema" = $<schema> WHERE "className" = $<className>' ,
1224
1226
{ schema, className }
1225
1227
) ;
1226
1228
if ( values . length > 1 ) {
@@ -1232,7 +1234,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
1232
1234
// Return a promise for all schemas known to this adapter, in Parse format. In case the
1233
1235
// schemas cannot be retrieved, returns a promise that rejects. Requirements for the
1234
1236
// rejection reason are TBD.
1235
- getAllClasses ( ) {
1237
+ async getAllClasses ( ) {
1236
1238
const self = this ;
1237
1239
return this . _client . task ( 'get-all-classes' , async t => {
1238
1240
await self . _ensureSchemaCollectionExists ( t ) ;
@@ -1245,10 +1247,10 @@ export class PostgresStorageAdapter implements StorageAdapter {
1245
1247
// Return a promise for the schema with the given name, in Parse format. If
1246
1248
// this adapter doesn't know about the schema, return a promise that rejects with
1247
1249
// undefined as the reason.
1248
- getClass ( className : string ) {
1250
+ async getClass ( className : string ) {
1249
1251
debug ( 'getClass' , className ) ;
1250
1252
return this . _client
1251
- . any ( 'SELECT * FROM "_SCHEMA" WHERE "className"= $<className>' , {
1253
+ . any ( 'SELECT * FROM "_SCHEMA" WHERE "className" = $<className>' , {
1252
1254
className,
1253
1255
} )
1254
1256
. then ( result => {
@@ -1261,7 +1263,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
1261
1263
}
1262
1264
1263
1265
// TODO: remove the mongo format dependency in the return value
1264
- createObject (
1266
+ async createObject (
1265
1267
className : string ,
1266
1268
schema : SchemaType ,
1267
1269
object : any ,
@@ -1426,7 +1428,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
1426
1428
// Remove all objects that match the given Parse Query.
1427
1429
// If no objects match, reject with OBJECT_NOT_FOUND. If objects are found and deleted, resolve with undefined.
1428
1430
// If there is some other error, reject with INTERNAL_SERVER_ERROR.
1429
- deleteObjectsByQuery (
1431
+ async deleteObjectsByQuery (
1430
1432
className : string ,
1431
1433
schema : SchemaType ,
1432
1434
query : QueryType ,
@@ -1469,7 +1471,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
1469
1471
return promise ;
1470
1472
}
1471
1473
// Return value not currently well specified.
1472
- findOneAndUpdate (
1474
+ async findOneAndUpdate (
1473
1475
className : string ,
1474
1476
schema : SchemaType ,
1475
1477
query : QueryType ,
@@ -1487,7 +1489,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
1487
1489
}
1488
1490
1489
1491
// Apply the update to all objects that match the given Parse Query.
1490
- updateObjectsByQuery (
1492
+ async updateObjectsByQuery (
1491
1493
className : string ,
1492
1494
schema : SchemaType ,
1493
1495
query : QueryType ,
@@ -1980,7 +1982,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
1980
1982
// As such, we shouldn't expose this function to users of parse until we have an out-of-band
1981
1983
// Way of determining if a field is nullable. Undefined doesn't count against uniqueness,
1982
1984
// which is why we use sparse indexes.
1983
- ensureUniqueness (
1985
+ async ensureUniqueness (
1984
1986
className : string ,
1985
1987
schema : SchemaType ,
1986
1988
fieldNames : string [ ]
@@ -2016,7 +2018,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
2016
2018
}
2017
2019
2018
2020
// Executes a count.
2019
- count (
2021
+ async count (
2020
2022
className : string ,
2021
2023
schema : SchemaType ,
2022
2024
query : QueryType ,
@@ -2055,7 +2057,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
2055
2057
} ) ;
2056
2058
}
2057
2059
2058
- distinct (
2060
+ async distinct (
2059
2061
className : string ,
2060
2062
schema : SchemaType ,
2061
2063
query : QueryType ,
@@ -2121,7 +2123,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
2121
2123
) ;
2122
2124
}
2123
2125
2124
- aggregate ( className : string , schema : any , pipeline : any ) {
2126
+ async aggregate ( className : string , schema : any , pipeline : any ) {
2125
2127
debug ( 'aggregate' , className , pipeline ) ;
2126
2128
const values = [ className ] ;
2127
2129
let index : number = 2 ;
@@ -2323,7 +2325,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
2323
2325
});
2324
2326
}
2325
2327
2326
- performInitialization({ VolatileClassesSchemas }: any) {
2328
+ async performInitialization({ VolatileClassesSchemas }: any) {
2327
2329
// TODO: This method needs to be rewritten to make proper use of connections (@vitaly-t)
2328
2330
debug('performInitialization');
2329
2331
const promises = VolatileClassesSchemas.map(schema => {
@@ -2362,7 +2364,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
2362
2364
});
2363
2365
}
2364
2366
2365
- createIndexes(className: string, indexes: any, conn: ?any): Promise<void> {
2367
+ async createIndexes(className: string, indexes: any, conn: ?any): Promise<void> {
2366
2368
return (conn || this._client).tx(t =>
2367
2369
t.batch(
2368
2370
indexes.map(i => {
@@ -2376,43 +2378,43 @@ export class PostgresStorageAdapter implements StorageAdapter {
2376
2378
);
2377
2379
}
2378
2380
2379
- createIndexesIfNeeded(
2381
+ async createIndexesIfNeeded(
2380
2382
className: string,
2381
2383
fieldName: string,
2382
2384
type: any,
2383
2385
conn: ?any
2384
2386
): Promise<void> {
2385
- return (conn || this._client).none(
2387
+ await (conn || this._client).none(
2386
2388
'CREATE INDEX $1:name ON $2:name ($3:name)',
2387
2389
[fieldName, className, type]
2388
2390
);
2389
2391
}
2390
2392
2391
- dropIndexes(className: string, indexes: any, conn: any): Promise<void> {
2393
+ async dropIndexes(className: string, indexes: any, conn: any): Promise<void> {
2392
2394
const queries = indexes.map(i => ({
2393
2395
query: 'DROP INDEX $1:name',
2394
2396
values: i,
2395
2397
}));
2396
- return (conn || this._client).tx(t =>
2398
+ await (conn || this._client).tx(t =>
2397
2399
t.none(this._pgp.helpers.concat(queries))
2398
2400
);
2399
2401
}
2400
2402
2401
- getIndexes(className: string) {
2403
+ async getIndexes(className: string) {
2402
2404
const qs = 'SELECT * FROM pg_indexes WHERE tablename = ${ className } ';
2403
2405
return this._client.any(qs, { className });
2404
2406
}
2405
2407
2406
- updateSchemaWithIndexes(): Promise<void> {
2408
+ async updateSchemaWithIndexes(): Promise<void> {
2407
2409
return Promise.resolve();
2408
2410
}
2409
2411
2410
2412
// Used for testing purposes
2411
- updateEstimatedCount(className: string) {
2413
+ async updateEstimatedCount(className: string) {
2412
2414
return this._client.none('ANALYZE $1:name', [className]);
2413
2415
}
2414
2416
2415
- createTransactionalSession(): Promise<any> {
2417
+ async createTransactionalSession(): Promise<any> {
2416
2418
return new Promise(resolve => {
2417
2419
const transactionalSession = {};
2418
2420
transactionalSession.result = this._client.tx(t => {
0 commit comments