Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIx: pg driver's output goes beyond database layer #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions JavaScript/b-transport/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const crud = (pool) => (table) => ({
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 this.query(`${sql} WHERE id = $1`, [id]);
},

async create({ ...record }) {
Expand All @@ -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 this.query(sql, data);
},

async update(id, { ...record }) {
Expand All @@ -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 this.query(sql, data);
},

async delete(id) {
const sql = 'DELETE FROM ${table} WHERE id = $1';
return pool.query(sql, [id]);
return this.query(sql, [id]);
},
});

Expand Down
2 changes: 1 addition & 1 deletion JavaScript/b-transport/transport/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = (routing, port, console) => {
if (!handler) return 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);

Expand Down
10 changes: 5 additions & 5 deletions JavaScript/c-commonjs/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const crud = (table) => ({
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 this.query(`${sql} WHERE id = $1`, [id]);
},

async create({ ...record }) {
Expand All @@ -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 this.query(sql, data);
},

async update(id, { ...record }) {
Expand All @@ -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 this.query(sql, data);
},

async delete(id) {
const sql = 'DELETE FROM ${table} WHERE id = $1';
return pool.query(sql, [id]);
return this.query(sql, [id]);
},
});

Expand Down
2 changes: 1 addition & 1 deletion JavaScript/c-commonjs/transport/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = (routing, port, console) => {
if (!handler) return 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);

Expand Down
10 changes: 5 additions & 5 deletions JavaScript/d-messenger/lib/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const crud = (pool) => (table) => ({
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 this.query(`${sql} WHERE id = $1`, [id]);
},

async create({ ...record }) {
Expand All @@ -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 this.query(sql, data);
},

async update(id, { ...record }) {
Expand All @@ -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 this.query(sql, data);
},

async delete(id) {
const sql = 'DELETE FROM ${table} WHERE id = $1';
return pool.query(sql, [id]);
return this.query(sql, [id]);
},
});

Expand Down