type
SQL.Options
Configuration options for SQL client connection and behavior
const config: Bun.SQL.Options = {
host: 'localhost',
port: 5432,
user: 'dbuser',
password: 'secretpass',
database: 'myapp',
idleTimeout: 30,
max: 20,
onconnect: (err) => {
if (!err) console.log('Connected to database');
}
};Referenced types
interface SQLiteOptions
Options for Database
- readonly?: boolean
Open the database as read-only (no write operations, no create).
Equivalent to constants.SQLITE_OPEN_READONLY
- safeIntegers?: boolean
When
true, integers are returned asbigint.When
false, integers are returned asnumberand truncated to 52 bits. - strict?: boolean
When set to
falseorundefined:- Queries missing bound parameters do NOT throw an error
- Bound named parameters in JavaScript need to exactly match the SQL query.
const db = new Database(":memory:", { strict: false }); db.run("INSERT INTO foo (name) VALUES ($name)", { $name: "foo" });When set to
true:- Queries missing bound parameters throw an error
- Bound named parameters in JavaScript no longer need the
$,:, or@prefix. The SQL query keeps its prefix.
interface PostgresOrMySQLOptions
- allowPublicKeyRetrieval?: boolean
MySQL only. Allow the client to request the server's RSA public key during
caching_sha2_password/sha256_passwordauthentication when the connection is not protected by TLS. Disabled by default because a network attacker can substitute their own key and recover the plaintext password. Enable only for trusted local connections, or use TLS instead. - bigint?: boolean
Return values outside the i32 range as
BigInt. By default they are returned as strings. - tls?: boolean | BunFile | 'require' | TLSOptions | 'disable' | 'allow' | 'prefer' | 'verify-ca' | 'verify-full'
Whether to use TLS/SSL for the connection. A string selects the SSL mode (
"disable","allow","prefer","require","verify-ca","verify-full").