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

feat: implement insert/update/delete builders #39

Merged
merged 5 commits into from Jul 26, 2023

Conversation

lundibundi
Copy link
Member

No description provided.

@tshemsedinov
Copy link
Member

looks like you forgot to execute

npm run fmt

Comment on lines 5 to 7
const { makeParamValue } = require('./query-builder');
const { checkTypeOrQuery, mapJoinIterable } = require('./utils');
const { QueryConditionsBuilder } = require('./query-conditions-builder');
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

return mapJoinIterable(
from,
f => (typeof f === 'string' ? f : `${f.table} AS ${f.alias}`),
f => (!f.alias ? String(f.table) : `${f.table} AS ${f.alias}`),
Copy link
Member

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 ?

Copy link
Member Author

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.

}

build() {
let query = 'UPDATE';
Copy link
Member

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 ?

Copy link
Member Author

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) {
Copy link
Member

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

Copy link
Member Author

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.

Comment on lines 9 to 11
this.operations = {
from: null,
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.operations = {
from: null,
};
this.operations = { from: null };

Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}

build() {
let query = 'DELETE';
Copy link
Member

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 ?

build() {
let query = 'DELETE';

const from = this.operations.from;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const from = this.operations.from;
const { from } = this.operations;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

if (!from) {
throw new Error('Cannot generate SQL, tableName is not defined');
}
query += String(from.table) + (from.alias ? `AS ${from.alias}` : '');
Copy link
Member

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

Suggested change
query += String(from.table) + (from.alias ? `AS ${from.alias}` : '');
const alias = from.alias ? `AS ${from.alias}` : '';
query += `$from.table $alias`;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@lundibundi lundibundi changed the title feat: start working on update/delete feat: implement insert/update/delete builders Jul 25, 2023
@lundibundi lundibundi marked this pull request as ready for review July 25, 2023 18:14
Copy link
Member

@tshemsedinov tshemsedinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lundibundi lundibundi merged commit 046298e into master Jul 26, 2023
12 checks passed
@lundibundi lundibundi deleted the feat-add-insert-update-delete branch July 26, 2023 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants