Skip to content

Commit

Permalink
Merge pull request #6 from olegnn/1.0.1
Browse files Browse the repository at this point in the history
`1.0.1`: minor improvements
  • Loading branch information
olegnn authored Aug 17, 2023
2 parents d3da516 + 9071a19 commit a1dfdb2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"author": "Oleg Nosov <[email protected]>",
"name": "sql-template-builder",
"version": "1.0.0",
"version": "1.0.1",
"main": "./index.js",
"description": "Complex SQL query builder",
"keywords": [
Expand Down
20 changes: 13 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,16 @@ const TEMPLATE_ARGS = {
};

const TEMPLATE_ARG = Symbol("sql-template-builder/TEMPLATE_ARG");
const NO_VALUE = Symbol("sql-template-builder/NO_VALUE");

const EMPTY_ARRAY = [];
const NEW_LINE_REGEXP = /\n/g;
const CACHED_MEMBERS = [
MEMBERS.GET_QUERY_VALUES,
MEMBERS.GET_QUERY_STATEMENTS,
MEMBERS.GET_TEXT,
MEMBERS.GET_SQL,
];

/**
* @class
Expand All @@ -55,6 +63,7 @@ class SQLQuery {
* @param {?Array<string>} queryParts - An array of the query parts.
* @param {?Array<*>} values - An array of the query values.
* @param {?string} delimiter - String to join top-level statements.
* @param {*?} name - Name to be used for this query.
* @returns {SQLQuery}
*/
constructor(
Expand All @@ -80,12 +89,10 @@ class SQLQuery {
this[MEMBERS.VALUES] = values;
this[MEMBERS.DELIMITER] = delimiter;
this[MEMBERS.NAME] = name;
[
MEMBERS.GET_QUERY_VALUES,
MEMBERS.GET_QUERY_STATEMENTS,
MEMBERS.GET_TEXT,
MEMBERS.GET_SQL,
].forEach((key) => void (this[key] = cacheLast(this[key])));

CACHED_MEMBERS.forEach((key) => {
this[key] = cacheLast(this[key]);
});
}
}

Expand Down Expand Up @@ -325,7 +332,6 @@ Object.defineProperty(SQLQuery.prototype, "sql", {
* @returns {function(): T}
*/
const cacheLast = (fn) => {
const NO_VALUE = {};
let lastVal = NO_VALUE;

return function cached() {
Expand Down

0 comments on commit a1dfdb2

Please sign in to comment.