@quark-fw/clisma 0.1.13 → 0.1.15
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/README.md +135 -19
- package/dist/assert-replicated-schema.d.ts +2 -0
- package/dist/assert-replicated-schema.js +16 -0
- package/dist/build-count-query.js +2 -1
- package/dist/build-create-dictionary-query.d.ts +2 -0
- package/dist/build-create-dictionary-query.js +51 -0
- package/dist/build-find-many-query.js +1 -1
- package/dist/build-index-sql.d.ts +2 -0
- package/dist/build-index-sql.js +11 -0
- package/dist/client.d.ts +21 -3
- package/dist/client.js +75 -21
- package/dist/column.d.ts +30 -1
- package/dist/column.js +55 -0
- package/dist/ddl-shared.d.ts +13 -0
- package/dist/ddl-shared.js +54 -0
- package/dist/ddl.d.ts +3 -0
- package/dist/ddl.js +42 -7
- package/dist/dictionary.d.ts +26 -0
- package/dist/dictionary.js +7 -0
- package/dist/engine.d.ts +16 -0
- package/dist/engine.js +26 -0
- package/dist/ensure-dictionaries-on-nodes.d.ts +3 -0
- package/dist/ensure-dictionaries-on-nodes.js +15 -0
- package/dist/ensure-tables-on-nodes.d.ts +11 -0
- package/dist/ensure-tables-on-nodes.js +39 -0
- package/dist/escape-id.d.ts +1 -0
- package/dist/escape-id.js +4 -0
- package/dist/expr.d.ts +5 -0
- package/dist/expr.js +4 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +5 -0
- package/dist/migrate.d.ts +3 -0
- package/dist/migrate.js +52 -5
- package/dist/query.d.ts +26 -0
- package/dist/query.js +60 -0
- package/dist/rows.js +9 -0
- package/dist/schema.d.ts +4 -2
- package/dist/sql-shared.d.ts +5 -2
- package/dist/sql-shared.js +16 -7
- package/dist/table-client.js +9 -2
- package/dist/table.d.ts +26 -4
- package/dist/table.js +24 -3
- package/package.json +2 -2
package/dist/table.d.ts
CHANGED
|
@@ -1,15 +1,37 @@
|
|
|
1
1
|
import { Column } from "./column.js";
|
|
2
|
+
import type { EngineSpec } from "./engine.js";
|
|
3
|
+
import type { KeyPart } from "./expr.js";
|
|
2
4
|
import { Simplify } from "./types.js";
|
|
3
5
|
export type MutationStrategy = "alter" | "lightweight" | "replacing";
|
|
6
|
+
export type IndexType = "bloom_filter" | "set" | "minmax" | "tokenbf_v1" | "ngrambf_v1";
|
|
7
|
+
export type IndexDefinition = {
|
|
8
|
+
name: string;
|
|
9
|
+
expr: KeyPart;
|
|
10
|
+
type: IndexType;
|
|
11
|
+
args?: (number | string)[];
|
|
12
|
+
granularity?: number;
|
|
13
|
+
};
|
|
4
14
|
export type TableDefinition<TColumns extends Record<string, Column<unknown>>> = {
|
|
5
|
-
engine: string;
|
|
6
|
-
|
|
15
|
+
engine: string | EngineSpec;
|
|
16
|
+
replication?: {
|
|
17
|
+
path: string;
|
|
18
|
+
replica: string;
|
|
19
|
+
};
|
|
20
|
+
orderBy: KeyPart[];
|
|
21
|
+
primaryKey?: KeyPart[];
|
|
22
|
+
partitionBy?: KeyPart;
|
|
23
|
+
sampleBy?: KeyPart;
|
|
24
|
+
indexes?: IndexDefinition[];
|
|
25
|
+
ttl?: string;
|
|
26
|
+
settings?: Record<string, string | number>;
|
|
27
|
+
comment?: string;
|
|
7
28
|
mutations?: MutationStrategy;
|
|
8
29
|
columns: TColumns;
|
|
9
30
|
};
|
|
10
31
|
export type AnyColumns = Record<string, Column<unknown>>;
|
|
11
32
|
export type AnyTable = TableDefinition<AnyColumns>;
|
|
12
33
|
export declare function table<TColumns extends Record<string, Column<unknown>>>(def: TableDefinition<TColumns>): TableDefinition<TColumns>;
|
|
13
|
-
export type
|
|
34
|
+
export type InferColumns<TColumns extends Record<string, Column<unknown>>> = Simplify<{
|
|
14
35
|
[K in keyof TColumns]: TColumns[K] extends Column<infer T> ? T : never;
|
|
15
|
-
}
|
|
36
|
+
}>;
|
|
37
|
+
export type InferRow<TTable> = TTable extends TableDefinition<infer TColumns> ? InferColumns<TColumns> : never;
|
package/dist/table.js
CHANGED
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
// src/table.ts
|
|
2
|
+
import { collapsingOf, isReplacingEngine, keyColumns } from "./ddl-shared.js";
|
|
3
|
+
const INTEGER_TYPE = /^(U?Int(8|16|32|64))$/;
|
|
2
4
|
export function table(def) {
|
|
3
|
-
if (def.mutations === "replacing" &&
|
|
4
|
-
!def.engine.includes("ReplacingMergeTree")) {
|
|
5
|
+
if (def.mutations === "replacing" && !isReplacingEngine(def.engine)) {
|
|
5
6
|
throw new Error(`mutations: "replacing" requires a ReplacingMergeTree engine ` +
|
|
6
|
-
`(got "${def.engine}")`);
|
|
7
|
+
`(got "${typeof def.engine === "string" ? def.engine : def.engine.family}")`);
|
|
8
|
+
}
|
|
9
|
+
// коллапс работает только с целочисленным знаком и версией — ошибка
|
|
10
|
+
// схемы должна всплыть при объявлении, а не при первом INSERT
|
|
11
|
+
const collapsing = collapsingOf(def.engine);
|
|
12
|
+
if (collapsing) {
|
|
13
|
+
const sign = def.columns[collapsing.sign];
|
|
14
|
+
if (!sign || sign.clickhouseType !== "Int8") {
|
|
15
|
+
throw new Error(`Collapsing engine requires sign column "${collapsing.sign}" of type Int8`);
|
|
16
|
+
}
|
|
17
|
+
if (collapsing.version) {
|
|
18
|
+
const version = def.columns[collapsing.version];
|
|
19
|
+
if (!version || !INTEGER_TYPE.test(version.clickhouseType)) {
|
|
20
|
+
throw new Error(`VersionedCollapsingMergeTree requires integer version column "${collapsing.version}"`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
for (const key of keyColumns([...def.orderBy, ...(def.primaryKey ?? [])])) {
|
|
25
|
+
if (!def.columns[key]) {
|
|
26
|
+
throw new Error(`Key column "${key}" is not declared in columns`);
|
|
27
|
+
}
|
|
7
28
|
}
|
|
8
29
|
return def;
|
|
9
30
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quark-fw/clisma",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.15",
|
|
4
4
|
"description": "Prisma-like typed client and schema migrator for ClickHouse",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"clickhouse",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"build": "tsc -p tsconfig.build.json",
|
|
33
33
|
"typecheck": "tsc --noEmit",
|
|
34
34
|
"test": "tsx --env-file=./src/test/.env ./src/test/index.ts",
|
|
35
|
-
"test:unit": "tsx --test src/test/unit.test.ts",
|
|
35
|
+
"test:unit": "tsx --test src/test/unit.test.ts src/test/ddl.test.ts",
|
|
36
36
|
"prepublishOnly": "npm run typecheck && npm run test:unit && npm run build"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|