fix(core): update
This commit is contained in:
parent
333e9c1316
commit
7753e58036
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@pushrocks/smartclickhouse',
|
||||
version: '2.0.7',
|
||||
version: '2.0.8',
|
||||
description: 'an odm for talking to clickhouse'
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import * as plugins from './smartclickhouse.plugins.js';
|
||||
|
||||
export interface IClickhouseHttpClientOptions {
|
||||
user?: string;
|
||||
username?: string;
|
||||
password?: string;
|
||||
url: string;
|
||||
}
|
||||
@ -32,19 +32,13 @@ export class ClickhouseHttpClient {
|
||||
|
||||
public async start() {
|
||||
this.computedProperties.parsedUrl = plugins.smarturl.Smarturl.createFromUrl(this.options.url);
|
||||
this.computedProperties.parsedUrl.username = this.options.user ? this.options.user : '';
|
||||
this.computedProperties.parsedUrl.password = this.options.password ? this.options.password : '';
|
||||
console.log(this.computedProperties.parsedUrl);
|
||||
this.computedProperties.connectionUrl = this.computedProperties.parsedUrl.toString();
|
||||
}
|
||||
|
||||
public async ping() {
|
||||
const parsedUrlForPing = plugins.smarturl.Smarturl.createFromUrl(
|
||||
this.computedProperties.connectionUrl.toString()
|
||||
);
|
||||
parsedUrlForPing.username = null;
|
||||
parsedUrlForPing.password = null;
|
||||
|
||||
const ping = await this.webrequestInstance.request(parsedUrlForPing.toString(), {
|
||||
const ping = await this.webrequestInstance.request(this.computedProperties.connectionUrl.toString(), {
|
||||
method: 'GET',
|
||||
timeoutMs: 1000,
|
||||
});
|
||||
@ -54,9 +48,11 @@ export class ClickhouseHttpClient {
|
||||
public async queryPromise(queryArg: string) {
|
||||
const returnArray = [];
|
||||
const response = await this.webrequestInstance.request(`${this.computedProperties.connectionUrl}?query=${encodeURIComponent(queryArg)}`, {
|
||||
method: 'POST'
|
||||
method: 'POST',
|
||||
headers: this.getHeaders(),
|
||||
});
|
||||
// console.log('===================');
|
||||
// console.log(this.computedProperties.connectionUrl);
|
||||
// console.log(queryArg);
|
||||
// console.log((await response.clone().text()).split(/\r?\n/))
|
||||
if (response.headers.get('X-ClickHouse-Format') === 'JSONEachRow') {
|
||||
@ -78,8 +74,20 @@ export class ClickhouseHttpClient {
|
||||
const queryArg = `INSERT INTO ${databaseArg}.${tableArg} FORMAT JSONEachRow`;
|
||||
const response = await this.webrequestInstance.request(`${this.computedProperties.connectionUrl}?query=${encodeURIComponent(queryArg)}`, {
|
||||
method: 'POST',
|
||||
body: documents.map(docArg => JSON.stringify(docArg)).join('\n')
|
||||
body: documents.map(docArg => JSON.stringify(docArg)).join('\n'),
|
||||
headers: this.getHeaders()
|
||||
});
|
||||
return response;
|
||||
}
|
||||
|
||||
private getHeaders() {
|
||||
const headers: {[key: string]: string} = {}
|
||||
if (this.options.username) {
|
||||
headers['X-ClickHouse-User'] = this.options.username;
|
||||
}
|
||||
if (this.options.password) {
|
||||
headers['X-ClickHouse-Key'] = this.options.password;
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import { ClickhouseHttpClient } from './smartclickhouse.classes.httpclient.js';
|
||||
export interface IClickhouseConstructorOptions {
|
||||
url: string;
|
||||
database: string;
|
||||
user?: string;
|
||||
username?: string;
|
||||
password?: string;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user