@@ -11,14 +11,14 @@ const init = (options) => {
11
11
const crud = ( table ) => ( {
12
12
async query ( sql , args ) {
13
13
const result = await pool . query ( sql , args ) ;
14
- return result . rows ;
14
+ return await result . rows ;
15
15
} ,
16
16
17
17
async read ( id , fields = [ '*' ] ) {
18
18
const names = fields . join ( ', ' ) ;
19
19
const sql = `SELECT ${ names } FROM ${ table } ` ;
20
- if ( ! id ) return pool . query ( sql ) ;
21
- return pool . query ( `${ sql } WHERE id = $1` , [ id ] ) ;
20
+ if ( ! id ) return this . query ( sql ) ;
21
+ return await this . query ( `${ sql } WHERE id = $1` , [ id ] ) ;
22
22
} ,
23
23
24
24
async create ( { ...record } ) {
@@ -33,7 +33,7 @@ const crud = (table) => ({
33
33
const fields = '"' + keys . join ( '", "' ) + '"' ;
34
34
const params = nums . join ( ', ' ) ;
35
35
const sql = `INSERT INTO "${ table } " (${ fields } ) VALUES (${ params } )` ;
36
- return pool . query ( sql , data ) ;
36
+ return await this . query ( sql , data ) ;
37
37
} ,
38
38
39
39
async update ( id , { ...record } ) {
@@ -48,12 +48,12 @@ const crud = (table) => ({
48
48
const delta = updates . join ( ', ' ) ;
49
49
const sql = `UPDATE ${ table } SET ${ delta } WHERE id = $${ ++ i } ` ;
50
50
data . push ( id ) ;
51
- return pool . query ( sql , data ) ;
51
+ return await this . query ( sql , data ) ;
52
52
} ,
53
53
54
54
async delete ( id ) {
55
- const sql = ' DELETE FROM ${table} WHERE id = $1' ;
56
- return pool . query ( sql , [ id ] ) ;
55
+ const sql = ` DELETE FROM ${ table } WHERE id = $1` ;
56
+ return await this . query ( sql , [ id ] ) ;
57
57
} ,
58
58
} ) ;
59
59
0 commit comments