fix(core): update
This commit is contained in:
@@ -17,7 +17,7 @@ export class ClickhouseHttpClient {
|
||||
// INSTANCE
|
||||
public options: IClickhouseHttpClientOptions;
|
||||
public webrequestInstance = new plugins.webrequest.WebRequest({
|
||||
logging: false
|
||||
logging: false,
|
||||
});
|
||||
public computedProperties: {
|
||||
connectionUrl: string;
|
||||
@@ -37,20 +37,25 @@ export class ClickhouseHttpClient {
|
||||
}
|
||||
|
||||
public async ping() {
|
||||
|
||||
const ping = await this.webrequestInstance.request(this.computedProperties.connectionUrl.toString(), {
|
||||
method: 'GET',
|
||||
timeoutMs: 1000,
|
||||
});
|
||||
const ping = await this.webrequestInstance.request(
|
||||
this.computedProperties.connectionUrl.toString(),
|
||||
{
|
||||
method: 'GET',
|
||||
timeoutMs: 1000,
|
||||
}
|
||||
);
|
||||
return ping.status === 200 ? true : false;
|
||||
}
|
||||
|
||||
public async queryPromise(queryArg: string) {
|
||||
const returnArray = [];
|
||||
const response = await this.webrequestInstance.request(`${this.computedProperties.connectionUrl}?query=${encodeURIComponent(queryArg)}`, {
|
||||
method: 'POST',
|
||||
headers: this.getHeaders(),
|
||||
});
|
||||
const response = await this.webrequestInstance.request(
|
||||
`${this.computedProperties.connectionUrl}?query=${encodeURIComponent(queryArg)}`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: this.getHeaders(),
|
||||
}
|
||||
);
|
||||
// console.log('===================');
|
||||
// console.log(this.computedProperties.connectionUrl);
|
||||
// console.log(queryArg);
|
||||
@@ -66,22 +71,24 @@ export class ClickhouseHttpClient {
|
||||
}
|
||||
} else {
|
||||
}
|
||||
return returnArray
|
||||
|
||||
return returnArray;
|
||||
}
|
||||
|
||||
public async insertPromise(databaseArg: string, tableArg: string, documents: any[]) {
|
||||
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'),
|
||||
headers: this.getHeaders()
|
||||
});
|
||||
const response = await this.webrequestInstance.request(
|
||||
`${this.computedProperties.connectionUrl}?query=${encodeURIComponent(queryArg)}`,
|
||||
{
|
||||
method: 'POST',
|
||||
body: documents.map((docArg) => JSON.stringify(docArg)).join('\n'),
|
||||
headers: this.getHeaders(),
|
||||
}
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
private getHeaders() {
|
||||
const headers: {[key: string]: string} = {}
|
||||
const headers: { [key: string]: string } = {};
|
||||
if (this.options.username) {
|
||||
headers['X-ClickHouse-User'] = this.options.username;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user