@ratiu5/kysely-bun-psql
v0.0.3
Published
Kysely dialect for PostgreSQL using the Bun's SQL client
Maintainers
Readme
kysely-bun-psql
⚠️ Beta Status: This package is currently in beta. While it's functional and tested, you may encounter bugs or missing features. Please open an issue if you find any problems or have feature requests. Pull requests are welcome!
Kysely dialect for PostgreSQL using Bun's built-in SQL client under the hood.
This dialect provides a fast, native PostgreSQL client for Kysely when running in Bun, leveraging Bun's built-in SQL support introduced in v1.2.
Installation
bun add @ratiu5/kysely-bun-psqlUsage
import { Kysely, type Generated } from "kysely";
import { BunDialect } from "kysely-bun-psql";
interface Database {
person: {
id: Generated<number>;
first_name: string;
last_name: string | null;
created_at: Generated<Date>;
};
}
const db = new Kysely<Database>({
dialect: new BunDialect({
url: "postgres://user:pass@localhost:5432/db",
}),
});
// Execute queries
const person = await db
.selectFrom("person")
.selectAll()
.where("id", "=", 1)
.executeTakeFirst();
// Use transactions
await db.transaction().execute(async (trx) => {
await trx
.insertInto("person")
.values({
first_name: "John",
last_name: "Doe",
})
.execute();
});
// Clean up
await db.destroy();Configuration
The dialect accepts all the same options as Bun's SQL client:
interface BunDialectConfig {
url: string;
hostname?: string;
port?: number;
database?: string;
username?: string;
password?: string;
max?: number;
idleTimeout?: number;
maxLifetime?: number;
connectionTimeout?: number;
tls?: boolean;
}Requirements
- Bun v1.2 or higher
License
MIT License, see `LICENSE`
