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
| Name | Type | Description |
name | string | Database name, default 'default'. |
baseUrl | string | API base URL override. |
fetch | FetchFn | Custom fetch implementation. |
credentialStore | CredentialStore | Token storage loader/saver. |
seed | string | SQL executed right after creation. |
seedFile | string | SQL file content executed after creation. |
timeout | number | Request timeout in milliseconds. |
maxRetries | number | Retry count (capped at 3). |
retryDelay | number | Delay 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
| Name | Type | Description |
baseUrl | string | Client API endpoint (default production URL). |
token | string | Optional bearer token. If omitted, auto-registers anonymously. |
fetch | FetchFn | Custom fetch implementation. |
credentialStore | CredentialStore | Optional lazy token loader when no token passed. |
timeout | number | Request timeout in milliseconds. |
maxRetries | number | Retry count (capped at 3). |
retryDelay | number | Delay 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
| Method | Returns | Description |
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
| Field | Type | Description |
path | string | Full file path. |
size | number | File size in bytes. |
file_type | 'regular' | 'directory' | 'symlink' | Entry type. |
mtime | number | Last modified (Unix timestamp). |
etag | string | Content hash for caching. |