Skip to content

Commit 9dce5fa

Browse files
committed
changes in c-commonjs example
1 parent 1ac8749 commit 9dce5fa

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

JavaScript/c-commonjs/api/country.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ const country = db.crud('country');
66
module.exports = {
77
async read(id) {
88
console.log({ db });
9-
return country.read(id);
9+
return await country.read(id);
1010
},
1111

1212
async find(mask) {
1313
const sql = 'SELECT * from country where name like $1';
14-
return country.query(sql, [mask]);
14+
return await country.query(sql, [mask]);
1515
},
1616
};

JavaScript/c-commonjs/api/talks.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
module.exports = {
44
async say(message) {
55
console.log({ message });
6-
return { status: 'ok' };
6+
return await { status: 'ok' };
77
},
88
};

JavaScript/c-commonjs/api/user.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@ const users = db.crud('users');
66

77
module.exports = {
88
async read(id) {
9-
return users.read(id, ['id', 'login']);
9+
return await users.read(id, ['id', 'login']);
1010
},
1111

1212
async create({ login, password }) {
1313
const passwordHash = await common.hash(password);
14-
return users.create({ login, password: passwordHash });
14+
return await users.create({ login, password: passwordHash });
1515
},
1616

1717
async update(id, { login, password }) {
1818
const passwordHash = await common.hash(password);
19-
return users.update(id, { login, password: passwordHash });
19+
return await users.update(id, { login, password: passwordHash });
2020
},
2121

2222
async delete(id) {
23-
return users.delete(id);
23+
return await users.delete(id);
2424
},
2525

2626
async find(mask) {
2727
const sql = 'SELECT login from users where login like $1';
28-
return users.query(sql, [mask]);
28+
return await users.query(sql, [mask]);
2929
},
3030
};

JavaScript/c-commonjs/db.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ const init = (options) => {
1111
const crud = (table) => ({
1212
async query(sql, args) {
1313
const result = await pool.query(sql, args);
14-
return result.rows;
14+
return await result.rows;
1515
},
1616

1717
async read(id, fields = ['*']) {
1818
const names = fields.join(', ');
1919
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]);
2222
},
2323

2424
async create({ ...record }) {
@@ -33,7 +33,7 @@ const crud = (table) => ({
3333
const fields = '"' + keys.join('", "') + '"';
3434
const params = nums.join(', ');
3535
const sql = `INSERT INTO "${table}" (${fields}) VALUES (${params})`;
36-
return pool.query(sql, data);
36+
return await this.query(sql, data);
3737
},
3838

3939
async update(id, { ...record }) {
@@ -48,12 +48,12 @@ const crud = (table) => ({
4848
const delta = updates.join(', ');
4949
const sql = `UPDATE ${table} SET ${delta} WHERE id = $${++i}`;
5050
data.push(id);
51-
return pool.query(sql, data);
51+
return await this.query(sql, data);
5252
},
5353

5454
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]);
5757
},
5858
});
5959

JavaScript/c-commonjs/transport/http.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module.exports = (routing, port, console) => {
3232
if (!handler) return void res.end('"Not found"');
3333
const { args } = await receiveArgs(req);
3434
console.log(`${socket.remoteAddress} ${method} ${url}`);
35-
const result = await handler(args);
35+
const result = await handler(...args);
3636
res.end(JSON.stringify(result));
3737
}).listen(port);
3838

0 commit comments

Comments
 (0)