Add event bus and storage layer
This commit is contained in:
parent
9ba51d8e96
commit
488ae82ed6
19 changed files with 537 additions and 21 deletions
39
packages/storage/src/clickhouse.ts
Normal file
39
packages/storage/src/clickhouse.ts
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import { createClient, type ClickHouseClient } from "@clickhouse/client";
|
||||
import type { OptionPrint } from "@islandflow/types";
|
||||
import { normalizeOptionPrint, optionPrintsTableDDL, OPTION_PRINTS_TABLE } from "./option-prints";
|
||||
|
||||
export type ClickHouseOptions = {
|
||||
url: string;
|
||||
database?: string;
|
||||
username?: string;
|
||||
password?: string;
|
||||
};
|
||||
|
||||
export const createClickHouseClient = (options: ClickHouseOptions): ClickHouseClient => {
|
||||
return createClient({
|
||||
url: options.url,
|
||||
database: options.database,
|
||||
username: options.username,
|
||||
password: options.password
|
||||
});
|
||||
};
|
||||
|
||||
export const ensureOptionPrintsTable = async (
|
||||
client: ClickHouseClient
|
||||
): Promise<void> => {
|
||||
await client.exec({
|
||||
query: optionPrintsTableDDL()
|
||||
});
|
||||
};
|
||||
|
||||
export const insertOptionPrint = async (
|
||||
client: ClickHouseClient,
|
||||
print: OptionPrint
|
||||
): Promise<void> => {
|
||||
const record = normalizeOptionPrint(print);
|
||||
await client.insert({
|
||||
table: OPTION_PRINTS_TABLE,
|
||||
values: [record],
|
||||
format: "JSONEachRow"
|
||||
});
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue