-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: implement insert/update/delete builders #39
Conversation
looks like you forgot to execute
|
lib/select-builder.js
Outdated
const { makeParamValue } = require('./query-builder'); | ||
const { checkTypeOrQuery, mapJoinIterable } = require('./utils'); | ||
const { QueryConditionsBuilder } = require('./query-conditions-builder'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to add .js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
lib/select-builder.js
Outdated
return mapJoinIterable( | ||
from, | ||
f => (typeof f === 'string' ? f : `${f.table} AS ${f.alias}`), | ||
f => (!f.alias ? String(f.table) : `${f.table} AS ${f.alias}`), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we use arrow-parens: always ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, looks like i mixed up styles. Will update.
lib/update-builder.js
Outdated
} | ||
|
||
build() { | ||
let query = 'UPDATE'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe: query = []; .push, push, .join ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to avoid array-join unnecessarily.
lib/utils.js
Outdated
@@ -30,9 +31,19 @@ const joinIterable = (val, sep) => { | |||
return res; | |||
}; | |||
|
|||
const checkTypeOrQuery = (value, name, type) => { | |||
if (!(value instanceof QueryBuilder) && typeof value !== type) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to me we need OR
logic here: !instance || !type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this is "exit condition" for error cases.
lib/delete-builder.js
Outdated
this.operations = { | ||
from: null, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.operations = { | |
from: null, | |
}; | |
this.operations = { from: null }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In line 16 we have one-liner
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
lib/delete-builder.js
Outdated
} | ||
|
||
build() { | ||
let query = 'DELETE'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe: query = []; .push, push, .join ?
lib/delete-builder.js
Outdated
build() { | ||
let query = 'DELETE'; | ||
|
||
const from = this.operations.from; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const from = this.operations.from; | |
const { from } = this.operations; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
lib/delete-builder.js
Outdated
if (!from) { | ||
throw new Error('Cannot generate SQL, tableName is not defined'); | ||
} | ||
query += String(from.table) + (from.alias ? `AS ${from.alias}` : ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like from.table
will be string already
query += String(from.table) + (from.alias ? `AS ${from.alias}` : ''); | |
const alias = from.alias ? `AS ${from.alias}` : ''; | |
query += `$from.table $alias`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
No description provided.