TypeScript SDK

Postgres for agents,
one line of code

Use the official get-db9 package to create, seed, and manage PostgreSQL-compatible databases with instant setup or full client API control.

npm install get-db9
yarn add get-db9
pnpm add get-db9
bun add get-db9
Read our docs →
TypeScript SDK Examples
create-database.ts
import { instantDatabase } from 'get-db9';

const db = await instantDatabase({
  name: 'myapp',
  seed: 'CREATE TABLE users (id SERIAL PRIMARY KEY, name TEXT)',
});

console.log(db.connectionString);
// postgresql://tenant.admin:password@host:5433/postgres
client-example.ts
import { createDb9Client } from 'get-db9/client';
 
 const client = createDb9Client();
 const db = await client.databases.create({ name: 'myapp' });
 const result = await client.databases.sql(db.id, 'SELECT * FROM users');
 console.log(result.columns, result.rows);
filesystem-example.ts
import { createDb9Client } from 'get-db9/client';

const client = createDb9Client();
const dbId = 'my-database-id';

await client.fs.mkdir(dbId, '/data');
await client.fs.write(dbId, '/data/hello.txt', 'Hello from db9!');

const content = await client.fs.read(dbId, '/data/hello.txt');
const files = await client.fs.list(dbId, '/data/');
const info = await client.fs.stat(dbId, '/data/hello.txt');
const ok = await client.fs.exists(dbId, '/data/hello.txt');

await client.fs.remove(dbId, '/data/hello.txt');

Choose your integration layer

Use the high-level instant API or compose the full client API for precise control over auth, databases, SQL, and lifecycle operations.

instantDatabase(options?)

Creates or reuses a database by name, auto-registering anonymously when no token exists. Supports SQL seeding via seed or seedFile.

Example
import { instantDatabase } from 'get-db9';

const db = await instantDatabase({
  name: 'myapp',
  seed: 'CREATE TABLE users (id SERIAL PRIMARY KEY, name TEXT)',
});

console.log(db.databaseId, db.connectionString);
Parameters
NameTypeDescription
namestringDatabase name, default 'default'.
baseUrlstringAPI base URL override.
fetchFetchFnCustom fetch implementation.
credentialStoreCredentialStoreToken storage loader/saver.
seedstringSQL executed right after creation.
seedFilestringSQL file content executed after creation.
timeoutnumberRequest timeout in milliseconds.
maxRetriesnumberRetry count (capped at 3).
retryDelaynumberDelay between retries in ms.

createDb9Client(options?)

Typed Client API with auth, database, SQL, schema, dump, migration, branch, and user operations. Auto-registers anonymously when no token provided.

Example
import { createDb9Client } from 'get-db9/client';
 
 const client = createDb9Client();
 const db = await client.databases.create({ name: 'myapp' });
 const result = await client.databases.sql(db.id, 'SELECT * FROM users');
Parameters
NameTypeDescription
baseUrlstringClient API endpoint (default production URL).
tokenstringOptional bearer token. If omitted, auto-registers anonymously.
fetchFetchFnCustom fetch implementation.
credentialStoreCredentialStoreOptional lazy token loader when no token passed.
timeoutnumberRequest timeout in milliseconds.
maxRetriesnumberRetry count (capped at 3).
retryDelaynumberDelay between retries in ms.

client.fs

Cloud filesystem operations for reading, writing, and managing files attached to each database. Built for RAG pipelines, file ingestion, and agent workflows.

Methods
MethodReturnsDescription
list(dbId, path, options?)Promise<Fs9FileEntry[]>List directory contents.
read(dbId, path)Promise<string>Read file content as text.
write(dbId, path, content)Promise<void>Write text content to a file.
stat(dbId, path)Promise<Fs9FileEntry>Get file metadata (size, type, timestamps).
mkdir(dbId, path)Promise<void>Create a directory (recursive).
remove(dbId, path)Promise<void>Delete a file or directory.
readBinary(dbId, path)Promise<ArrayBuffer>Read file as binary.
exists(dbId, path)Promise<boolean>Check if file exists.
events(dbId, opts?)Promise<Fs9EventEntry[]>Get filesystem event log.
Example
const client = createDb9Client();

await client.fs.mkdir(dbId, '/data');
await client.fs.write(dbId, '/data/doc.txt', 'Hello!');

const content = await client.fs.read(dbId, '/data/doc.txt');
const files = await client.fs.list(dbId, '/data/');
const info = await client.fs.stat(dbId, '/data/doc.txt');

await client.fs.remove(dbId, '/data/doc.txt');
Fs9FileEntry
FieldTypeDescription
pathstringFull file path.
sizenumberFile size in bytes.
file_type'regular' | 'directory' | 'symlink'Entry type.
mtimenumberLast modified (Unix timestamp).
etagstringContent hash for caching.

Built for shipping fast

Drop one package in your stack and move from empty project to production-ready database workflows.

One-liner setup

instantDatabase() creates or reuses a database immediately.

🔒

Zero config auth

Anonymous register + local credential store means fewer setup steps.

📦

Full typed API

Comprehensive TypeScript response models for all SDK methods.

🔄

ESM + CJS

Build output supports modern runtimes and existing Node workflows.

🔄

Two API layers

High-level instant API and full Client API for complete control.

🌱

Database seeding

Seed tables and fixtures at creation time with SQL strings or files.

📁

Cloud filesystem

Read, write, list, and manage files per database with client.fs.

🔑

Token management

Create, list, and revoke named API tokens with client.tokens.

🔄

Auto 401 retry

Automatic anonymous token refresh on 401 — zero manual re-auth needed.

Start building in seconds

Install the SDK, call one function, and ship your first query immediately.

npm install get-db9