Bun SQL
PostgreSQL driver using Bun's built-in SQL client
Requirements
- Bun runtime
Configuration
import { createClient } from "viborm/drivers/bun-sql";
const client = createClient({
databaseUrl: process.env.DATABASE_URL,
schema,
});Options
| Option | Type | Description |
|---|---|---|
client | SQL | Existing Bun SQL client |
databaseUrl | string | PostgreSQL connection URL |
options | object | Connection options |
pgvector | boolean | Enable pgvector support |
postgis | boolean | Enable PostGIS support |
Options Object
| Option | Type | Description |
|---|---|---|
hostname | string | Database host |
port | number | Database port |
username | string | Database user |
password | string | Database password |
database | string | Database name |
tls | boolean | object | TLS configuration |
max | number | Maximum connections |
idleTimeout | number | Idle connection timeout |
maxLifetime | number | Maximum connection lifetime |
Using Options
import { createClient } from "viborm/drivers/bun-sql";
const client = createClient({
options: {
hostname: "localhost",
port: 5432,
username: "postgres",
password: "password",
database: "mydb",
},
schema,
});With pgvector
import { createClient } from "viborm/drivers/bun-sql";
const client = createClient({
databaseUrl: process.env.DATABASE_URL,
pgvector: true,
schema,
});Transactions
Bun SQL supports full transactions with savepoints for nested transactions.
await client.$transaction(async (tx) => {
await tx.user.create({ data: { name: "Alice" } });
await tx.post.create({ data: { title: "Hello", authorId: "..." } });
});Limitations
- Only available in Bun runtime
- API similar to postgres.js