@housekit/orm 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +224 -0
- package/dist/builders/delete.d.ts +21 -0
- package/dist/builders/insert.d.ts +128 -0
- package/dist/builders/prepared.d.ts +11 -0
- package/dist/builders/select.d.ts +352 -0
- package/dist/builders/select.types.d.ts +76 -0
- package/dist/builders/update.d.ts +23 -0
- package/dist/client.d.ts +52 -0
- package/dist/codegen/zod.d.ts +4 -0
- package/dist/column.d.ts +76 -0
- package/dist/compiler.d.ts +27 -0
- package/dist/core.d.ts +6 -0
- package/dist/data-types.d.ts +150 -0
- package/dist/dictionary.d.ts +263 -0
- package/dist/engines.d.ts +558 -0
- package/dist/expressions.d.ts +72 -0
- package/dist/external.d.ts +177 -0
- package/dist/index.d.ts +187 -0
- package/dist/index.js +222 -0
- package/dist/logger.d.ts +8 -0
- package/dist/materialized-views.d.ts +271 -0
- package/dist/metadata.d.ts +33 -0
- package/dist/modules/aggregates.d.ts +205 -0
- package/dist/modules/array.d.ts +122 -0
- package/dist/modules/conditional.d.ts +110 -0
- package/dist/modules/conversion.d.ts +189 -0
- package/dist/modules/geo.d.ts +202 -0
- package/dist/modules/hash.d.ts +7 -0
- package/dist/modules/index.d.ts +12 -0
- package/dist/modules/json.d.ts +130 -0
- package/dist/modules/math.d.ts +28 -0
- package/dist/modules/string.d.ts +167 -0
- package/dist/modules/time.d.ts +154 -0
- package/dist/modules/types.d.ts +177 -0
- package/dist/modules/window.d.ts +27 -0
- package/dist/relational.d.ts +33 -0
- package/dist/relations.d.ts +15 -0
- package/dist/schema-builder.d.ts +172 -0
- package/dist/table.d.ts +172 -0
- package/dist/utils/background-batcher.d.ts +20 -0
- package/dist/utils/batch-transform.d.ts +20 -0
- package/dist/utils/binary-reader.d.ts +48 -0
- package/dist/utils/binary-serializer.d.ts +160 -0
- package/dist/utils/binary-worker-code.d.ts +1 -0
- package/dist/utils/binary-worker-pool.d.ts +76 -0
- package/dist/utils/binary-worker.d.ts +12 -0
- package/dist/utils/insert-processing.d.ts +23 -0
- package/dist/utils/lru-cache.d.ts +10 -0
- package/package.json +68 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HouseKit External Data Sources - Type-Safe External Table Functions
|
|
3
|
+
*
|
|
4
|
+
* ClickHouse can query external data sources directly in SQL.
|
|
5
|
+
* These helpers create virtual table references that can be used in JOINs.
|
|
6
|
+
*
|
|
7
|
+
* Standard ORMs often lack support for this - HouseKit's Data Gravity approach
|
|
8
|
+
* moves computation to ClickHouse instead of downloading data to Node.js.
|
|
9
|
+
*/
|
|
10
|
+
import { type TableColumns, type TableOptions } from './table';
|
|
11
|
+
/**
|
|
12
|
+
* External table that can be used in FROM/JOIN clauses
|
|
13
|
+
*/
|
|
14
|
+
export interface ExternalTableDefinition<TCols extends TableColumns = TableColumns> {
|
|
15
|
+
$table: string;
|
|
16
|
+
$columns: TCols;
|
|
17
|
+
$options: TableOptions & {
|
|
18
|
+
externallyManaged: true;
|
|
19
|
+
kind: 'external';
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* External tables don't have CREATE statements
|
|
23
|
+
*/
|
|
24
|
+
toSQL(): string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* S3 file format options
|
|
28
|
+
*/
|
|
29
|
+
export type S3Format = 'CSV' | 'CSVWithNames' | 'TSV' | 'TabSeparated' | 'TabSeparatedWithNames' | 'JSONEachRow' | 'JSON' | 'JSONCompact' | 'Parquet' | 'ORC' | 'Arrow' | 'Avro' | 'Native';
|
|
30
|
+
/**
|
|
31
|
+
* S3 compression options
|
|
32
|
+
*/
|
|
33
|
+
export type S3Compression = 'none' | 'gzip' | 'br' | 'xz' | 'zstd' | 'lz4' | 'bz2';
|
|
34
|
+
/**
|
|
35
|
+
* S3 access configuration for external table functions
|
|
36
|
+
*/
|
|
37
|
+
export interface ExternalS3Config {
|
|
38
|
+
/** S3 bucket URL with path pattern (supports wildcards) */
|
|
39
|
+
url: string;
|
|
40
|
+
/** AWS access key (optional if using IAM roles) */
|
|
41
|
+
accessKeyId?: string;
|
|
42
|
+
/** AWS secret key (optional if using IAM roles) */
|
|
43
|
+
secretAccessKey?: string;
|
|
44
|
+
/** File format */
|
|
45
|
+
format?: S3Format;
|
|
46
|
+
/** Structure definition for the file (e.g., 'id UInt32, name String') */
|
|
47
|
+
structure?: string;
|
|
48
|
+
/** Compression type */
|
|
49
|
+
compression?: S3Compression;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* URL source configuration (for HTTP endpoints)
|
|
53
|
+
*/
|
|
54
|
+
export interface ExternalURLConfig {
|
|
55
|
+
/** URL to fetch data from */
|
|
56
|
+
url: string;
|
|
57
|
+
/** File format */
|
|
58
|
+
format: S3Format;
|
|
59
|
+
/** Structure definition */
|
|
60
|
+
structure?: string;
|
|
61
|
+
/** HTTP headers */
|
|
62
|
+
headers?: Record<string, string>;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* File source configuration (for local/mounted files)
|
|
66
|
+
*/
|
|
67
|
+
export interface ExternalFileConfig {
|
|
68
|
+
/** File path pattern (supports wildcards) */
|
|
69
|
+
path: string;
|
|
70
|
+
/** File format */
|
|
71
|
+
format: S3Format;
|
|
72
|
+
/** Structure definition */
|
|
73
|
+
structure?: string;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* HDFS configuration
|
|
77
|
+
*/
|
|
78
|
+
export interface HDFSConfig {
|
|
79
|
+
/** HDFS URL */
|
|
80
|
+
url: string;
|
|
81
|
+
/** File format */
|
|
82
|
+
format: S3Format;
|
|
83
|
+
/** Structure definition */
|
|
84
|
+
structure?: string;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* MySQL external table configuration
|
|
88
|
+
*/
|
|
89
|
+
export interface MySQLExternalConfig {
|
|
90
|
+
host: string;
|
|
91
|
+
port?: number;
|
|
92
|
+
database: string;
|
|
93
|
+
table: string;
|
|
94
|
+
user: string;
|
|
95
|
+
password: string;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* PostgreSQL external table configuration
|
|
99
|
+
*/
|
|
100
|
+
export interface PostgreSQLExternalConfig {
|
|
101
|
+
host: string;
|
|
102
|
+
port?: number;
|
|
103
|
+
database: string;
|
|
104
|
+
table: string | {
|
|
105
|
+
schema: string;
|
|
106
|
+
table: string;
|
|
107
|
+
};
|
|
108
|
+
user: string;
|
|
109
|
+
password: string;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Create an S3 external table reference for use in queries.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* import { s3, eq, sql } from '@housekit/orm';
|
|
117
|
+
*
|
|
118
|
+
* // Define external S3 data
|
|
119
|
+
* const externalUsers = s3({
|
|
120
|
+
* url: 's3://my-bucket/users/*.parquet',
|
|
121
|
+
* format: 'Parquet',
|
|
122
|
+
* });
|
|
123
|
+
*
|
|
124
|
+
* // Use in a JOIN - ClickHouse reads S3 directly!
|
|
125
|
+
* const query = db.select({
|
|
126
|
+
* eventType: events.event_type,
|
|
127
|
+
* userName: sql`externalUsers.name`,
|
|
128
|
+
* })
|
|
129
|
+
* .from(events)
|
|
130
|
+
* .innerJoin(externalUsers, eq(events.user_id, sql`externalUsers.id`));
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
export declare function s3<TCols extends TableColumns = {}>(config: ExternalS3Config, columns?: TCols): ExternalTableDefinition<TCols> & TCols;
|
|
134
|
+
/**
|
|
135
|
+
* Create an S3 Cluster external table (for distributed reading)
|
|
136
|
+
*/
|
|
137
|
+
export declare function s3Cluster<TCols extends TableColumns = {}>(clusterName: string, config: ExternalS3Config, columns?: TCols): ExternalTableDefinition<TCols> & TCols;
|
|
138
|
+
/**
|
|
139
|
+
* Create a URL external table reference.
|
|
140
|
+
*/
|
|
141
|
+
export declare function url<TCols extends TableColumns = {}>(config: ExternalURLConfig, columns?: TCols): ExternalTableDefinition<TCols> & TCols;
|
|
142
|
+
/**
|
|
143
|
+
* Create a File external table reference.
|
|
144
|
+
*/
|
|
145
|
+
export declare function file<TCols extends TableColumns = {}>(config: ExternalFileConfig, columns?: TCols): ExternalTableDefinition<TCols> & TCols;
|
|
146
|
+
/**
|
|
147
|
+
* Create an HDFS external table reference.
|
|
148
|
+
*/
|
|
149
|
+
export declare function hdfs<TCols extends TableColumns = {}>(config: HDFSConfig, columns?: TCols): ExternalTableDefinition<TCols> & TCols;
|
|
150
|
+
/**
|
|
151
|
+
* Create a MySQL external table reference.
|
|
152
|
+
*
|
|
153
|
+
* @warning **SECURITY WARNING**: This includes the password in plain text in the generated SQL.
|
|
154
|
+
* The password will be stored in plain text in ClickHouse's `system.query_log` unless you have
|
|
155
|
+
* configured query masking on the server. Ensure you use a read-only user with minimal permissions.
|
|
156
|
+
*/
|
|
157
|
+
export declare function mysql<TCols extends TableColumns = {}>(config: MySQLExternalConfig, columns?: TCols): ExternalTableDefinition<TCols> & TCols;
|
|
158
|
+
/**
|
|
159
|
+
* Create a PostgreSQL external table reference.
|
|
160
|
+
*
|
|
161
|
+
* @warning **SECURITY WARNING**: This includes the password in plain text in the generated SQL.
|
|
162
|
+
* The password will be stored in plain text in ClickHouse's `system.query_log` unless you have
|
|
163
|
+
* configured query masking on the server. Ensure you use a read-only user with minimal permissions.
|
|
164
|
+
*/
|
|
165
|
+
export declare function postgresql<TCols extends TableColumns = {}>(config: PostgreSQLExternalConfig, columns?: TCols): ExternalTableDefinition<TCols> & TCols;
|
|
166
|
+
/**
|
|
167
|
+
* Create an inline VALUES table (useful for small lookup tables in queries)
|
|
168
|
+
*/
|
|
169
|
+
export declare function values<T extends Record<string, any>>(data: T[], structure: string): ExternalTableDefinition;
|
|
170
|
+
/**
|
|
171
|
+
* Create a Numbers table function (generates sequence of numbers)
|
|
172
|
+
*/
|
|
173
|
+
export declare function numbers(count: number, offset?: number): ExternalTableDefinition;
|
|
174
|
+
/**
|
|
175
|
+
* Create a generateRandom table function
|
|
176
|
+
*/
|
|
177
|
+
export declare function generateRandom(structure: string, randomSeed?: number, maxStringLength?: number, maxArrayLength?: number): ExternalTableDefinition;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { type TableDefinition, type TableColumns } from './core';
|
|
2
|
+
import { createClientFromConfigObject, type ClientConfigWithSchema } from './client';
|
|
3
|
+
export { ClickHouseColumn } from './column';
|
|
4
|
+
export { type TableDefinition, type TableColumns, type TableOptions, type IndexDefinition, type ProjectionDefinition, index, projection, deriveTable, renderSchema } from './table';
|
|
5
|
+
export { Engine, type EngineConfiguration } from './engines';
|
|
6
|
+
export * from './external';
|
|
7
|
+
export * from './expressions';
|
|
8
|
+
export * from './builders/select';
|
|
9
|
+
export * from './builders/select.types';
|
|
10
|
+
export * from './builders/insert';
|
|
11
|
+
export * from './builders/delete';
|
|
12
|
+
export * from './builders/update';
|
|
13
|
+
export * from './metadata';
|
|
14
|
+
export * from './compiler';
|
|
15
|
+
export * from './modules';
|
|
16
|
+
export * from './relational';
|
|
17
|
+
export * from './logger';
|
|
18
|
+
export * from './client';
|
|
19
|
+
export { t, defineTable, table, view, defineView, materializedView, defineMaterializedView, dictionary, defineDictionary, defineProjection, detectMaterializedViewDrift, extractMVQuery, createMigrationBridge, generateBlueGreenMigration, relations, type ColumnBuilder, type EnhancedTableOptions } from './schema-builder';
|
|
20
|
+
export { sql } from './expressions';
|
|
21
|
+
export { generateSelectSchema, generateInsertSchema } from './codegen/zod';
|
|
22
|
+
export { BinaryWriter, createBinaryEncoder, serializeRowBinary, serializeRowsBinary, buildBinaryConfig, type BinaryEncoder, type BinarySerializationConfig, } from './utils/binary-serializer';
|
|
23
|
+
export { SyncBinarySerializer, BinaryWorkerPool, type BinaryWorkerPoolOptions, } from './utils/binary-worker-pool';
|
|
24
|
+
/**
|
|
25
|
+
* Load housekit.config.js/ts and create a client by name.
|
|
26
|
+
*/
|
|
27
|
+
export declare function createClientFromConfig(databaseName?: string): Promise<HousekitClient>;
|
|
28
|
+
export type HousekitClient = ReturnType<typeof createClientFromConfigObject>;
|
|
29
|
+
export declare function createClient(): Promise<HousekitClient>;
|
|
30
|
+
export declare function createClient(config: ClientConfigWithSchema): HousekitClient;
|
|
31
|
+
export declare function createClient(databaseName: string): Promise<HousekitClient>;
|
|
32
|
+
export declare function tableExists(client: HousekitClient, tableName: string): Promise<boolean>;
|
|
33
|
+
export declare function ensureTable<TCols extends TableColumns>(client: HousekitClient, table: TableDefinition<TCols>): Promise<void>;
|
|
34
|
+
export declare function dropTable(client: HousekitClient, tableName: string, options?: {
|
|
35
|
+
ifExists?: boolean;
|
|
36
|
+
}): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Create multiple ClickHouse clients for multi-database setups
|
|
39
|
+
* @example
|
|
40
|
+
* const clients = createClients({
|
|
41
|
+
* analytics: { url: 'http://localhost:8123', database: 'analytics' },
|
|
42
|
+
* logs: { url: 'http://localhost:8123', database: 'logs' }
|
|
43
|
+
* });
|
|
44
|
+
*
|
|
45
|
+
* await clients.analytics.select().from(events);
|
|
46
|
+
* await clients.logs.insert(logTable).values({...});
|
|
47
|
+
*/
|
|
48
|
+
export declare function createClients<T extends Record<string, ClientConfigWithSchema>>(configs: T): Record<keyof T, HousekitClient>;
|
|
49
|
+
/**
|
|
50
|
+
* Close all clients in a multi-database setup
|
|
51
|
+
*/
|
|
52
|
+
export declare function closeAllClients(clients: Record<string, HousekitClient>): Promise<void>;
|
|
53
|
+
import { defineTable, defineProjection, detectMaterializedViewDrift, extractMVQuery, createMigrationBridge, generateBlueGreenMigration, relations } from './schema-builder';
|
|
54
|
+
import { sql } from './expressions';
|
|
55
|
+
import { deriveTable } from './table';
|
|
56
|
+
import { generateSelectSchema, generateInsertSchema } from './codegen/zod';
|
|
57
|
+
/**
|
|
58
|
+
* Optional default export for users who prefer this style.
|
|
59
|
+
* Named exports are recommended for better tree-shaking.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* // Named exports (recommended)
|
|
64
|
+
* import { table, t, Engine } from '@housekit/orm';
|
|
65
|
+
*
|
|
66
|
+
* // Default export (alternative)
|
|
67
|
+
* import housekit from '@housekit/orm';
|
|
68
|
+
* const users = housekit.table('users', { ... });
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
declare const _default: {
|
|
72
|
+
t: {
|
|
73
|
+
int8: (name: string) => import("./column").ClickHouseColumn<number, true, false>;
|
|
74
|
+
int16: (name: string) => import("./column").ClickHouseColumn<number, true, false>;
|
|
75
|
+
integer: (name: string) => import("./column").ClickHouseColumn<number, true, false>;
|
|
76
|
+
int32: (name: string) => import("./column").ClickHouseColumn<number, true, false>;
|
|
77
|
+
int64: (name: string) => import("./column").ClickHouseColumn<number, true, false>;
|
|
78
|
+
int128: (name: string) => import("./column").ClickHouseColumn<number, true, false>;
|
|
79
|
+
int256: (name: string) => import("./column").ClickHouseColumn<number, true, false>;
|
|
80
|
+
uint8: (name: string) => import("./column").ClickHouseColumn<number, true, false>;
|
|
81
|
+
uint16: (name: string) => import("./column").ClickHouseColumn<number, true, false>;
|
|
82
|
+
uint32: (name: string) => import("./column").ClickHouseColumn<number, true, false>;
|
|
83
|
+
uint64: (name: string) => import("./column").ClickHouseColumn<number, true, false>;
|
|
84
|
+
uint128: (name: string) => import("./column").ClickHouseColumn<number, true, false>;
|
|
85
|
+
uint256: (name: string) => import("./column").ClickHouseColumn<number, true, false>;
|
|
86
|
+
float32: (name: string) => import("./column").ClickHouseColumn<number, true, false>;
|
|
87
|
+
float: (name: string) => import("./column").ClickHouseColumn<number, true, false>;
|
|
88
|
+
float64: (name: string) => import("./column").ClickHouseColumn<number, true, false>;
|
|
89
|
+
bfloat16: (name: string) => import("./column").ClickHouseColumn<number, true, false>;
|
|
90
|
+
decimal: (name: string, precision?: number, scale?: number) => import("./column").ClickHouseColumn<number, true, false>;
|
|
91
|
+
decimal32: (name: string, scale?: number) => import("./column").ClickHouseColumn<number, true, false>;
|
|
92
|
+
decimal64: (name: string, scale?: number) => import("./column").ClickHouseColumn<number, true, false>;
|
|
93
|
+
decimal128: (name: string, scale?: number) => import("./column").ClickHouseColumn<number, true, false>;
|
|
94
|
+
decimal256: (name: string, scale?: number) => import("./column").ClickHouseColumn<number, true, false>;
|
|
95
|
+
text: (name: string) => import("./column").ClickHouseColumn<string, true, false>;
|
|
96
|
+
string: (name: string) => import("./column").ClickHouseColumn<string, true, false>;
|
|
97
|
+
fixedString: (name: string, length: number) => import("./column").ClickHouseColumn<string, true, false>;
|
|
98
|
+
varchar: (name: string, opts?: {
|
|
99
|
+
length?: number;
|
|
100
|
+
}) => import("./column").ClickHouseColumn<string, true, false>;
|
|
101
|
+
date: (name: string) => import("./column").ClickHouseColumn<string | Date, true, false>;
|
|
102
|
+
date32: (name: string) => import("./column").ClickHouseColumn<string | Date, true, false>;
|
|
103
|
+
timestamp: (name: string, timezone?: string) => import("./column").ClickHouseColumn<string | Date, true, false>;
|
|
104
|
+
datetime: (name: string, timezone?: string) => import("./column").ClickHouseColumn<string | Date, true, false>;
|
|
105
|
+
datetime64: (name: string, precision?: number, timezone?: string) => import("./column").ClickHouseColumn<string | Date, true, false>;
|
|
106
|
+
boolean: (name: string) => import("./column").ClickHouseColumn<boolean, true, false>;
|
|
107
|
+
bool: (name: string) => import("./column").ClickHouseColumn<boolean, true, false>;
|
|
108
|
+
uuid: (name: string) => import("./column").ClickHouseColumn<string, true, false>;
|
|
109
|
+
ipv4: (name: string) => import("./column").ClickHouseColumn<string, true, false>;
|
|
110
|
+
ipv6: (name: string) => import("./column").ClickHouseColumn<string, true, false>;
|
|
111
|
+
array: <T>(col: import("./column").ClickHouseColumn<T>) => import("./column").ClickHouseColumn<T[], true, false>;
|
|
112
|
+
tuple: (name: string, types: string[]) => import("./column").ClickHouseColumn<any, true, false>;
|
|
113
|
+
map: (name: string, keyType?: string, valueType?: string) => import("./column").ClickHouseColumn<Record<string, any>, true, false>;
|
|
114
|
+
nested: (name: string, fields: Record<string, string>) => import("./column").ClickHouseColumn<any, true, false>;
|
|
115
|
+
json: <TSchema = Record<string, any>>(name: string) => import("./column").ClickHouseColumn<TSchema, false, false>;
|
|
116
|
+
dynamic: (name: string, maxTypes?: number) => import("./column").ClickHouseColumn<any, true, false>;
|
|
117
|
+
lowCardinality: <T, TNotNull extends boolean, TAutoGenerated extends boolean>(col: import("./column").ClickHouseColumn<T, TNotNull, TAutoGenerated>) => import("./column").ClickHouseColumn<T, TNotNull, TAutoGenerated>;
|
|
118
|
+
aggregateFunction: (name: string, funcName: string, ...argTypes: string[]) => import("./column").ClickHouseColumn<any, true, false>;
|
|
119
|
+
simpleAggregateFunction: (name: string, funcName: string, argType: string) => import("./column").ClickHouseColumn<any, true, false>;
|
|
120
|
+
point: (name: string) => import("./column").ClickHouseColumn<[number, number], true, false>;
|
|
121
|
+
ring: (name: string) => import("./column").ClickHouseColumn<[number, number][], true, false>;
|
|
122
|
+
polygon: (name: string) => import("./column").ClickHouseColumn<[number, number][][], true, false>;
|
|
123
|
+
multiPolygon: (name: string) => import("./column").ClickHouseColumn<[number, number][][][], true, false>;
|
|
124
|
+
enum: (name: string, values: readonly string[]) => import("./column").ClickHouseColumn<string, false, false>;
|
|
125
|
+
};
|
|
126
|
+
table: typeof defineTable;
|
|
127
|
+
defineTable: typeof defineTable;
|
|
128
|
+
view: typeof import("./table").chView;
|
|
129
|
+
defineView: typeof import("./table").chView;
|
|
130
|
+
materializedView: typeof import("./materialized-views").chMaterializedView;
|
|
131
|
+
defineMaterializedView: typeof import("./materialized-views").chMaterializedView;
|
|
132
|
+
dictionary: typeof import("./dictionary").chDictionary;
|
|
133
|
+
defineDictionary: typeof import("./dictionary").chDictionary;
|
|
134
|
+
defineProjection: typeof defineProjection;
|
|
135
|
+
relations: typeof relations;
|
|
136
|
+
createClient: typeof createClient;
|
|
137
|
+
createClients: typeof createClients;
|
|
138
|
+
closeAllClients: typeof closeAllClients;
|
|
139
|
+
Engine: {
|
|
140
|
+
MergeTree: (options?: Omit<import("./engines").MergeTreeConfig, "type">) => import("./engines").MergeTreeConfig;
|
|
141
|
+
ReplacingMergeTree: (versionColumn?: string, isDeletedColumn?: string, options?: Omit<import("./engines").ReplacingMergeTreeConfig, "type" | "versionColumn" | "isDeletedColumn">) => import("./engines").ReplacingMergeTreeConfig;
|
|
142
|
+
SummingMergeTree: (columns?: string[], options?: Omit<import("./engines").SummingMergeTreeConfig, "type" | "columns">) => import("./engines").SummingMergeTreeConfig;
|
|
143
|
+
AggregatingMergeTree: (options?: Omit<import("./engines").AggregatingMergeTreeConfig, "type">) => import("./engines").AggregatingMergeTreeConfig;
|
|
144
|
+
CollapsingMergeTree: (signColumn: string, options?: Omit<import("./engines").CollapsingMergeTreeConfig, "type" | "signColumn">) => import("./engines").CollapsingMergeTreeConfig;
|
|
145
|
+
VersionedCollapsingMergeTree: (signColumn: string, versionColumn: string, options?: Omit<import("./engines").VersionedCollapsingMergeTreeConfig, "type" | "signColumn" | "versionColumn">) => import("./engines").VersionedCollapsingMergeTreeConfig;
|
|
146
|
+
GraphiteMergeTree: (configSection: string, options?: Omit<import("./engines").GraphiteMergeTreeConfig, "type" | "configSection">) => import("./engines").GraphiteMergeTreeConfig;
|
|
147
|
+
ReplicatedMergeTree: (config?: Omit<import("./engines").ReplicatedMergeTreeConfig, "type">) => import("./engines").ReplicatedMergeTreeConfig;
|
|
148
|
+
Buffer: <T extends TableColumns>(targetTable: TableDefinition<T>, opts: {
|
|
149
|
+
minRows: number;
|
|
150
|
+
maxRows: number;
|
|
151
|
+
layers?: number;
|
|
152
|
+
minTime?: number;
|
|
153
|
+
maxTime?: number;
|
|
154
|
+
minBytes?: number;
|
|
155
|
+
maxBytes?: number;
|
|
156
|
+
}) => import("./engines").BufferConfig;
|
|
157
|
+
BufferExplicit: (config: Omit<import("./engines").BufferConfig, "type">) => import("./engines").BufferConfig;
|
|
158
|
+
Distributed: (config: Omit<import("./engines").DistributedConfig, "type">) => import("./engines").DistributedConfig;
|
|
159
|
+
Null: () => import("./engines").NullConfig;
|
|
160
|
+
Log: () => import("./engines").LogConfig;
|
|
161
|
+
TinyLog: () => import("./engines").TinyLogConfig;
|
|
162
|
+
Memory: (config?: Omit<import("./engines").MemoryConfig, "type">) => import("./engines").MemoryConfig;
|
|
163
|
+
Join: (strictness: import("./engines").JoinConfig["strictness"], joinType: import("./engines").JoinConfig["joinType"], keys: string[]) => import("./engines").JoinConfig;
|
|
164
|
+
Dictionary: (dictionaryName: string) => import("./engines").DictionaryConfig;
|
|
165
|
+
File: (format: string, compression?: import("./engines").FileConfig["compression"]) => import("./engines").FileConfig;
|
|
166
|
+
URL: (url: string, format: string, compression?: import("./engines").URLConfig["compression"]) => import("./engines").URLConfig;
|
|
167
|
+
S3: (config: Omit<import("./engines").S3Config, "type">) => import("./engines").S3Config;
|
|
168
|
+
Kafka: (config: Omit<import("./engines").KafkaConfig, "type">) => import("./engines").KafkaConfig;
|
|
169
|
+
PostgreSQL: (config: Omit<import("./engines").PostgreSQLConfig, "type">) => import("./engines").PostgreSQLConfig;
|
|
170
|
+
MySQL: (config: Omit<import("./engines").MySQLConfig, "type">) => import("./engines").MySQLConfig;
|
|
171
|
+
};
|
|
172
|
+
sql: typeof sql;
|
|
173
|
+
index: (name: string) => {
|
|
174
|
+
on: (...cols: import("./column").ClickHouseColumn[]) => {
|
|
175
|
+
type: (type: import("./table").IndexDefinition["type"], granularity?: number) => import("./table").IndexDefinition;
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
projection: (name: string, query: string) => import("./table").ProjectionDefinition;
|
|
179
|
+
deriveTable: typeof deriveTable;
|
|
180
|
+
detectMaterializedViewDrift: typeof detectMaterializedViewDrift;
|
|
181
|
+
extractMVQuery: typeof extractMVQuery;
|
|
182
|
+
createMigrationBridge: typeof createMigrationBridge;
|
|
183
|
+
generateBlueGreenMigration: typeof generateBlueGreenMigration;
|
|
184
|
+
generateSelectSchema: typeof generateSelectSchema;
|
|
185
|
+
generateInsertSchema: typeof generateInsertSchema;
|
|
186
|
+
};
|
|
187
|
+
export default _default;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { resolve, join } from "path";
|
|
3
|
+
import { existsSync, readdirSync } from "fs";
|
|
4
|
+
import { createClientFromConfigObject } from "./client";
|
|
5
|
+
import { ClickHouseColumn } from "./column";
|
|
6
|
+
import {
|
|
7
|
+
index,
|
|
8
|
+
projection,
|
|
9
|
+
deriveTable,
|
|
10
|
+
renderSchema
|
|
11
|
+
} from "./table";
|
|
12
|
+
import { Engine } from "./engines";
|
|
13
|
+
|
|
14
|
+
export * from "./external";
|
|
15
|
+
export * from "./expressions";
|
|
16
|
+
export * from "./builders/select";
|
|
17
|
+
export * from "./builders/select.types";
|
|
18
|
+
export * from "./builders/insert";
|
|
19
|
+
export * from "./builders/delete";
|
|
20
|
+
export * from "./builders/update";
|
|
21
|
+
export * from "./metadata";
|
|
22
|
+
export * from "./compiler";
|
|
23
|
+
export * from "./modules";
|
|
24
|
+
export * from "./relational";
|
|
25
|
+
export * from "./logger";
|
|
26
|
+
export * from "./client";
|
|
27
|
+
import {
|
|
28
|
+
t,
|
|
29
|
+
defineTable,
|
|
30
|
+
table,
|
|
31
|
+
view,
|
|
32
|
+
defineView,
|
|
33
|
+
materializedView,
|
|
34
|
+
defineMaterializedView,
|
|
35
|
+
dictionary,
|
|
36
|
+
defineDictionary,
|
|
37
|
+
defineProjection,
|
|
38
|
+
detectMaterializedViewDrift,
|
|
39
|
+
extractMVQuery,
|
|
40
|
+
createMigrationBridge,
|
|
41
|
+
generateBlueGreenMigration,
|
|
42
|
+
relations
|
|
43
|
+
} from "./schema-builder";
|
|
44
|
+
import { sql } from "./expressions";
|
|
45
|
+
import { generateSelectSchema, generateInsertSchema } from "./codegen/zod";
|
|
46
|
+
import {
|
|
47
|
+
BinaryWriter,
|
|
48
|
+
createBinaryEncoder,
|
|
49
|
+
serializeRowBinary,
|
|
50
|
+
serializeRowsBinary,
|
|
51
|
+
buildBinaryConfig
|
|
52
|
+
} from "./utils/binary-serializer";
|
|
53
|
+
import {
|
|
54
|
+
SyncBinarySerializer,
|
|
55
|
+
BinaryWorkerPool
|
|
56
|
+
} from "./utils/binary-worker-pool";
|
|
57
|
+
import {
|
|
58
|
+
t as t2,
|
|
59
|
+
defineTable as defineTable2,
|
|
60
|
+
table as table2,
|
|
61
|
+
view as view2,
|
|
62
|
+
defineView as defineView2,
|
|
63
|
+
materializedView as materializedView2,
|
|
64
|
+
defineMaterializedView as defineMaterializedView2,
|
|
65
|
+
dictionary as dictionary2,
|
|
66
|
+
defineDictionary as defineDictionary2,
|
|
67
|
+
defineProjection as defineProjection2,
|
|
68
|
+
detectMaterializedViewDrift as detectMaterializedViewDrift2,
|
|
69
|
+
extractMVQuery as extractMVQuery2,
|
|
70
|
+
createMigrationBridge as createMigrationBridge2,
|
|
71
|
+
generateBlueGreenMigration as generateBlueGreenMigration2,
|
|
72
|
+
relations as relations2
|
|
73
|
+
} from "./schema-builder";
|
|
74
|
+
import { sql as sql2 } from "./expressions";
|
|
75
|
+
import { Engine as Engine2 } from "./engines";
|
|
76
|
+
import { index as index2, projection as projection2, deriveTable as deriveTable2 } from "./table";
|
|
77
|
+
import { generateSelectSchema as generateSelectSchema2, generateInsertSchema as generateInsertSchema2 } from "./codegen/zod";
|
|
78
|
+
async function createClientFromConfig(databaseName = "default") {
|
|
79
|
+
const config = await loadConfig();
|
|
80
|
+
const dbConfig = config.databases[databaseName];
|
|
81
|
+
if (!dbConfig) {
|
|
82
|
+
throw new Error(`Database "${databaseName}" not found in housekit.config.js. Available databases: ${Object.keys(config.databases).join(", ")}`);
|
|
83
|
+
}
|
|
84
|
+
const clientConfig = {
|
|
85
|
+
url: dbConfig.url || (dbConfig.host ? `http://${dbConfig.host}${dbConfig.port ? `:${dbConfig.port}` : ""}` : "http://localhost:8123"),
|
|
86
|
+
database: dbConfig.database,
|
|
87
|
+
username: dbConfig.username || "default",
|
|
88
|
+
password: dbConfig.password || ""
|
|
89
|
+
};
|
|
90
|
+
return createClientFromConfigObject(clientConfig);
|
|
91
|
+
}
|
|
92
|
+
async function loadConfig() {
|
|
93
|
+
const root = process.cwd();
|
|
94
|
+
const extensions = ["ts", "js", "mjs", "cjs"];
|
|
95
|
+
function findConfigFile(dir, depth = 0) {
|
|
96
|
+
if (depth > 10)
|
|
97
|
+
return null;
|
|
98
|
+
if (dir.includes("node_modules") || dir.includes(".git"))
|
|
99
|
+
return null;
|
|
100
|
+
for (const ext of extensions) {
|
|
101
|
+
const configPath2 = join(dir, `housekit.config.${ext}`);
|
|
102
|
+
if (existsSync(configPath2)) {
|
|
103
|
+
return configPath2;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (depth < 3) {
|
|
107
|
+
try {
|
|
108
|
+
const entries = readdirSync(dir, { withFileTypes: true });
|
|
109
|
+
for (const entry of entries) {
|
|
110
|
+
if (entry.isDirectory() && !entry.name.startsWith(".") && entry.name !== "node_modules") {
|
|
111
|
+
const found = findConfigFile(join(dir, entry.name), depth + 1);
|
|
112
|
+
if (found)
|
|
113
|
+
return found;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
} catch {}
|
|
117
|
+
}
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
const configPath = findConfigFile(root);
|
|
121
|
+
if (configPath) {
|
|
122
|
+
const module = await import(resolve(configPath));
|
|
123
|
+
return module.default;
|
|
124
|
+
}
|
|
125
|
+
throw new Error("housekit.config.{ts,js,mjs,cjs} not found in workspace.");
|
|
126
|
+
}
|
|
127
|
+
function createClient(configOrName) {
|
|
128
|
+
if (configOrName === undefined) {
|
|
129
|
+
return createClientFromConfig("default");
|
|
130
|
+
}
|
|
131
|
+
if (typeof configOrName === "string") {
|
|
132
|
+
return createClientFromConfig(configOrName);
|
|
133
|
+
}
|
|
134
|
+
return createClientFromConfigObject(configOrName);
|
|
135
|
+
}
|
|
136
|
+
async function tableExists(client2, tableName) {
|
|
137
|
+
return client2.tableExists(tableName);
|
|
138
|
+
}
|
|
139
|
+
async function ensureTable(client2, table3) {
|
|
140
|
+
return client2.ensureTable(table3);
|
|
141
|
+
}
|
|
142
|
+
async function dropTable(client2, tableName, options) {
|
|
143
|
+
return client2.dropTable(tableName, options);
|
|
144
|
+
}
|
|
145
|
+
function createClients(configs) {
|
|
146
|
+
const clients = {};
|
|
147
|
+
for (const [name, config] of Object.entries(configs)) {
|
|
148
|
+
clients[name] = createClientFromConfigObject(config);
|
|
149
|
+
}
|
|
150
|
+
return clients;
|
|
151
|
+
}
|
|
152
|
+
async function closeAllClients(clients) {
|
|
153
|
+
await Promise.all(Object.values(clients).map((client2) => client2.close()));
|
|
154
|
+
}
|
|
155
|
+
var src_default = {
|
|
156
|
+
t: t2,
|
|
157
|
+
table: table2,
|
|
158
|
+
defineTable: defineTable2,
|
|
159
|
+
view: view2,
|
|
160
|
+
defineView: defineView2,
|
|
161
|
+
materializedView: materializedView2,
|
|
162
|
+
defineMaterializedView: defineMaterializedView2,
|
|
163
|
+
dictionary: dictionary2,
|
|
164
|
+
defineDictionary: defineDictionary2,
|
|
165
|
+
defineProjection: defineProjection2,
|
|
166
|
+
relations: relations2,
|
|
167
|
+
createClient,
|
|
168
|
+
createClients,
|
|
169
|
+
closeAllClients,
|
|
170
|
+
Engine: Engine2,
|
|
171
|
+
sql: sql2,
|
|
172
|
+
index: index2,
|
|
173
|
+
projection: projection2,
|
|
174
|
+
deriveTable: deriveTable2,
|
|
175
|
+
detectMaterializedViewDrift: detectMaterializedViewDrift2,
|
|
176
|
+
extractMVQuery: extractMVQuery2,
|
|
177
|
+
createMigrationBridge: createMigrationBridge2,
|
|
178
|
+
generateBlueGreenMigration: generateBlueGreenMigration2,
|
|
179
|
+
generateSelectSchema: generateSelectSchema2,
|
|
180
|
+
generateInsertSchema: generateInsertSchema2
|
|
181
|
+
};
|
|
182
|
+
export {
|
|
183
|
+
view,
|
|
184
|
+
tableExists,
|
|
185
|
+
table,
|
|
186
|
+
t,
|
|
187
|
+
sql,
|
|
188
|
+
serializeRowsBinary,
|
|
189
|
+
serializeRowBinary,
|
|
190
|
+
renderSchema,
|
|
191
|
+
relations,
|
|
192
|
+
projection,
|
|
193
|
+
materializedView,
|
|
194
|
+
index,
|
|
195
|
+
generateSelectSchema,
|
|
196
|
+
generateInsertSchema,
|
|
197
|
+
generateBlueGreenMigration,
|
|
198
|
+
extractMVQuery,
|
|
199
|
+
ensureTable,
|
|
200
|
+
dropTable,
|
|
201
|
+
dictionary,
|
|
202
|
+
detectMaterializedViewDrift,
|
|
203
|
+
deriveTable,
|
|
204
|
+
defineView,
|
|
205
|
+
defineTable,
|
|
206
|
+
defineProjection,
|
|
207
|
+
defineMaterializedView,
|
|
208
|
+
defineDictionary,
|
|
209
|
+
src_default as default,
|
|
210
|
+
createMigrationBridge,
|
|
211
|
+
createClients,
|
|
212
|
+
createClientFromConfig,
|
|
213
|
+
createClient,
|
|
214
|
+
createBinaryEncoder,
|
|
215
|
+
closeAllClients,
|
|
216
|
+
buildBinaryConfig,
|
|
217
|
+
SyncBinarySerializer,
|
|
218
|
+
Engine,
|
|
219
|
+
ClickHouseColumn,
|
|
220
|
+
BinaryWriter,
|
|
221
|
+
BinaryWorkerPool
|
|
222
|
+
};
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface HousekitLogger {
|
|
2
|
+
logQuery(query: string, params: any, durationMs: number, stats?: {
|
|
3
|
+
readRows: number;
|
|
4
|
+
readBytes: number;
|
|
5
|
+
}): void;
|
|
6
|
+
logError(error: Error, query: string): void;
|
|
7
|
+
}
|
|
8
|
+
export declare function wrapClientWithLogger(client: any, logger?: HousekitLogger): any;
|