Commit 10c131bf authored by 孙傲's avatar 孙傲

增加数据库网关sdk

parent bb0b8bc6
/**
* 数据库网关服务
*/
const axios = require('axios');
class DatabaseManagementSystem {
constructor(options) {
this.options = Object.assign({
user: "default",
password: "",
timeout: 3 * 60 * 1000, // 3 min
enable_http_compression: 0,
date_time_output_format: "simple",
output_format_json_quote_64bit_integers: 1,
named_parameter_format: "jdbc"
}, options);
this.http = axios.create({
method: "POST",
baseURL: this.options.url,
params: {
enable_http_compression: this.options.enable_http_compression,
date_time_output_format: this.options.date_time_output_format,
output_format_json_quote_64bit_integers: this.options.output_format_json_quote_64bit_integers,
named_parameter_format: this.options.named_parameter_format
},
headers: {
"Accept-Encoding": "gzip",
"X-ClickHouse-User": this.options.user,
"X-ClickHouse-Key": this.options.password,
"X-ClickHouse-Format": "JSON"
},
responseType: "JSON",
responseEncoding: "utf8",
timeout: this.options.timeout
});
}
async query(database, query, queryParameters) {
let { data: { data } } = await this.http({
url: "",
params: {
database: database,
params: queryParameters ? JSON.stringify(queryParameters) : null
},
data: query
});
return data;
}
async predefinedQuery(database, query, queryParameters) {
let { data: { data } } = await this.http({
url: query,
params: {
database: database,
params: queryParameters ? JSON.stringify(queryParameters) : null
}
});
return data;
}
}
module.exports = {
DatabaseManagementSystem
}
\ No newline at end of file
{
"name": "nodejs-yitong-sdk",
"version": "1.0.3",
"version": "1.0.4",
"description": "",
"main": "index.js",
"scripts": {
......@@ -16,4 +16,4 @@
"log4js": "^6.1.2",
"opentracing": "^0.14.4"
}
}
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment