@linked-db/linked-ql
Advanced tools
Comparing version 0.7.8 to 0.7.9
@@ -14,3 +14,3 @@ { | ||
"icon": "https://webqit.io/icon.svg", | ||
"version": "0.7.8", | ||
"version": "0.7.9", | ||
"license": "MIT", | ||
@@ -17,0 +17,0 @@ "repository": { |
@@ -31,2 +31,3 @@ | ||
LIMIT_CLAUSE = null; | ||
UNION_CLAUSE = null; | ||
@@ -238,2 +239,11 @@ /** | ||
/** | ||
* Sets the statement's UNION_CLAUSE | ||
* | ||
* .union(query); | ||
* | ||
* @return string | ||
*/ | ||
union(...union) { return (this.build('UNION_CLAUSE', union, this.constructor, 'select'), this.UNION_CLAUSE/* for: chaining purposes */); } | ||
/** | ||
* @inheritdoc | ||
@@ -269,2 +279,3 @@ */ | ||
limit_clause: this.LIMIT_CLAUSE, | ||
union_clause: this.UNION_CLAUSE, | ||
flags: this.FLAGS, | ||
@@ -290,2 +301,3 @@ }; | ||
if (json.limit_clause) instance.limit(json.limit_clause); | ||
if (json.union_clause) instance.union(json.union_clause); | ||
return instance; | ||
@@ -310,2 +322,3 @@ } | ||
if (this.LIMIT_CLAUSE) sql.push('LIMIT', (Array.isArray(this.LIMIT_CLAUSE) ? this.LIMIT_CLAUSE : [this.LIMIT_CLAUSE]).join(',')); | ||
if (this.UNION_CLAUSE) sql.push('UNION', this.UNION_CLAUSE); | ||
return sql.join(' '); | ||
@@ -324,3 +337,3 @@ } | ||
const $body = this.mySubstitutePlaceholders(instance, body.trim()); | ||
const clausesMap = { from: { backtest: '^(?!.*\\s+DISTINCT\\s+$)', test: 'FROM' }, join:JoinClause, where:'WHERE', groupBy:GroupByClause, having:'HAVING', window:WindowClause, orderBy:OrderByClause, offset:'OFFSET', limit:'LIMIT' }; | ||
const clausesMap = { from: { backtest: '^(?!.*\\s+DISTINCT\\s+$)', test: 'FROM' }, join:JoinClause, where:'WHERE', groupBy:GroupByClause, having:'HAVING', window:WindowClause, orderBy:OrderByClause, offset:'OFFSET', limit:'LIMIT', union:'UNION' }; | ||
const { tokens: [ fieldsSpec, ...tokens ], matches: clauses } = Lexer.lex($body, Object.values(clausesMap).map(x => typeof x === 'string' || x.test ? x : x.regex), { useRegex: 'i' }); | ||
@@ -348,2 +361,7 @@ // SELECT_LIST | ||
} | ||
// UNION | ||
else if (clauseKey === 'UNION') { | ||
const node = parseCallback(instance, tokens.shift().trim(), [this]); | ||
instance[clauseKey](node); | ||
} | ||
// OFFSET|LIMIT | ||
@@ -350,0 +368,0 @@ else if (['offset', 'limit'].includes(clauseKey)) { |
@@ -76,2 +76,7 @@ | ||
/** | ||
* NULL | ||
*/ | ||
null(...args) { return this.constraint('NULL', ...args); } | ||
/** | ||
* ON_UPDATE | ||
@@ -78,0 +83,0 @@ */ |
@@ -35,3 +35,3 @@ | ||
"$ref" int CONSTRAINT nn not null CONSTRAINT uni_q unique CONSTRAINT fk REFERENCES pretest (id) MATCH FULL ON DELETE RESTRICT ON UPDATE SET NULL, | ||
ref2 int, | ||
ref2 int unique, | ||
rand VARCHAR (11) CHECK (rand IS NOT NULL), | ||
@@ -38,0 +38,0 @@ rand2 text null, |
@@ -109,2 +109,3 @@ | ||
) | ||
query1.union(q => q.name('a')); | ||
//query1.from(['new_db_name','books']).as('base_alias'); | ||
@@ -111,0 +112,0 @@ query1.from(['new_db_name','users']).as('base_alias'); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
1663312
11346