questdb-typesafe-client

Client

Configure and use the QuestDB HTTP client.

Creating a Client

The QuestDBClient connects to QuestDB over its HTTP REST API. No native drivers are needed.

import { QuestDBClient } from "@fcannizzaro/questdb-typesafe-client";

const db = new QuestDBClient({
  host: "localhost",
  port: 9000,
});

Configuration Options

OptionTypeDefaultDescription
hoststring"localhost"QuestDB hostname
portnumber9000QuestDB HTTP port
httpsbooleanfalseUse HTTPS
usernamestringBasic auth username
passwordstringBasic auth password
timeoutnumber30000Request timeout in milliseconds
retriesnumber0Retry count for transient errors
fetchtypeof fetchglobal fetchCustom fetch implementation

Authentication

const db = new QuestDBClient({
  host: "questdb.example.com",
  port: 443,
  https: true,
  username: "admin",
  password: "secret",
});

Retries

The client retries on 5xx and network errors with exponential backoff (100ms * attempt). 4xx errors are never retried.

const db = new QuestDBClient({
  host: "localhost",
  retries: 3, // retry up to 3 times on transient errors
});

Custom Fetch

Useful for testing or environments with custom HTTP clients:

const db = new QuestDBClient({
  host: "localhost",
  fetch: myCustomFetch,
});

Client Methods

client.table(def)

Creates a typed Table instance from a table definition. This is the main entry point for queries and DDL.

const energyReadings = defineTable({ /* ... */ });
const table = db.table(energyReadings);

client.exec(sql)

Execute raw SQL via the /exec endpoint:

const result = await db.exec("SELECT * FROM energy_readings LIMIT 10");
// result: { columns, dataset, count, ... }

client.import(tableName, csvData, options?)

Bulk CSV import via the /imp endpoint:

const csv = "ts,source,power_kw\n2026-01-01T00:00:00Z,solar,48.7\n";
const result = await db.import("energy_readings", csv, {
  timestamp: "ts",
  partitionBy: "DAY",
});
// result: { rowsImported, rowsRejected, ... }

Import options:

OptionTypeDescription
overwritebooleanOverwrite existing table
durablebooleanDurable import
atomicity"relaxed" | "strict"Atomicity level
timestampstringTimestamp column name
partitionByPartitionByPartition strategy

client.ping()

Health check — returns true if QuestDB is reachable:

const healthy = await db.ping();

On this page