This document describes the JavaScript API for Turso. The API is implemented in two different packages:
- @tursodatabase/database (
bindings/javascript) - Native bindings for the Turso database. - @tursodatabase/serverless (
packages/turso-serverless) - Serverless driver for Turso Cloud databases.
The API is compatible with the libSQL promise API, which is an asynchronous variant of the better-sqlite3 API.
Opens a new database connection.
| Param | Type | Description |
|---|---|---|
| path | string |
Path to the database file |
The path parameter points to the SQLite database file to open. If the file pointed to by path does not exists, it will be created.
To open an in-memory database, please pass :memory: as the path parameter.
The function returns a Database object.
The Database class represents a connection that can prepare and execute SQL statements.
Prepares a SQL statement for execution.
| Param | Type | Description |
|---|---|---|
| sql | string |
The SQL statement string to prepare. |
The function returns a Statement object.
This function is currently not supported.
This function is currently not supported.
This function is currently not supported.
This function is currently not supported.
This function is currently not supported.
This function is currently not supported.
This function is currently not supported.
This function is currently not supported.
This function is currently not supported.
Executes a SQL statement.
| Param | Type | Description |
|---|---|---|
| sql | string |
The SQL statement string to execute. |
This function is currently not supported.
Closes the database connection.
Executes the SQL statement and returns an info object.
| Param | Type | Description |
|---|---|---|
| bindParameters | array of objects |
The bind parameters for executing the statement. |
The returned info object contains two properties: changes that describes the number of modified rows and info.lastInsertRowid that represents the rowid of the last inserted row.
Executes the SQL statement and returns the first row.
| Param | Type | Description |
|---|---|---|
| bindParameters | array of objects |
The bind parameters for executing the statement. |
Executes the SQL statement and returns an array of the resulting rows.
| Param | Type | Description |
|---|---|---|
| bindParameters | array of objects |
The bind parameters for executing the statement. |
Executes the SQL statement and returns an iterator to the resulting rows.
| Param | Type | Description |
|---|---|---|
| bindParameters | array of objects |
The bind parameters for executing the statement. |
This function is currently not supported.
This function is currently not supported.
This function is currently not supported.
This function is currently not supported.
This function is currently not supported.
This function is currently not supported.