interface
SQL.SQLiteOptions
interface SQLiteOptions
Options for Database
- adapter?: 'sqlite'
Selects the SQLite adapter. Optional when filename is set, because a
filenameselects SQLite too. - bigint?: boolean
Return every integer as a
BigInt. The same assafeIntegers, under the name that the other adapters use.safeIntegerstakes priority. - create?: boolean
Allow creating a new database
Equivalent to constants.SQLITE_OPEN_CREATE
When
false, opening a file that does not exist throws an error with the codeSQLITE_CANTOPEN. - filename?: URL | string & {} | ':memory:'
Path to the database file
Examples:
sqlite://:memory:sqlite://./path/to/database.dbsqlite:///Users/bun/projects/my-app/database.db./dev.db:memory:
Everything from the first
?is a query string, which can havemode=:ro(read-only),rw(read-write, the file must exist) orrwc(read-write and create, the default).memoryhas no effect, and any other mode throws. Thereadonlyandcreateoptions take priority over it, and a read-only database ignorescreateandreadwrite.Without a
filename, Bun reads aDATABASE_URLthat is not a PostgreSQL, MySQL or MariaDB URL, thenSQLITE_URL. - readonly?: boolean
Open the database as read-only (no write operations, no create).
Equivalent to constants.SQLITE_OPEN_READONLY
Together with
create: trueorreadwrite: true, the constructor throws aTypeError. - readwrite?: boolean
Open the database as read-write
Equivalent to constants.SQLITE_OPEN_READWRITE
readwrite: truewithoutcreate: truedoes not create the file.readwrite: falseis the same asreadonly: true. - safeIntegers?: boolean
When
true, integers are returned asbigint.When
false, integers are returned asnumber, and integers beyond 53 bits are rounded to the nearestnumber.When
true, abigintparameter that does not fit in a signed 64-bit integer throws aRangeError. Whenfalse, it keeps its low 64 bits:2n ** 64n - 1nis stored as-1. - strict?: boolean
When set to
true, a query with a missing bound parameter throws an error. When set tofalseorundefined, the parameter isNULL.In both modes, the key of a named parameter can include the
$,:, or@prefix or leave it out. If an object has both keys, the key without the prefix wins in strict mode, and the key with the prefix otherwise.const db = new Database(":memory:", { strict: true }); db.run("INSERT INTO foo (name) VALUES ($name)", { name: "foo" }); db.run("INSERT INTO foo (name) VALUES ($name)", { nmae: "foo" }); // throws - transform?: Transform | NameTransform
Renames columns between the database and JavaScript, for example SQL.camel