Create a Database instance with the specified connection configuration.
The connection configuration. These keys are evaluated lazily, so it is possible to omit the baseUrl or signer, depending on your query needs. For a read-only Database for instance, only the baseUrl needs to be provided.
Readonly
configExecute a set of Statements in batch mode. Batching sends multiple SQL statements inside a single call to the network. This can have a huge performance impact, as it only sends one transaction to the Tableland smart contract, thereby reducing gas costs. Batched statements are similar to SQL transactions. If a statement in the sequence fails, then an error is returned for that specific statement, and it aborts or rolls back the entire sequence.
An array of run results.
Export a (set of) tables to the SQLite binary format. Not implemented yet!
Additional options to control execution.
Executes one or more queries directly without prepared statements
or parameters binding. This method can have poorer performance
(prepared statements can be reused in some cases) and, more importantly,
is less safe. Only use this method for maintenance and one-shot tasks
(example: migration jobs). The input can be one or multiple queries
separated by the standard ;
.
If an error occurs, an exception is thrown with the query and error
messages (see below for Errors
).
Currently, the entire string of statements is submitted as a single
transaction. In the future, more "intelligent" transaction planning,
splitting, and batching may be used.
A set of SQL statement strings separated by semi-colons.
Additional options to control execution.
A single run result.
Create a new prepared statement. Both static and prepared statements are supported. In the current implementation, the prepared statements are prepared locally, and executed remotely (on-chain).
The SQL statement string to prepare.
A Statement object constructed with the given SQL string.
Static
forStatic
readCreate a Database that uses the default baseUrl for a given chain.
The name or id of the chain to target.
A Database without a signer configured.
since 4.0.1, will be deleted in 5.0.0
Generated using TypeDoc
Database is the primary API for accessing the Tabeland network as a database. This class provides a small and simple API that will feel very familiar to web2 database users. It includes the concept of prepared statements, SQL parameter binding, execution and query modes, and more. It is actually similar to the better-sqlite3, and D1 APIs in many respects.