Skip to main content
In this TypeScript quickstart you will learn how to:
  • Retrieve database credentials
  • Install the libSQL client
  • Connect to a remote Bunny Database
  • Execute a query using SQL

Quickstart

1

Retrieve database credentials

You will need an existing database to continue. If you don’t have one, create one.Navigate to Dashboard > Edge Platform > Database > [Select Database] > Access to find your database URL and generate an access token.
You should store these as environment variables to keep them secure.
2

Install @libsql/client

Install the libSQL client package:
3

Initialize a new client

Create a client instance with your database URL and auth token:
4

Execute a query using SQL

You can execute a SQL query against your database by calling execute():
If you need to use placeholders for values, you can do that:

Using with Bunny Edge Scripting

You can connect Edge Scripts to your database by adding credentials as environment variables directly from the database dashboard. See Edge Scripting for step-by-step instructions on connecting your script to Bunny Database.
When using Edge Scripting, your database credentials are automatically available as BUNNY_DATABASE_URL and BUNNY_DATABASE_AUTH_TOKEN environment variables after generating a token from the database dashboard.

Using with Magic Containers

You can connect Magic Container apps to your database by adding credentials as environment variables directly from the database dashboard. See Magic Containers for step-by-step instructions on connecting your app to Bunny Database.
When using Magic Containers, your database credentials are automatically available as BUNNY_DATABASE_URL and BUNNY_DATABASE_AUTH_TOKEN environment variables after generating a token from the database dashboard.

Response

Each query method returns a Promise<ResultSet>:

Placeholders

libSQL supports the use of positional and named placeholders within SQL statements:
libSQL supports the same named placeholder characters as SQLite — :, @ and $.

Batch Transactions

A batch consists of multiple SQL statements executed sequentially within an implicit transaction. The backend handles the transaction: success commits all changes, while any failure results in a full rollback with no modifications.

Transaction Modes

Interactive Transactions

Interactive transactions in SQLite ensure the consistency of a series of read and write operations within a transaction’s scope. These transactions give you control over when to commit or roll back changes, isolating them from other client activity.
Interactive transactions in libSQL lock the database for writing until committed or rolled back, with a 5-second timeout. They can impact performance on high-latency or busy databases.