@quark-fw/clisma 0.1.8 → 0.1.9
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/dist/build-count-query.d.ts +2 -2
- package/dist/build-delete-query.d.ts +2 -2
- package/dist/build-find-many-query.d.ts +2 -2
- package/dist/build-find-many-query.js +2 -1
- package/dist/build-lightweight-delete-query.d.ts +2 -2
- package/dist/build-update-query.d.ts +2 -2
- package/dist/client.d.ts +2 -2
- package/dist/column.d.ts +3 -3
- package/dist/ddl.d.ts +2 -2
- package/dist/ddl.js +1 -3
- package/dist/migrate.d.ts +2 -2
- package/dist/rows.d.ts +2 -2
- package/dist/schema.d.ts +3 -2
- package/dist/sql-shared.d.ts +9 -10
- package/dist/sql-shared.js +2 -2
- package/dist/table-client.d.ts +3 -3
- package/dist/table-client.js +6 -2
- package/dist/table.d.ts +4 -2
- package/dist/where.d.ts +2 -2
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnyTable } from "./table.js";
|
|
2
2
|
import { WhereInput } from "./where.js";
|
|
3
3
|
import { SQLBuildResult } from "./sql-shared.js";
|
|
4
|
-
export declare function buildCountQuery(database: string, tableName: string, table:
|
|
4
|
+
export declare function buildCountQuery<T>(database: string, tableName: string, table: AnyTable, where?: WhereInput<T>): SQLBuildResult;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnyTable } from "./table.js";
|
|
2
2
|
import { WhereInput } from "./where.js";
|
|
3
3
|
import { SQLBuildResult } from "./sql-shared.js";
|
|
4
|
-
export declare function buildDeleteQuery(database: string, tableName: string, table:
|
|
4
|
+
export declare function buildDeleteQuery<T>(database: string, tableName: string, table: AnyTable, where?: WhereInput<T>): SQLBuildResult;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnyTable } from "./table.js";
|
|
2
2
|
import { FindManyArgs, SQLBuildResult } from "./sql-shared.js";
|
|
3
|
-
export declare function buildFindManyQuery(database: string, tableName: string, table:
|
|
3
|
+
export declare function buildFindManyQuery<T>(database: string, tableName: string, table: AnyTable, args?: FindManyArgs<T>): SQLBuildResult;
|
|
@@ -5,7 +5,8 @@ export function buildFindManyQuery(database, tableName, table, args = {}) {
|
|
|
5
5
|
// SELECT
|
|
6
6
|
let selectSQL = "*";
|
|
7
7
|
if (args.select) {
|
|
8
|
-
const
|
|
8
|
+
const select = args.select;
|
|
9
|
+
const keys = Object.keys(select).filter((k) => select[k] === true);
|
|
9
10
|
if (keys.length) {
|
|
10
11
|
selectSQL = keys.map(ctx.colRef).join(", ");
|
|
11
12
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnyTable } from "./table.js";
|
|
2
2
|
import { WhereInput } from "./where.js";
|
|
3
3
|
import { SQLBuildResult } from "./sql-shared.js";
|
|
4
|
-
export declare function buildLightweightDeleteQuery(database: string, tableName: string, table:
|
|
4
|
+
export declare function buildLightweightDeleteQuery<T>(database: string, tableName: string, table: AnyTable, where?: WhereInput<T>): SQLBuildResult;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnyTable } from "./table.js";
|
|
2
2
|
import { WhereInput } from "./where.js";
|
|
3
3
|
import { SQLBuildResult } from "./sql-shared.js";
|
|
4
|
-
export declare function buildUpdateQuery(database: string, tableName: string, table:
|
|
4
|
+
export declare function buildUpdateQuery<T>(database: string, tableName: string, table: AnyTable, where: WhereInput<T> | undefined, data: Record<string, unknown>): SQLBuildResult;
|
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TableClient } from "./table-client.js";
|
|
2
|
-
import { InferRow } from "./table.js";
|
|
2
|
+
import { AnyTable, InferRow } from "./table.js";
|
|
3
3
|
import { MigrationPlan } from "./migrate.js";
|
|
4
4
|
type ClientOptions = {
|
|
5
5
|
url: string;
|
|
@@ -10,7 +10,7 @@ type ClientOptions = {
|
|
|
10
10
|
};
|
|
11
11
|
export declare function createClient<TSchema extends {
|
|
12
12
|
database?: string;
|
|
13
|
-
tables: Record<string,
|
|
13
|
+
tables: Record<string, AnyTable>;
|
|
14
14
|
}>(schema: TSchema, options: ClientOptions): { [K in keyof TSchema["tables"]]: TableClient<InferRow<TSchema["tables"][K]>>; } & {
|
|
15
15
|
$init(): Promise<void>;
|
|
16
16
|
$migrate(): Promise<MigrationPlan>;
|
package/dist/column.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export type Column<T> = {
|
|
|
3
3
|
nullable: boolean;
|
|
4
4
|
__type?: T;
|
|
5
5
|
};
|
|
6
|
-
type NullableColumn<C extends Column<
|
|
6
|
+
type NullableColumn<C extends Column<unknown>> = C extends Column<infer T> ? Column<T | null> : never;
|
|
7
7
|
export declare const t: {
|
|
8
8
|
string: () => Column<string>;
|
|
9
9
|
uint8: () => Column<number>;
|
|
@@ -11,7 +11,7 @@ export declare const t: {
|
|
|
11
11
|
int32: () => Column<number>;
|
|
12
12
|
boolean: () => Column<boolean>;
|
|
13
13
|
datetime: () => Column<Date>;
|
|
14
|
-
nullable<C extends Column<
|
|
15
|
-
array<C extends Column<
|
|
14
|
+
nullable<C extends Column<unknown>>(col: C): NullableColumn<C>;
|
|
15
|
+
array<C extends Column<unknown>>(col: C): Column<C extends Column<infer T> ? T[] : never>;
|
|
16
16
|
};
|
|
17
17
|
export {};
|
package/dist/ddl.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function buildCreateTableSQL(database: string, tableName: string, table:
|
|
1
|
+
import { AnyTable } from "./table.js";
|
|
2
|
+
export declare function buildCreateTableSQL(database: string, tableName: string, table: AnyTable): string;
|
package/dist/ddl.js
CHANGED
|
@@ -2,9 +2,7 @@
|
|
|
2
2
|
import { escapeId } from "./sql.js";
|
|
3
3
|
export function buildCreateTableSQL(database, tableName, table) {
|
|
4
4
|
const columnsSQL = Object.entries(table.columns)
|
|
5
|
-
.map(([name, col]) => {
|
|
6
|
-
return `${escapeId(name)} ${col.clickhouseType}`;
|
|
7
|
-
})
|
|
5
|
+
.map(([name, col]) => `${escapeId(name)} ${col.clickhouseType}`)
|
|
8
6
|
.join(",\n");
|
|
9
7
|
return `
|
|
10
8
|
CREATE TABLE IF NOT EXISTS ${escapeId(database)}.${escapeId(tableName)}
|
package/dist/migrate.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnyTable } from "./table.js";
|
|
2
2
|
export type DbColumn = {
|
|
3
3
|
table: string;
|
|
4
4
|
name: string;
|
|
@@ -8,4 +8,4 @@ export type MigrationPlan = {
|
|
|
8
8
|
statements: string[];
|
|
9
9
|
warnings: string[];
|
|
10
10
|
};
|
|
11
|
-
export declare function buildMigrationPlan(database: string, tables: Record<string,
|
|
11
|
+
export declare function buildMigrationPlan(database: string, tables: Record<string, AnyTable>, existing: DbColumn[]): MigrationPlan;
|
package/dist/rows.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function deserializeRows<T>(rows:
|
|
1
|
+
import { AnyColumns } from "./table.js";
|
|
2
|
+
export declare function deserializeRows<T>(rows: Record<string, unknown>[], columns: AnyColumns): T[];
|
package/dist/schema.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { AnyTable } from "./table.js";
|
|
2
|
+
export type ClismaSchema<TTables extends Record<string, AnyTable>> = {
|
|
2
3
|
database?: string;
|
|
3
4
|
tables: TTables;
|
|
4
5
|
};
|
|
5
|
-
export declare function createClisma<TTables extends Record<string,
|
|
6
|
+
export declare function createClisma<TTables extends Record<string, AnyTable>>(schema: ClismaSchema<TTables>): ClismaSchema<TTables>;
|
package/dist/sql-shared.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { TableDefinition } from "./table.js";
|
|
1
|
+
import { AnyColumns, AnyTable } from "./table.js";
|
|
3
2
|
import { WhereInput } from "./where.js";
|
|
4
3
|
export type SQLBuildResult = {
|
|
5
4
|
sql: string;
|
|
6
|
-
params: Record<string,
|
|
5
|
+
params: Record<string, unknown>;
|
|
7
6
|
};
|
|
8
7
|
export type OrderByInput<T> = {
|
|
9
8
|
[K in keyof T]?: "asc" | "desc";
|
|
@@ -19,13 +18,13 @@ export type FindManyArgs<T> = {
|
|
|
19
18
|
};
|
|
20
19
|
export declare function escapeId(name: string): string;
|
|
21
20
|
export declare const NO_LIMIT = "18446744073709551615";
|
|
22
|
-
export declare function createBuildContext(tableName: string, columns:
|
|
23
|
-
params: Record<string,
|
|
21
|
+
export declare function createBuildContext(tableName: string, columns: AnyColumns): {
|
|
22
|
+
params: Record<string, unknown>;
|
|
24
23
|
colRef: (key: string) => string;
|
|
25
24
|
baseType: (key: string) => string;
|
|
26
|
-
addParam: (value:
|
|
27
|
-
whereSQL: (where:
|
|
25
|
+
addParam: (value: unknown, type: string) => string;
|
|
26
|
+
whereSQL: (where: Record<string, unknown>) => string;
|
|
28
27
|
};
|
|
29
|
-
export declare function tableRef(database: string, tableName: string, table:
|
|
30
|
-
export declare function checkPagination(name: string, value:
|
|
31
|
-
export declare function validateUpdateData(table:
|
|
28
|
+
export declare function tableRef(database: string, tableName: string, table: AnyTable): string;
|
|
29
|
+
export declare function checkPagination(name: string, value: number): void;
|
|
30
|
+
export declare function validateUpdateData(table: AnyTable, tableName: string, data: Record<string, unknown>): string[];
|
package/dist/sql-shared.js
CHANGED
|
@@ -99,7 +99,7 @@ export function createBuildContext(tableName, columns) {
|
|
|
99
99
|
if (value === undefined)
|
|
100
100
|
continue;
|
|
101
101
|
if (key === "AND") {
|
|
102
|
-
const list = Array.isArray(value) ? value : [value];
|
|
102
|
+
const list = (Array.isArray(value) ? value : [value]);
|
|
103
103
|
for (const w of list) {
|
|
104
104
|
const c = whereSQL(w);
|
|
105
105
|
if (c)
|
|
@@ -115,7 +115,7 @@ export function createBuildContext(tableName, columns) {
|
|
|
115
115
|
parts.push(`(${conds.join(" OR ")})`);
|
|
116
116
|
}
|
|
117
117
|
else if (key === "NOT") {
|
|
118
|
-
const list = Array.isArray(value) ? value : [value];
|
|
118
|
+
const list = (Array.isArray(value) ? value : [value]);
|
|
119
119
|
for (const w of list) {
|
|
120
120
|
const c = whereSQL(w);
|
|
121
121
|
if (c)
|
package/dist/table-client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ClickHouseClient } from "@clickhouse/client";
|
|
2
|
-
import {
|
|
2
|
+
import { AnyTable } from "./table.js";
|
|
3
3
|
import { Simplify } from "./types.js";
|
|
4
4
|
import { WhereInput } from "./where.js";
|
|
5
5
|
import { FindManyArgs } from "./sql.js";
|
|
@@ -15,12 +15,12 @@ type OptionalCreateKeys<T> = NullableKeys<T> | ("id" & keyof T);
|
|
|
15
15
|
export type CreateData<T> = Simplify<Omit<T, OptionalCreateKeys<T>> & {
|
|
16
16
|
[K in OptionalCreateKeys<T>]?: T[K];
|
|
17
17
|
}>;
|
|
18
|
-
export declare class TableClient<T
|
|
18
|
+
export declare class TableClient<T extends Record<string, unknown>> {
|
|
19
19
|
private database;
|
|
20
20
|
private tableName;
|
|
21
21
|
private table;
|
|
22
22
|
private client;
|
|
23
|
-
constructor(database: string, tableName: string, table:
|
|
23
|
+
constructor(database: string, tableName: string, table: AnyTable, client: ClickHouseClient);
|
|
24
24
|
private get tableRef();
|
|
25
25
|
private runQuery;
|
|
26
26
|
findMany<A extends FindManyArgs<T>>(args?: A): Promise<FindManyResult<T, A>[]>;
|
package/dist/table-client.js
CHANGED
|
@@ -42,7 +42,10 @@ export class TableClient {
|
|
|
42
42
|
return deserializeRows(rows, this.table.columns);
|
|
43
43
|
}
|
|
44
44
|
async findFirst(args) {
|
|
45
|
-
const rows = await this.findMany({
|
|
45
|
+
const rows = await this.findMany({
|
|
46
|
+
...args,
|
|
47
|
+
take: 1,
|
|
48
|
+
});
|
|
46
49
|
return rows[0] ?? null;
|
|
47
50
|
}
|
|
48
51
|
async count(args) {
|
|
@@ -70,7 +73,8 @@ export class TableClient {
|
|
|
70
73
|
full[colName] = null;
|
|
71
74
|
}
|
|
72
75
|
else if (full[colName] instanceof Date) {
|
|
73
|
-
full[colName] = new Date(Math.floor(full[colName].getTime() / 1000) *
|
|
76
|
+
full[colName] = new Date(Math.floor(full[colName].getTime() / 1000) *
|
|
77
|
+
1000);
|
|
74
78
|
}
|
|
75
79
|
}
|
|
76
80
|
const obj = {};
|
package/dist/table.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { Column } from "./column.js";
|
|
2
2
|
import { Simplify } from "./types.js";
|
|
3
3
|
export type MutationStrategy = "alter" | "lightweight" | "replacing";
|
|
4
|
-
export type TableDefinition<TColumns extends Record<string, Column<
|
|
4
|
+
export type TableDefinition<TColumns extends Record<string, Column<unknown>>> = {
|
|
5
5
|
engine: string;
|
|
6
6
|
orderBy: string[];
|
|
7
7
|
mutations?: MutationStrategy;
|
|
8
8
|
columns: TColumns;
|
|
9
9
|
};
|
|
10
|
-
export
|
|
10
|
+
export type AnyColumns = Record<string, Column<unknown>>;
|
|
11
|
+
export type AnyTable = TableDefinition<AnyColumns>;
|
|
12
|
+
export declare function table<TColumns extends Record<string, Column<unknown>>>(def: TableDefinition<TColumns>): TableDefinition<TColumns>;
|
|
11
13
|
export type InferRow<TTable> = TTable extends TableDefinition<infer TColumns> ? Simplify<{
|
|
12
14
|
[K in keyof TColumns]: TColumns[K] extends Column<infer T> ? T : never;
|
|
13
15
|
}> : never;
|
package/dist/where.d.ts
CHANGED
|
@@ -14,11 +14,11 @@ export type ScalarFilter<T> = {
|
|
|
14
14
|
not?: T | null;
|
|
15
15
|
in?: T[];
|
|
16
16
|
notIn?: T[];
|
|
17
|
-
} & (T extends number | bigint | Date | string ? ComparableFilter<T> :
|
|
17
|
+
} & (T extends number | bigint | Date | string ? ComparableFilter<T> : unknown) & (T extends string ? StringFilter : unknown);
|
|
18
18
|
export type WhereInput<T> = {
|
|
19
19
|
AND?: WhereInput<T> | WhereInput<T>[];
|
|
20
20
|
OR?: WhereInput<T>[];
|
|
21
21
|
NOT?: WhereInput<T> | WhereInput<T>[];
|
|
22
22
|
} & {
|
|
23
|
-
[K in keyof T]?: T[K] extends readonly
|
|
23
|
+
[K in keyof T]?: T[K] extends readonly unknown[] ? never : T[K] | ScalarFilter<NonNullable<T[K]>> | null;
|
|
24
24
|
};
|