@linked-db/linked-ql
Advanced tools
Comparing version 0.4.0 to 0.4.1
@@ -14,3 +14,3 @@ { | ||
"icon": "https://webqit.io/icon.svg", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"license": "MIT", | ||
@@ -17,0 +17,0 @@ "repository": { |
@@ -55,6 +55,8 @@ | ||
// Where and fields | ||
if (Array.isArray(args[0])) { | ||
query.select(...args[0]); | ||
if (/^\d+$/.test(args[0]) || _isObject(args[0])) { | ||
await this.resolveWhere(query, args[0]); | ||
} else { | ||
query.select(...(args[0] || ['*'])); | ||
await this.resolveWhere(query, args[1]); | ||
} else await this.resolveWhere(query, args[0]); | ||
} | ||
// Handle | ||
@@ -203,2 +205,3 @@ query.from([this.database.name, this.name]); | ||
values = values.map(row => row.map(v => { | ||
if (this.params.bindings !== false) return q => q.$bind(0, v); | ||
if ([true,false,null].includes(v)) return q => q.literal(v); | ||
@@ -205,0 +208,0 @@ if (v instanceof Date) return q => q.value(v.toISOString().split('.')[0]); |
@@ -64,3 +64,4 @@ | ||
} | ||
const result = await this.driver.query(queryInstance.toString(), params.params || []); | ||
const bindings = (queryInstance.BINDINGS || []).concat(params.params || []).map(value => Array.isArray(value) || typeof value === 'object' && value ? JSON.stringify(value) : value); | ||
const result = await this.driver.query(queryInstance.toString(), bindings); | ||
return result.rows || result; | ||
@@ -67,0 +68,0 @@ }, ...arguments); |
@@ -12,3 +12,3 @@ | ||
super(context); | ||
this._vars = []; | ||
this._BINDINGS = []; | ||
} | ||
@@ -29,3 +29,3 @@ | ||
*/ | ||
get variables() { return this._vars; } | ||
get BINDINGS() { return this._BINDINGS; } | ||
@@ -38,2 +38,11 @@ /** | ||
/** | ||
* @inheritdoc | ||
*/ | ||
clone() { | ||
const clone = super.clone(); | ||
if (this._BINDINGS.length) clone._BINDINGS = this._BINDINGS.slice(0); | ||
return clone; | ||
} | ||
/** | ||
* @returns String | ||
@@ -40,0 +49,0 @@ */ |
@@ -23,8 +23,11 @@ | ||
*/ | ||
$value(offset, value = undefined) { | ||
$var(offset) { this.OFFSET = offset; } | ||
/** | ||
* @inheritdoc | ||
*/ | ||
$bind(offset, value) { | ||
this.OFFSET = offset; | ||
if (arguments.length === 2) { | ||
this.statementNode.variables.push(value); | ||
if (this.OFFSET === 0) this.OFFSET = this.statementNode.variables.length; | ||
} | ||
this.statementNode.BINDINGS.push(value); | ||
if (this.OFFSET === 0) this.OFFSET = this.statementNode.BINDINGS.length; | ||
} | ||
@@ -31,0 +34,0 @@ |
@@ -25,4 +25,5 @@ | ||
//await lqlClient.alterDatabase('private', db => db.name('public'), { noCreateSavepoint: true }); | ||
console.log('DROP 4', await lqlClient.query('SELECT 2 + 3 as summm')); | ||
console.log('DROP 4', await lqlClient.query('DROP DATABASE if exists obj_information_schema CASCADE')); | ||
console.log('SELECT 1', await lqlClient.query('SELECT 2 + 3 as summm')); | ||
console.log('DROP 5', await lqlClient.query('DROP DATABASE if exists obj_information_schema CASCADE')); | ||
console.log('DROP 4', await lqlClient.query('DROP DATABASE if exists test_db CASCADE')); | ||
console.log('DROP 3', await lqlClient.query('DROP TABLE if exists public.books')); | ||
@@ -48,2 +49,12 @@ console.log('DROP 2', await lqlClient.query('DROP TABLE if exists public.users')); | ||
console.log('.....create test_db.....', await lqlClient.query(`CREATE DATABASE test_db`)); | ||
const savepoint2b = await lqlClient.database('test_db').savepoint(); | ||
console.log('.....create test_db.users.....', await lqlClient.query(`CREATE TABLE test_db.users ( | ||
id int primary key generated always as identity, | ||
title varchar, | ||
name varchar, | ||
created_time timestamp | ||
)`, { savepointDesc: 'Created users' })); | ||
const savepoint2c = await lqlClient.database('test_db').savepoint(); | ||
console.log('.....create books.....', await lqlClient.query(`CREATE TABLE books ( | ||
@@ -50,0 +61,0 @@ id int primary key generated always as identity, |
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
1589074
12104