Socket
Socket
Sign inDemoInstall

@clickhouse/client

Package Overview
Dependencies
Maintainers
3
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@clickhouse/client - npm Package Compare versions

Comparing version 0.0.11 to 0.0.12

dist/utils/process.d.ts

7

dist/client.d.ts
/// <reference types="node" />
/// <reference types="node" />
import Stream from 'stream';
import type { InsertResult, QueryResult } from './connection';
import type { Logger } from './logger';

@@ -28,3 +29,3 @@ import { type DataFormat } from './data_formatter';

password?: string;
/** The name of the application using the nodejs client. Default: 'clickhouse-js'. */
/** The name of the application using the nodejs client. Default: empty. */
application?: string;

@@ -84,4 +85,4 @@ /** Database name to use. Default value: `default`. */

query(params: QueryParams): Promise<ResultSet>;
exec(params: ExecParams): Promise<Stream.Readable>;
insert<T>(params: InsertParams<T>): Promise<void>;
exec(params: ExecParams): Promise<QueryResult>;
insert<T>(params: InsertParams<T>): Promise<InsertResult>;
ping(): Promise<boolean>;

@@ -88,0 +89,0 @@ close(): Promise<void>;

@@ -45,2 +45,3 @@ "use strict";

return {
application_id: config.application,
url: createUrl((_a = config.host) !== null && _a !== void 0 ? _a : 'http://localhost:8123'),

@@ -106,11 +107,11 @@ connect_timeout: (_b = config.connect_timeout) !== null && _b !== void 0 ? _b : 10000,

const query = formatQuery(params.query, format);
const stream = await this.connection.query({
const { stream, query_id } = await this.connection.query({
query,
...this.getBaseParams(params),
});
return new result_1.ResultSet(stream, format);
return new result_1.ResultSet(stream, format, query_id);
}
exec(params) {
async exec(params) {
const query = removeTrailingSemi(params.query.trim());
return this.connection.exec({
return await this.connection.exec({
query,

@@ -123,4 +124,4 @@ ...this.getBaseParams(params),

validateInsertValues(params.values, format);
const query = `INSERT into ${params.table.trim()} FORMAT ${format}`;
await this.connection.insert({
const query = `INSERT INTO ${params.table.trim()} FORMAT ${format}`;
return await this.connection.insert({
query,

@@ -127,0 +128,0 @@ values: encodeValues(params.values, format),

@@ -6,3 +6,3 @@ /// <reference types="node" />

import type { Logger } from '../../logger';
import type { BaseParams, Connection, ConnectionParams, InsertParams } from '../connection';
import type { BaseParams, Connection, ConnectionParams, InsertParams, InsertResult, QueryResult } from '../connection';
export interface RequestParams {

@@ -26,6 +26,7 @@ method: 'GET' | 'POST';

ping(): Promise<boolean>;
query(params: BaseParams): Promise<Stream.Readable>;
exec(params: BaseParams): Promise<Stream.Readable>;
insert(params: InsertParams): Promise<void>;
query(params: BaseParams): Promise<QueryResult>;
exec(params: BaseParams): Promise<QueryResult>;
insert(params: InsertParams): Promise<InsertResult>;
close(): Promise<void>;
private generateQueryId;
private logResponse;

@@ -32,0 +33,0 @@ protected getHeaders(params: RequestParams): {

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -13,2 +36,4 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

const utils_1 = require("../../utils");
const user_agent_1 = require("../../utils/user_agent");
const uuid = __importStar(require("uuid"));
function isSuccessfulResponse(statusCode) {

@@ -82,2 +107,3 @@ return Boolean(statusCode && 200 <= statusCode && statusCode < 300);

Authorization: `Basic ${Buffer.from(`${username}:${password}`).toString('base64')}`,
'User-Agent': (0, user_agent_1.getUserAgent)(this.config.application_id),
};

@@ -190,10 +216,11 @@ }

// TODO add status code check
const response = await this.request({
const stream = await this.request({
method: 'GET',
url: (0, transform_url_1.transformUrl)({ url: this.config.url, pathname: '/ping' }),
});
response.destroy();
stream.destroy();
return true;
}
async query(params) {
const query_id = this.generateQueryId();
const clickhouse_settings = withHttpSettings(params.clickhouse_settings, this.config.compression.decompress_response);

@@ -205,4 +232,5 @@ const searchParams = (0, http_search_params_1.toSearchParams)({

session_id: params.session_id,
query_id,
});
return await this.request({
const stream = await this.request({
method: 'POST',

@@ -214,4 +242,9 @@ url: (0, transform_url_1.transformUrl)({ url: this.config.url, pathname: '/', searchParams }),

});
return {
stream,
query_id,
};
}
async exec(params) {
const query_id = this.generateQueryId();
const searchParams = (0, http_search_params_1.toSearchParams)({

@@ -222,4 +255,5 @@ database: this.config.database,

session_id: params.session_id,
query_id,
});
return await this.request({
const stream = await this.request({
method: 'POST',

@@ -230,4 +264,9 @@ url: (0, transform_url_1.transformUrl)({ url: this.config.url, pathname: '/', searchParams }),

});
return {
stream,
query_id,
};
}
async insert(params) {
const query_id = this.generateQueryId();
const searchParams = (0, http_search_params_1.toSearchParams)({

@@ -239,2 +278,3 @@ database: this.config.database,

session_id: params.session_id,
query_id,
});

@@ -248,2 +288,3 @@ await this.request({

});
return { query_id };
}

@@ -255,2 +296,7 @@ async close() {

}
// needed for insert queries as the query_id is not generated automatically
// we will use it for `exec` and `insert` methods, but not `select`
generateQueryId() {
return uuid.v4();
}
logResponse(request, params, response, startTimestamp) {

@@ -257,0 +303,0 @@ // eslint-disable-next-line @typescript-eslint/no-unused-vars

@@ -8,4 +8,5 @@ import type { ClickHouseSettings } from '../../settings';

session_id?: string;
query_id?: string;
};
export declare function toSearchParams({ database, query, query_params, clickhouse_settings, session_id, }: ToSearchParamsOptions): URLSearchParams | undefined;
export declare function toSearchParams({ database, query, query_params, clickhouse_settings, session_id, query_id, }: ToSearchParamsOptions): URLSearchParams | undefined;
export {};

@@ -7,3 +7,3 @@ "use strict";

// https://stackoverflow.com/questions/812925/what-is-the-maximum-possible-length-of-a-query-string
function toSearchParams({ database, query, query_params, clickhouse_settings, session_id, }) {
function toSearchParams({ database, query, query_params, clickhouse_settings, session_id, query_id, }) {
if (clickhouse_settings === undefined &&

@@ -37,2 +37,5 @@ query_params === undefined &&

}
if (query_id) {
params.set('query_id', query_id);
}
return params;

@@ -39,0 +42,0 @@ }

@@ -8,2 +8,3 @@ /// <reference types="node" />

url: URL;
application_id?: string;
connect_timeout: number;

@@ -40,9 +41,16 @@ request_timeout: number;

}
export interface QueryResult {
stream: Stream.Readable;
query_id: string;
}
export interface InsertResult {
query_id: string;
}
export interface Connection {
ping(): Promise<boolean>;
close(): Promise<void>;
query(params: BaseParams): Promise<Stream.Readable>;
exec(params: BaseParams): Promise<Stream.Readable>;
insert(params: InsertParams): Promise<void>;
query(params: BaseParams): Promise<QueryResult>;
exec(params: BaseParams): Promise<QueryResult>;
insert(params: InsertParams): Promise<InsertResult>;
}
export declare function createConnection(params: ConnectionParams, logger: LogWriter): Connection;
declare const supportedJSONFormats: readonly ["JSON", "JSONObjectEachRow", "JSONEachRow", "JSONStringsEachRow", "JSONCompactEachRow", "JSONCompactStringsEachRow", "JSONCompactEachRowWithNames", "JSONCompactEachRowWithNamesAndTypes", "JSONCompactStringsEachRowWithNames", "JSONCompactStringsEachRowWithNamesAndTypes"];
declare const supportedRawFormats: readonly ["CSV", "CSVWithNames", "CSVWithNamesAndTypes", "TabSeparated", "TabSeparatedRaw", "TabSeparatedWithNames", "TabSeparatedWithNamesAndTypes", "CustomSeparated", "CustomSeparatedWithNames", "CustomSeparatedWithNamesAndTypes"];
export type JSONDataFormat = typeof supportedJSONFormats[number];
export type RawDataFormat = typeof supportedRawFormats[number];
export type JSONDataFormat = (typeof supportedJSONFormats)[number];
export type RawDataFormat = (typeof supportedRawFormats)[number];
export type DataFormat = JSONDataFormat | RawDataFormat;
declare const streamableFormat: readonly ["JSONEachRow", "JSONStringsEachRow", "JSONCompactEachRow", "JSONCompactStringsEachRow", "JSONCompactEachRowWithNames", "JSONCompactEachRowWithNamesAndTypes", "JSONCompactStringsEachRowWithNames", "JSONCompactStringsEachRowWithNamesAndTypes", "CSV", "CSVWithNames", "CSVWithNamesAndTypes", "TabSeparated", "TabSeparatedRaw", "TabSeparatedWithNames", "TabSeparatedWithNamesAndTypes", "CustomSeparated", "CustomSeparatedWithNames", "CustomSeparatedWithNamesAndTypes"];
type StreamableDataFormat = typeof streamableFormat[number];
type StreamableDataFormat = (typeof streamableFormat)[number];
export declare function isSupportedRawFormat(dataFormat: DataFormat): boolean;

@@ -9,0 +9,0 @@ export declare function validateStreamFormat(format: any): format is StreamableDataFormat;

@@ -7,3 +7,4 @@ /// <reference types="node" />

private readonly format;
constructor(_stream: Stream.Readable, format: DataFormat);
readonly query_id: string;
constructor(_stream: Stream.Readable, format: DataFormat, query_id: string);
/**

@@ -10,0 +11,0 @@ * The method waits for all the rows to be fully loaded

@@ -31,3 +31,3 @@ "use strict";

class ResultSet {
constructor(_stream, format) {
constructor(_stream, format, query_id) {
Object.defineProperty(this, "_stream", {

@@ -45,2 +45,8 @@ enumerable: true,

});
Object.defineProperty(this, "query_id", {
enumerable: true,
configurable: true,
writable: true,
value: query_id
});
}

@@ -47,0 +53,0 @@ /**

@@ -23,9 +23,10 @@ "use strict";

const query = query_formatter_1.QueryFormatter.createTable(this.options, options);
return this.client.exec({
const { stream } = await this.client.exec({
query,
clickhouse_settings: options.clickhouse_settings,
});
return stream;
}
insert({ abort_signal, clickhouse_settings, values, }) {
return this.client.insert({
async insert({ abort_signal, clickhouse_settings, values, }) {
await this.client.insert({
clickhouse_settings,

@@ -32,0 +33,0 @@ abort_signal,

{
"name": "@clickhouse/client",
"version": "0.0.11",
"version": "0.0.12",
"description": "Official JS client for ClickHouse DB",

@@ -40,25 +40,25 @@ "license": "Apache-2.0",

"dependencies": {
"node-abort-controller": "^3.0.1"
"node-abort-controller": "^3.0.1",
"uuid": "^9.0.0"
},
"devDependencies": {
"@jest/reporters": "^29.3.1",
"@types/jest": "^29.2.4",
"@types/node": "^18.11.11",
"@jest/reporters": "^29.4.0",
"@types/jest": "^29.4.0",
"@types/node": "^18.11.18",
"@types/split2": "^3.2.1",
"@types/uuid": "^9.0.0",
"@typescript-eslint/eslint-plugin": "^5.46.0",
"@typescript-eslint/parser": "^5.46.0",
"eslint": "^8.29.0",
"eslint-config-prettier": "^8.5.0",
"@typescript-eslint/eslint-plugin": "^5.49.0",
"@typescript-eslint/parser": "^5.49.0",
"eslint": "^8.32.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-prettier": "^4.2.1",
"husky": "^8.0.2",
"jest": "^29.3.1",
"jest": "^29.4.0",
"lint-staged": "^13.1.0",
"prettier": "2.8.1",
"prettier": "2.8.3",
"split2": "^4.1.0",
"ts-jest": "^29.0.3",
"ts-jest": "^29.0.5",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.1.1",
"typescript": "^4.9.4",
"uuid": "^9.0.0"
"tsconfig-paths": "^4.1.2",
"typescript": "^4.9.4"
},

@@ -65,0 +65,0 @@ "lint-staged": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc