Turso Quickstart (Ruby)
Get started with Turso and Ruby using the libSQL client in a few simple steps.
This is currently in technical preview. Join us in Discord to report any issues.
In this Ruby quickstart we will learn how to:
- Retrieve database credentials
- Install the libSQL package
- Connect to a local or remote Turso database
- Execute a query using SQL
- Sync changes to local database (optional)
Retrieve database credentials
You will need an existing database to continue. If you don’t have one, create one.
Get the database URL:
Get the database authentication token:
Assign credentials to the environment variables inside .env
.
Install
Inside your Ruby project, install the following Rubygem:
Connect
You must first initialize libSQL, create a libsql_database_t
object, and then open a libsql_connection_t
to it:
Execute
You can execute a SQL query against your existing database by preparing a statement and then executing it:
If you need to use placeholders for values, you can do that:
Sync (Embedded Replicas only)
When using embedded replicas, you should call sync
on the database to sync your local database with the primary database, unless you are using sync_interval
(though there is no issue with calling sync
with sync_interval
enabled):
Was this page helpful?