@@ -133,6 +133,7 @@ export class PostgresStorageAdapter {
133133 }
134134 } )
135135 . then ( ( ) => this . _client . query ( 'INSERT INTO "_SCHEMA" ("className", "schema", "isParseClass") VALUES ($<className>, $<schema>, true)' , { className, schema } ) )
136+ . then ( ( ) => schema ) ;
136137 }
137138
138139 addFieldIfNotExists ( className , fieldName , type ) {
@@ -212,7 +213,7 @@ export class PostgresStorageAdapter {
212213 // rejection reason are TBD.
213214 getAllClasses ( ) {
214215 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 } ) ) ) ;
216217 }
217218
218219 // Return a promise for the schema with the given name, in Parse format. If
@@ -329,6 +330,10 @@ export class PostgresStorageAdapter {
329330 updatePatterns . push ( `$${ index } :name = $${ index + 1 } ` ) ;
330331 values . push ( fieldName , fieldValue ) ;
331332 index += 2 ;
333+ } else if ( fieldValue . __type === 'Pointer' ) {
334+ updatePatterns . push ( `$${ index } :name = $${ index + 1 } ` ) ;
335+ values . push ( fieldName , fieldValue . objectId ) ;
336+ index += 2 ;
332337 } else {
333338 return Promise . reject ( new Parse . Error ( Parse . Error . OPERATION_FORBIDDEN , `Postgres doesn't support update ${ JSON . stringify ( fieldValue ) } yet` ) ) ;
334339 }
@@ -352,7 +357,10 @@ export class PostgresStorageAdapter {
352357 let where = buildWhereClause ( { schema, query, index : 2 } )
353358 values . push ( ...where . values ) ;
354359
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 } ` ;
356364 if ( limit !== undefined ) {
357365 values . push ( limit ) ;
358366 }
@@ -408,7 +416,14 @@ export class PostgresStorageAdapter {
408416
409417 // Executes a count.
410418 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 ) )
412427 }
413428}
414429
0 commit comments