@@ -133,6 +133,7 @@ export class PostgresStorageAdapter {
133
133
}
134
134
} )
135
135
. then ( ( ) => this . _client . query ( 'INSERT INTO "_SCHEMA" ("className", "schema", "isParseClass") VALUES ($<className>, $<schema>, true)' , { className, schema } ) )
136
+ . then ( ( ) => schema ) ;
136
137
}
137
138
138
139
addFieldIfNotExists ( className , fieldName , type ) {
@@ -212,7 +213,7 @@ export class PostgresStorageAdapter {
212
213
// rejection reason are TBD.
213
214
getAllClasses ( ) {
214
215
return this . _ensureSchemaCollectionExists ( )
215
- . then ( ( ) => this . _client . map ( 'SELECT * FROM "_SCHEMA"' ) , null , row => ( { className : row . className , ...row . schema } ) ) ;
216
+ . then ( ( ) => this . _client . map ( 'SELECT * FROM "_SCHEMA"' , null , row => ( { className : row . className , ...row . schema } ) ) ) ;
216
217
}
217
218
218
219
// Return a promise for the schema with the given name, in Parse format. If
@@ -329,6 +330,10 @@ export class PostgresStorageAdapter {
329
330
updatePatterns . push ( `$${ index } :name = $${ index + 1 } ` ) ;
330
331
values . push ( fieldName , fieldValue ) ;
331
332
index += 2 ;
333
+ } else if ( fieldValue . __type === 'Pointer' ) {
334
+ updatePatterns . push ( `$${ index } :name = $${ index + 1 } ` ) ;
335
+ values . push ( fieldName , fieldValue . objectId ) ;
336
+ index += 2 ;
332
337
} else {
333
338
return Promise . reject ( new Parse . Error ( Parse . Error . OPERATION_FORBIDDEN , `Postgres doesn't support update ${ JSON . stringify ( fieldValue ) } yet` ) ) ;
334
339
}
@@ -352,7 +357,10 @@ export class PostgresStorageAdapter {
352
357
let where = buildWhereClause ( { schema, query, index : 2 } )
353
358
values . push ( ...where . values ) ;
354
359
355
- const qs = `SELECT * FROM $1:name WHERE ${ where . pattern } ${ limit !== undefined ? `LIMIT $${ values . length + 1 } ` : '' } ` ;
360
+ const wherePattern = where . pattern . length > 0 ? `WHERE ${ where . pattern } ` : '' ;
361
+ const limitPattern = limit !== undefined ? `LIMIT $${ values . length + 1 } ` : '' ;
362
+
363
+ const qs = `SELECT * FROM $1:name ${ wherePattern } ${ limitPattern } ` ;
356
364
if ( limit !== undefined ) {
357
365
values . push ( limit ) ;
358
366
}
@@ -408,7 +416,14 @@ export class PostgresStorageAdapter {
408
416
409
417
// Executes a count.
410
418
count ( className , schema , query ) {
411
- return Promise . reject ( 'Not implemented yet.' )
419
+ let values = [ className ] ;
420
+ let where = buildWhereClause ( { schema, query, index : 2 } ) ;
421
+ values . push ( ...where . values ) ;
422
+
423
+ const wherePattern = where . pattern . length > 0 ? `WHERE ${ where . pattern } ` : '' ;
424
+ const qs = `SELECT COUNT(*) FROM $1:name ${ wherePattern } ` ;
425
+ return this . _client . query ( qs , values )
426
+ . then ( result => parseInt ( result [ 0 ] . count ) )
412
427
}
413
428
}
414
429
0 commit comments