clickhouse-sql-builder
Version:
A minimal, type-safe SQL builder for ClickHouse in the JavaScript ecosystem.
38 lines (37 loc) • 3.14 kB
TypeScript
declare const clickHouseParamTypes: readonly ["JSON", "Dynamic", "Object", "Polygon", "Ring", "Point", "SimpleAggregateFunction", "IntervalYear", "IntervalMonth", "IntervalWeek", "IntervalDay", "Enum", "IntervalMillisecond", "Int64", "IntervalMicrosecond", "MultiLineString", "IntervalNanosecond", "Nested", "LowCardinality", "Decimal", "AggregateFunction", "Float64", "IntervalHour", "IPv6", "Variant", "IPv4", "UUID", "Nothing", "UInt32", "DateTime", "Nullable", "Tuple", "IntervalMinute", "FixedString", "String", "DateTime64", "IntervalQuarter", "Date", "Int16", "Decimal128", "Array", "DateTime32", "Date32", "UInt256", "Int8", "Decimal64", "Int256", "Bool", "Int128", "Enum8", "UInt64", "Float32", "BFloat16", "Enum16", "MultiPolygon", "LineString", "UInt128", "UInt16", "Map", "UInt8", "Decimal256", "IntervalSecond", "Int32", "Decimal32"];
type ClickHouseParamType = typeof clickHouseParamTypes[number];
type AcceptBindingParamValue = string | number | Date;
export declare class ClickHouseQueryBuilder {
sql: string;
fromTable: string;
selectedFields: string[];
conditions: string[];
_groupBy: string;
_orderBy: string;
_withFill: string;
_limit?: number;
_params: [key: string, value: AcceptBindingParamValue, type: ClickHouseParamType][];
static select(fields: string[]): ClickHouseQueryBuilder;
from(table: string): this;
where(condition: string): this;
whereBetween(field: string, start: string, end: string): this;
andBetween(field: string, start: string, end: string): this;
and(condition: string): this;
groupBy(fields: string[]): ClickHouseQueryBuilder;
groupBy(field: string): ClickHouseQueryBuilder;
orderBy(field: string, order?: 'ASC' | 'DESC'): this;
withFill({ from, to, step }: {
from: string;
to: string;
step: string;
}): this;
limit(limit: number): this;
addParam(type: 'String', param: Record<string, AcceptBindingParamValue>): ClickHouseQueryBuilder;
addParam(type: 'DateTime64', param: Record<string, Date>): ClickHouseQueryBuilder;
queryParams(): Record<string, AcceptBindingParamValue>;
paramTypes(): Record<string, "JSON" | "Dynamic" | "Object" | "Polygon" | "Ring" | "Point" | "SimpleAggregateFunction" | "IntervalYear" | "IntervalMonth" | "IntervalWeek" | "IntervalDay" | "Enum" | "IntervalMillisecond" | "Int64" | "IntervalMicrosecond" | "MultiLineString" | "IntervalNanosecond" | "Nested" | "LowCardinality" | "Decimal" | "AggregateFunction" | "Float64" | "IntervalHour" | "IPv6" | "Variant" | "IPv4" | "UUID" | "Nothing" | "UInt32" | "DateTime" | "Nullable" | "Tuple" | "IntervalMinute" | "FixedString" | "String" | "DateTime64" | "IntervalQuarter" | "Date" | "Int16" | "Decimal128" | "Array" | "DateTime32" | "Date32" | "UInt256" | "Int8" | "Decimal64" | "Int256" | "Bool" | "Int128" | "Enum8" | "UInt64" | "Float32" | "BFloat16" | "Enum16" | "MultiPolygon" | "LineString" | "UInt128" | "UInt16" | "Map" | "UInt8" | "Decimal256" | "IntervalSecond" | "Int32" | "Decimal32">;
toSql(): string;
toString(): string;
}
declare const _default: {};
export default _default;