clickhouse
Advanced tools
Comparing version 1.2.9 to 1.2.10
16
index.js
@@ -45,4 +45,2 @@ 'use strict'; | ||
// const R_DATE = /\d{4}-\d{2}-\d{2}/; | ||
// const R_DATETIME = /\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}/; | ||
const R_ERROR = new RegExp('Code: ([0-9]{2}), .*Exception: (.+?), e\.what'); | ||
@@ -395,2 +393,3 @@ | ||
debug: false, | ||
database: 'default', | ||
user: 'default', | ||
@@ -525,4 +524,9 @@ password: '', | ||
let reqParams = {}; | ||
let reqParams = {}, | ||
configQS = _.merge({}, me.opts.config); | ||
if (me.opts.database) { | ||
configQS.database = me.opts.database; | ||
} | ||
if (typeof query === 'string') { | ||
@@ -532,3 +536,3 @@ let sql = query.trim(); | ||
if (sql.match(/^(select|show)/i)) { | ||
reqParams['url'] = me.url + '?query=' + encodeURIComponent(sql + ' FORMAT JSON') + '&' + querystring.stringify(me.opts.config); | ||
reqParams['url'] = me.url + '?query=' + encodeURIComponent(sql + ' FORMAT JSON') + '&' + querystring.stringify(configQS); | ||
@@ -553,3 +557,3 @@ if (data && data.external) { | ||
} else if (query.match(/^insert/i)) { | ||
reqParams['url'] = me.url + '?query=' + encodeURIComponent(query + ' FORMAT TabSeparated') + '&' + querystring.stringify(me.opts.config); | ||
reqParams['url'] = me.url + '?query=' + encodeURIComponent(query + ' FORMAT TabSeparated') + '&' + querystring.stringify(configQS); | ||
@@ -560,3 +564,3 @@ if (data) { | ||
} else { | ||
reqParams['url'] = me.url + '?query=' + encodeURIComponent(query) + '&' + querystring.stringify(me.opts.config); | ||
reqParams['url'] = me.url + '?query=' + encodeURIComponent(query) + '&' + querystring.stringify(configQS); | ||
} | ||
@@ -563,0 +567,0 @@ |
@@ -33,3 +33,3 @@ { | ||
"name": "clickhouse", | ||
"version": "1.2.9", | ||
"version": "1.2.10", | ||
"repository": { | ||
@@ -36,0 +36,0 @@ "type": "git", |
@@ -7,6 +7,10 @@ const | ||
const database = 'test_' + _.random(1000, 100000); | ||
const | ||
clickhouse = new ClickHouse({debug: false}), | ||
rowCount = _.random(50 * 1024, 1024 * 1024), | ||
clickhouse = new ClickHouse({ | ||
database : database, | ||
debug : false | ||
}), | ||
rowCount = 7,//_.random(50 * 1024, 1024 * 1024), | ||
sql = `SELECT | ||
@@ -19,2 +23,8 @@ number, | ||
before(async () => { | ||
const temp = new ClickHouse(); | ||
await temp.query(`DROP DATABASE IF EXISTS ${database}`).toPromise(); | ||
await temp.query(`CREATE DATABASE ${database}`).toPromise(); | ||
}); | ||
@@ -133,3 +143,3 @@ describe('Exec', () => { | ||
// } | ||
// | ||
// | ||
// expect(i).to.be(rowCount); | ||
@@ -160,3 +170,3 @@ // }); | ||
expect(result[0].count).to.be(rowCount); | ||
}); | ||
}); | ||
}); | ||
@@ -186,3 +196,3 @@ | ||
clickhouse.sessionId = sessionId; | ||
}); | ||
}); | ||
}); | ||
@@ -194,5 +204,4 @@ | ||
clickhouse.sessionId = Date.now(); | ||
await clickhouse.query('CREATE DATABASE IF NOT EXISTS test').toPromise(); | ||
await clickhouse.query('use test').toPromise(); | ||
await clickhouse.query(` | ||
const r = await clickhouse.query(` | ||
CREATE TABLE IF NOT EXISTS test_array ( | ||
@@ -206,2 +215,3 @@ date Date, | ||
`).toPromise(); | ||
expect(r).to.be.ok(); | ||
@@ -227,4 +237,4 @@ const rows = [ | ||
const r = await clickhouse.insert('INSERT INTO test_array (date, arr, arr2, arr3)', rows).toPromise(); | ||
expect(r).to.be.ok(); | ||
const r2 = await clickhouse.insert('INSERT INTO test_array (date, str, arr, arr2, arr3)', rows).toPromise(); | ||
expect(r2).to.be.ok(); | ||
@@ -251,3 +261,3 @@ | ||
const result5 = await clickhouse.insert( | ||
'INSERT INTO session_temp', data | ||
'INSERT INTO session_temp', data | ||
).toPromise(); | ||
@@ -304,5 +314,5 @@ expect(result5).to.be.ok(); | ||
const result11 = await clickhouse.query('SELECT date FROM test.test_array GROUP BY date WITH TOTALS').withTotals().toPromise(); | ||
expect(result11).to.have.key('meta'); | ||
expect(result11).to.have.key('data'); | ||
const result11 = await clickhouse.query('SELECT date FROM test_array GROUP BY date WITH TOTALS').withTotals().toPromise(); | ||
expect(result11).to.have.key('meta'); | ||
expect(result11).to.have.key('data'); | ||
expect(result11).to.have.key('totals'); | ||
@@ -318,3 +328,3 @@ expect(result11).to.have.key('rows'); | ||
const int_value_data = [{int_value: 0}] | ||
const int_value_data = [{int_value: 0}]; | ||
const result13 = await clickhouse.insert('INSERT INTO test_int_temp (int_value)', int_value_data).toPromise(); | ||
@@ -330,3 +340,3 @@ expect(result13).to.be.ok(); | ||
describe('response codes', () => { | ||
it('table is not exists', async () => { | ||
it('table is not exists', async () => { | ||
try { | ||
@@ -347,3 +357,3 @@ const result = await clickhouse.query('DROP TABLE session_temp').toPromise(); | ||
// expect(result).to.be.ok(); | ||
// await clickhouse.query('SELECT COUNT(*) AS count FROM session_temp2').toPromise(); | ||
@@ -358,1 +368,22 @@ // expect().fail('You should not be here2'); | ||
}); | ||
describe('set database', () => { | ||
it('create instance with non-default database', async () => { | ||
const noDefaultDb = 'default_' + _.random(1000, 10000); | ||
const r = await clickhouse.query(`CREATE DATABASE ${noDefaultDb}`).toPromise(); | ||
expect(r).to.be.ok(); | ||
const temp = new ClickHouse({ | ||
database: noDefaultDb | ||
}); | ||
const result3 = await temp.query('CREATE TABLE session_temp (str String) ENGINE=MergeTree PARTITION BY tuple() ORDER BY tuple()').toPromise(); | ||
expect(result3).to.be.ok(); | ||
const r2 = await temp.query(`DROP DATABASE ${noDefaultDb}`).toPromise(); | ||
expect(r2).to.be.ok(); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26969
766