Skip to content

Commit

Permalink
fix support for multiple database
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu Lefebvre committed Aug 6, 2024
1 parent e98f5b1 commit 6529b71
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/clickhouse/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { APP_NAME, config } from "../config.js";
// TODO: Check how to abort previous queries if haven't returned yet
// TODO: Make client connect to all DB instances
const client = createClient({
...config,
username: config.username,
password: config.password,
url: config.host,
clickhouse_settings: {
allow_experimental_object_type: 1,
readonly: "1",
Expand Down
6 changes: 3 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import pkg from "../package.json";
export const DEFAULT_PORT = "8080";
export const DEFAULT_HOSTNAME = "localhost";
export const DEFAULT_HOST = "http://localhost:8123";
export const DATABASE_SUFFIX = "token_v1"; // API will use {chain}_{DATABASE_SUFFIX} as the database name
export const DATABASE_SUFFIX = "tokens_v1"; // API will use {chain}_{DATABASE_SUFFIX} as the database name
export const DEFAULT_USERNAME = "default";
export const DEFAULT_PASSWORD = "default";
export const DEFAULT_MAX_LIMIT = 10000;
Expand All @@ -28,7 +28,7 @@ const opts = program
.addOption(new Option("-p, --port <number>", "HTTP port on which to attach the API").env("PORT").default(DEFAULT_PORT))
.addOption(new Option("--hostname <string>", "Server listen on HTTP hostname").env("HOSTNAME").default(DEFAULT_HOSTNAME))
.addOption(new Option("--host <string>", "Database HTTP hostname").env("HOST").default(DEFAULT_HOST))
.addOption(new Option("--database <string>", "The database suffix to use inside ClickHouse for {chain}_{database}").env("DATABASE").default(`eth_${DATABASE_SUFFIX}`))
.addOption(new Option("--database <string>", "The database suffix to use inside ClickHouse for {chain}_{database}").env("DATABASE").default(`${DATABASE_SUFFIX}`))
.addOption(new Option("--username <string>", "Database user").env("USERNAME").default(DEFAULT_USERNAME))
.addOption(new Option("--password <string>", "Password associated with the specified username").env("PASSWORD").default(DEFAULT_PASSWORD))
.addOption(new Option("--max-limit <number>", "Maximum LIMIT queries").env("MAX_LIMIT").default(DEFAULT_MAX_LIMIT))
Expand All @@ -41,8 +41,8 @@ export const config = z.object({
port: z.string(),
hostname: z.string(),
host: z.string(),
database: z.string(),
username: z.string(),
database: z.string(),
password: z.string(),
maxLimit: z.coerce.number(),
verbose: z.coerce.boolean(),
Expand Down

0 comments on commit 6529b71

Please sign in to comment.