Configuration options for SQL client connection and behavior
type
SQL.Options
type Options = SQLiteOptions | PostgresOrMySQLOptions
const config: Bun.SQL.Options = {
host: 'localhost',
port: 5432,
user: 'dbuser',
password: 'secretpass',
database: 'myapp',
idleTimeout: 30,
max: 20,
onconnect: (client) => {
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 set to
true
, integers are returned asbigint
types.When set to
false
, integers are returned asnumber
types and truncated to 52 bits. - strict?: boolean
When set to
false
orundefined
:- Queries missing bound parameters will 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 will throw an error
- Bound named parameters in JavaScript no longer need to be
$
,:
, or@
. The SQL query will remain prefixed.
interface PostgresOrMySQLOptions
- bigint?: boolean
By default values outside i32 range are returned as strings. If this is true, values outside i32 range are returned as BigInts.