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.5 to 0.0.6

11

dist/clickhouse_types.d.ts

@@ -1,2 +0,1 @@

export declare type DataType = 'UInt8' | 'UInt16' | 'UInt32' | 'UInt64' | 'UInt128' | 'UInt256' | 'Int8' | 'Int16' | 'Int32' | 'Int64' | 'Int128' | 'Int256' | 'Float32' | 'Float64';
export interface ResponseJSON<T = unknown> {

@@ -9,3 +8,3 @@ data: Array<T>;

name: string;
type: DataType;
type: string;
}>;

@@ -19,1 +18,9 @@ statistics?: {

}
export interface InputJSON<T = unknown> {
meta: {
name: string;
type: string;
}[];
data: T[];
}
export declare type InputJSONObjectEachRow<T = unknown> = Record<string, T>;

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

import type { ClickHouseSettings } from './settings';
import type { InputJSON, InputJSONObjectEachRow } from './clickhouse_types';
export interface ClickHouseClientConfigOptions {
/** A ClickHouse instance URL. Default value: `http://localhost:8123`. */
host?: string;
/** The timeout to setup a connection in milliseconds. Default value: `10_000`. */
/** The timeout to set up a connection in milliseconds. Default value: `10_000`. */
connect_timeout?: number;

@@ -58,2 +59,3 @@ /** The request timeout in milliseconds. Default value: `30_000`. */

}
declare type InsertValues<T> = ReadonlyArray<T> | Stream.Readable | InputJSON<T> | InputJSONObjectEachRow<T>;
export interface InsertParams<T = unknown> extends BaseParams {

@@ -63,3 +65,3 @@ /** Name of a table to insert into. */

/** A dataset to insert. */
values: ReadonlyArray<T> | Stream.Readable;
values: InsertValues<T>;
/** Format of the dataset to insert. */

@@ -80,3 +82,14 @@ format?: DataFormat;

}
export declare function validateInsertValues(values: ReadonlyArray<any> | Stream.Readable, format: DataFormat): void;
export declare function validateInsertValues<T>(values: InsertValues<T>, format: DataFormat): void;
/**
* A function encodes an array or a stream of JSON objects to a format compatible with ClickHouse.
* If values are provided as an array of JSON objects, the function encodes it in place.
* If values are provided as a stream of JSON objects, the function sets up the encoding of each chunk.
* If values are provided as a raw non-object stream, the function does nothing.
*
* @param values a set of values to send to ClickHouse.
* @param format a format to encode value to.
*/
export declare function encodeValues<T>(values: InsertValues<T>, format: DataFormat): string | Stream.Readable;
export declare function createClient(config?: ClickHouseClientConfigOptions): ClickHouseClient;
export {};

19

dist/client.js

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.createClient = exports.validateInsertValues = exports.ClickHouseClient = void 0;
exports.createClient = exports.encodeValues = exports.validateInsertValues = exports.ClickHouseClient = void 0;
const stream_1 = __importDefault(require("stream"));

@@ -136,4 +136,7 @@ const connection_1 = require("./connection");

function validateInsertValues(values, format) {
if (Array.isArray(values) === false && (0, utils_1.isStream)(values) === false) {
throw new Error('Insert expected "values" to be an array or a stream of values.');
if (!Array.isArray(values) &&
!(0, utils_1.isStream)(values) &&
typeof values !== 'object') {
throw new Error('Insert expected "values" to be an array, a stream of values or a JSON object, ' +
`got: ${typeof values}`);
}

@@ -171,4 +174,12 @@ if ((0, utils_1.isStream)(values)) {

// JSON* arrays
return values.map((value) => (0, data_formatter_1.encodeJSON)(value, format)).join('');
if (Array.isArray(values)) {
return values.map((value) => (0, data_formatter_1.encodeJSON)(value, format)).join('');
}
// JSON & JSONObjectEachRow format input
if (typeof values === 'object') {
return (0, data_formatter_1.encodeJSON)(values, format);
}
throw new Error(`Cannot encode values of type ${typeof values} with ${format} format`);
}
exports.encodeValues = encodeValues;
function createClient(config) {

@@ -175,0 +186,0 @@ return new ClickHouseClient(config);

@@ -1,2 +0,2 @@

declare const supportedJSONFormats: readonly ["JSON", "JSONEachRow", "JSONStringsEachRow", "JSONCompactEachRow", "JSONCompactStringsEachRow", "JSONCompactEachRowWithNames", "JSONCompactEachRowWithNamesAndTypes", "JSONCompactStringsEachRowWithNames", "JSONCompactStringsEachRowWithNamesAndTypes"];
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"];

@@ -3,0 +3,0 @@ export declare type JSONDataFormat = typeof supportedJSONFormats[number];

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

];
const supportedJSONFormats = ['JSON', ...streamableJSONFormats];
const supportedJSONFormats = [
'JSON',
'JSONObjectEachRow',
...streamableJSONFormats,
];
const supportedRawFormats = [

@@ -64,3 +68,3 @@ 'CSV',

if (isSupportedRawFormat(format)) {
throw new Error(`cannot decode ${format} to JSON`);
throw new Error(`Cannot decode ${format} to JSON`);
}

@@ -77,3 +81,3 @@ throw new Error(`The client does not support [${format}] format decoding.`);

function encodeJSON(value, format) {
if (streamableJSONFormats.includes(format)) {
if (supportedJSONFormats.includes(format)) {
return JSON.stringify(value) + '\n';

@@ -80,0 +84,0 @@ }

@@ -13,4 +13,4 @@ import { createClient } from './client';

export type { Logger } from './logger';
export type { ResponseJSON, DataType } from './clickhouse_types';
export type { ResponseJSON, InputJSON, InputJSONObjectEachRow, } from './clickhouse_types';
export type { ClickHouseSettings } from './settings';
export { SettingsMap } from './settings';
{
"name": "@clickhouse/client",
"version": "0.0.5",
"version": "0.0.6",
"description": "Official JS client for ClickHouse DB",

@@ -5,0 +5,0 @@ "license": "Apache-2.0",

@@ -153,23 +153,24 @@ <p align="center">

| Format | Input (array) | Input (stream) | Output (JSON) | Output (text) |
| ------------------------------------------ | ------------- | -------------- | ------------- | ------------- |
| JSON | ❌ | ❌ | ✔️ | ✔️ |
| JSONEachRow | ✔️ | ✔️ | ✔️ | ✔️ |
| JSONStringsEachRow | ✔️ | ✔️ | ✔️ | ✔️ |
| JSONCompactEachRow | ✔️ | ✔️ | ✔️ | ✔️ |
| JSONCompactStringsEachRow | ✔️ | ✔️ | ✔️ | ✔️ |
| JSONCompactEachRowWithNames | ✔️ | ✔️ | ✔️ | ✔️ |
| JSONCompactEachRowWithNamesAndTypes | ✔️ | ✔️ | ✔️ | ✔️ |
| JSONCompactStringsEachRowWithNames | ✔️ | ✔️ | ✔️ | ✔️ |
| JSONCompactStringsEachRowWithNamesAndTypes | ✔️ | ✔️ | ✔️ | ✔️ |
| CSV | ❌ | ✔️ | ❌ | ✔️ |
| CSVWithNames | ❌ | ✔️ | ❌ | ✔️ |
| CSVWithNamesAndTypes | ❌ | ✔️ | ❌ | ✔️ |
| TabSeparated | ❌ | ✔️ | ❌ | ✔️ |
| TabSeparatedRaw | ❌ | ✔️ | ❌ | ✔️ |
| TabSeparatedWithNames | ❌ | ✔️ | ❌ | ✔️ |
| TabSeparatedWithNamesAndTypes | ❌ | ✔️ | ❌ | ✔️ |
| CustomSeparated | ❌ | ✔️ | ❌ | ✔️ |
| CustomSeparatedWithNames | ❌ | ✔️ | ❌ | ✔️ |
| CustomSeparatedWithNamesAndTypes | ❌ | ✔️ | ❌ | ✔️ |
| Format | Input (array) | Input (stream) | Input (object) | Output (JSON) | Output (text) |
| ------------------------------------------ | ------------- | -------------- | -------------- | ------------- | ------------- |
| JSON | ❌ | ❌ | ✔️ | ✔️ | ✔️ |
| JSONObjectEachRow | ❌ | ❌ | ✔️ | ✔️ | ✔️ |
| JSONEachRow | ✔️ | ✔️ | ❌️ | ✔️ | ✔️ |
| JSONStringsEachRow | ✔️ | ✔️ | ❌️ | ✔️ | ✔️ |
| JSONCompactEachRow | ✔️ | ✔️ | ❌️ | ✔️ | ✔️ |
| JSONCompactStringsEachRow | ✔️ | ✔️ | ❌️ | ✔️ | ✔️ |
| JSONCompactEachRowWithNames | ✔️ | ✔️ | ❌️ | ✔️ | ✔️ |
| JSONCompactEachRowWithNamesAndTypes | ✔️ | ✔️ | ❌️ | ✔️ | ✔️ |
| JSONCompactStringsEachRowWithNames | ✔️ | ✔️ | ❌️ | ✔️ | ✔️ |
| JSONCompactStringsEachRowWithNamesAndTypes | ✔️ | ✔️ | ❌️ | ✔️ | ✔️ |
| CSV | ❌ | ✔️ | ❌ | ❌ | ✔️ |
| CSVWithNames | ❌ | ✔️ | ❌ | ❌ | ✔️ |
| CSVWithNamesAndTypes | ❌ | ✔️ | ❌ | ❌ | ✔️ |
| TabSeparated | ❌ | ✔️ | ❌ | ❌ | ✔️ |
| TabSeparatedRaw | ❌ | ✔️ | ❌ | ❌ | ✔️ |
| TabSeparatedWithNames | ❌ | ✔️ | ❌ | ❌ | ✔️ |
| TabSeparatedWithNamesAndTypes | ❌ | ✔️ | ❌ | ❌ | ✔️ |
| CustomSeparated | ❌ | ✔️ | ❌ | ❌ | ✔️ |
| CustomSeparatedWithNames | ❌ | ✔️ | ❌ | ❌ | ✔️ |
| CustomSeparatedWithNamesAndTypes | ❌ | ✔️ | ❌ | ❌ | ✔️ |

@@ -176,0 +177,0 @@ The entire list of ClickHouse input and output formats is available [here](https://clickhouse.com/docs/en/interfaces/formats).

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