diff --git a/JavaScript/a-config/api/country.js b/JavaScript/a-config/api/country.js index f99ac87..f1d91ca 100644 --- a/JavaScript/a-config/api/country.js +++ b/JavaScript/a-config/api/country.js @@ -3,11 +3,11 @@ const country = db('country'); ({ async read(id) { console.log({ db }); - return country.read(id); + return await country.read(id); }, async find(mask) { const sql = 'SELECT * from country where name like $1'; - return country.query(sql, [mask]); + return await country.query(sql, [mask]); }, }); diff --git a/JavaScript/a-config/api/user.js b/JavaScript/a-config/api/user.js index 0faaeb6..1f69dca 100644 --- a/JavaScript/a-config/api/user.js +++ b/JavaScript/a-config/api/user.js @@ -1,24 +1,24 @@ ({ async read(id) { - return db('users').read(id, ['id', 'login']); + return await db('users').read(id, ['id', 'login']); }, async create({ login, password }) { const passwordHash = await common.hash(password); - return db('users').create({ login, password: passwordHash }); + return await db('users').create({ login, password: passwordHash }); }, async update(id, { login, password }) { const passwordHash = await common.hash(password); - return db('users').update(id, { login, password: passwordHash }); + return await db('users').update(id, { login, password: passwordHash }); }, async delete(id) { - return db('users').delete(id); + return await db('users').delete(id); }, async find(mask) { const sql = 'SELECT login from users where login like $1'; - return db('users').query(sql, [mask]); + return await db('users').query(sql, [mask]); }, }); diff --git a/JavaScript/a-config/db.js b/JavaScript/a-config/db.js index 5e26018..8674f26 100644 --- a/JavaScript/a-config/db.js +++ b/JavaScript/a-config/db.js @@ -5,14 +5,14 @@ const pg = require('pg'); const crud = (pool) => (table) => ({ async query(sql, args) { const result = await pool.query(sql, args); - return result.rows; + return await result.rows; }, async read(id, fields = ['*']) { const names = fields.join(', '); const sql = `SELECT ${names} FROM ${table}`; - if (!id) return pool.query(sql); - return pool.query(`${sql} WHERE id = $1`, [id]); + if (!id) return await this.query(sql); + return await this.query(`${sql} WHERE id = $1`, [id]); }, async create({ ...record }) { @@ -27,7 +27,7 @@ const crud = (pool) => (table) => ({ const fields = '"' + keys.join('", "') + '"'; const params = nums.join(', '); const sql = `INSERT INTO "${table}" (${fields}) VALUES (${params})`; - return pool.query(sql, data); + return await this.query(sql, data); }, async update(id, { ...record }) { @@ -42,12 +42,12 @@ const crud = (pool) => (table) => ({ const delta = updates.join(', '); const sql = `UPDATE ${table} SET ${delta} WHERE id = $${++i}`; data.push(id); - return pool.query(sql, data); + return await this.query(sql, data); }, async delete(id) { - const sql = 'DELETE FROM ${table} WHERE id = $1'; - return pool.query(sql, [id]); + const sql = `DELETE FROM ${table} WHERE id = $1`; + return await this.query(sql, [id]); }, }); diff --git a/JavaScript/a-config/http.js b/JavaScript/a-config/http.js index 9f3f87f..52a57ce 100644 --- a/JavaScript/a-config/http.js +++ b/JavaScript/a-config/http.js @@ -24,7 +24,7 @@ module.exports = (routing, port) => { if (signature.includes('{')) args.push(await receiveArgs(req)); console.log(`${socket.remoteAddress} ${method} ${url}`); const result = await handler(...args); - res.end(JSON.stringify(result.rows)); + res.end(JSON.stringify(result)); }).listen(port); console.log(`API on port ${port}`); diff --git a/JavaScript/a-config/ws.js b/JavaScript/a-config/ws.js index ad9cd74..69c972b 100644 --- a/JavaScript/a-config/ws.js +++ b/JavaScript/a-config/ws.js @@ -26,7 +26,7 @@ module.exports = (routing, port) => { console.log(`${ip} ${name}.${method}(${parameters})`); try { const result = await handler(...args); - connection.send(JSON.stringify(result.rows), { binary: false }); + connection.send(JSON.stringify(result), { binary: false }); } catch (err) { console.error(err); connection.send('"Server error"', { binary: false }); diff --git a/JavaScript/b-transport/api/country.js b/JavaScript/b-transport/api/country.js index f99ac87..f1d91ca 100644 --- a/JavaScript/b-transport/api/country.js +++ b/JavaScript/b-transport/api/country.js @@ -3,11 +3,11 @@ const country = db('country'); ({ async read(id) { console.log({ db }); - return country.read(id); + return await country.read(id); }, async find(mask) { const sql = 'SELECT * from country where name like $1'; - return country.query(sql, [mask]); + return await country.query(sql, [mask]); }, }); diff --git a/JavaScript/b-transport/api/talks.js b/JavaScript/b-transport/api/talks.js index d910c12..9a994ff 100644 --- a/JavaScript/b-transport/api/talks.js +++ b/JavaScript/b-transport/api/talks.js @@ -1,6 +1,6 @@ ({ async say(message) { console.log({ message }); - return { status: 'ok' }; + return await { status: 'ok' }; }, }); diff --git a/JavaScript/b-transport/api/user.js b/JavaScript/b-transport/api/user.js index 0faaeb6..1f69dca 100644 --- a/JavaScript/b-transport/api/user.js +++ b/JavaScript/b-transport/api/user.js @@ -1,24 +1,24 @@ ({ async read(id) { - return db('users').read(id, ['id', 'login']); + return await db('users').read(id, ['id', 'login']); }, async create({ login, password }) { const passwordHash = await common.hash(password); - return db('users').create({ login, password: passwordHash }); + return await db('users').create({ login, password: passwordHash }); }, async update(id, { login, password }) { const passwordHash = await common.hash(password); - return db('users').update(id, { login, password: passwordHash }); + return await db('users').update(id, { login, password: passwordHash }); }, async delete(id) { - return db('users').delete(id); + return await db('users').delete(id); }, async find(mask) { const sql = 'SELECT login from users where login like $1'; - return db('users').query(sql, [mask]); + return await db('users').query(sql, [mask]); }, }); diff --git a/JavaScript/b-transport/db.js b/JavaScript/b-transport/db.js index 5e26018..8674f26 100644 --- a/JavaScript/b-transport/db.js +++ b/JavaScript/b-transport/db.js @@ -5,14 +5,14 @@ const pg = require('pg'); const crud = (pool) => (table) => ({ async query(sql, args) { const result = await pool.query(sql, args); - return result.rows; + return await result.rows; }, async read(id, fields = ['*']) { const names = fields.join(', '); const sql = `SELECT ${names} FROM ${table}`; - if (!id) return pool.query(sql); - return pool.query(`${sql} WHERE id = $1`, [id]); + if (!id) return await this.query(sql); + return await this.query(`${sql} WHERE id = $1`, [id]); }, async create({ ...record }) { @@ -27,7 +27,7 @@ const crud = (pool) => (table) => ({ const fields = '"' + keys.join('", "') + '"'; const params = nums.join(', '); const sql = `INSERT INTO "${table}" (${fields}) VALUES (${params})`; - return pool.query(sql, data); + return await this.query(sql, data); }, async update(id, { ...record }) { @@ -42,12 +42,12 @@ const crud = (pool) => (table) => ({ const delta = updates.join(', '); const sql = `UPDATE ${table} SET ${delta} WHERE id = $${++i}`; data.push(id); - return pool.query(sql, data); + return await this.query(sql, data); }, async delete(id) { - const sql = 'DELETE FROM ${table} WHERE id = $1'; - return pool.query(sql, [id]); + const sql = `DELETE FROM ${table} WHERE id = $1`; + return await this.query(sql, [id]); }, }); diff --git a/JavaScript/b-transport/transport/http.js b/JavaScript/b-transport/transport/http.js index e12b373..6367dd3 100644 --- a/JavaScript/b-transport/transport/http.js +++ b/JavaScript/b-transport/transport/http.js @@ -32,7 +32,7 @@ module.exports = (routing, port, console) => { if (!handler) return void res.end('"Not found"'); const { args } = await receiveArgs(req); console.log(`${socket.remoteAddress} ${method} ${url}`); - const result = await handler(args); + const result = await handler(...args); res.end(JSON.stringify(result)); }).listen(port); diff --git a/JavaScript/c-commonjs/api/country.js b/JavaScript/c-commonjs/api/country.js index 4afc641..bfd3eff 100644 --- a/JavaScript/c-commonjs/api/country.js +++ b/JavaScript/c-commonjs/api/country.js @@ -6,11 +6,11 @@ const country = db.crud('country'); module.exports = { async read(id) { console.log({ db }); - return country.read(id); + return await country.read(id); }, async find(mask) { const sql = 'SELECT * from country where name like $1'; - return country.query(sql, [mask]); + return await country.query(sql, [mask]); }, }; diff --git a/JavaScript/c-commonjs/api/talks.js b/JavaScript/c-commonjs/api/talks.js index 04378d2..4081d8e 100644 --- a/JavaScript/c-commonjs/api/talks.js +++ b/JavaScript/c-commonjs/api/talks.js @@ -3,6 +3,6 @@ module.exports = { async say(message) { console.log({ message }); - return { status: 'ok' }; + return await { status: 'ok' }; }, }; diff --git a/JavaScript/c-commonjs/api/user.js b/JavaScript/c-commonjs/api/user.js index b2e65b7..57843c4 100644 --- a/JavaScript/c-commonjs/api/user.js +++ b/JavaScript/c-commonjs/api/user.js @@ -6,25 +6,25 @@ const users = db.crud('users'); module.exports = { async read(id) { - return users.read(id, ['id', 'login']); + return await users.read(id, ['id', 'login']); }, async create({ login, password }) { const passwordHash = await common.hash(password); - return users.create({ login, password: passwordHash }); + return await users.create({ login, password: passwordHash }); }, async update(id, { login, password }) { const passwordHash = await common.hash(password); - return users.update(id, { login, password: passwordHash }); + return await users.update(id, { login, password: passwordHash }); }, async delete(id) { - return users.delete(id); + return await users.delete(id); }, async find(mask) { const sql = 'SELECT login from users where login like $1'; - return users.query(sql, [mask]); + return await users.query(sql, [mask]); }, }; diff --git a/JavaScript/c-commonjs/db.js b/JavaScript/c-commonjs/db.js index 45a4a52..108a125 100644 --- a/JavaScript/c-commonjs/db.js +++ b/JavaScript/c-commonjs/db.js @@ -11,14 +11,14 @@ const init = (options) => { const crud = (table) => ({ async query(sql, args) { const result = await pool.query(sql, args); - return result.rows; + return await result.rows; }, async read(id, fields = ['*']) { const names = fields.join(', '); const sql = `SELECT ${names} FROM ${table}`; - if (!id) return pool.query(sql); - return pool.query(`${sql} WHERE id = $1`, [id]); + if (!id) return this.query(sql); + return await this.query(`${sql} WHERE id = $1`, [id]); }, async create({ ...record }) { @@ -33,7 +33,7 @@ const crud = (table) => ({ const fields = '"' + keys.join('", "') + '"'; const params = nums.join(', '); const sql = `INSERT INTO "${table}" (${fields}) VALUES (${params})`; - return pool.query(sql, data); + return await this.query(sql, data); }, async update(id, { ...record }) { @@ -48,12 +48,12 @@ const crud = (table) => ({ const delta = updates.join(', '); const sql = `UPDATE ${table} SET ${delta} WHERE id = $${++i}`; data.push(id); - return pool.query(sql, data); + return await this.query(sql, data); }, async delete(id) { - const sql = 'DELETE FROM ${table} WHERE id = $1'; - return pool.query(sql, [id]); + const sql = `DELETE FROM ${table} WHERE id = $1`; + return await this.query(sql, [id]); }, }); diff --git a/JavaScript/c-commonjs/transport/http.js b/JavaScript/c-commonjs/transport/http.js index e12b373..6367dd3 100644 --- a/JavaScript/c-commonjs/transport/http.js +++ b/JavaScript/c-commonjs/transport/http.js @@ -32,7 +32,7 @@ module.exports = (routing, port, console) => { if (!handler) return void res.end('"Not found"'); const { args } = await receiveArgs(req); console.log(`${socket.remoteAddress} ${method} ${url}`); - const result = await handler(args); + const result = await handler(...args); res.end(JSON.stringify(result)); }).listen(port);