Turso Quickstart (ActiveRecord)
Get started with Turso and ActiveRecord 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 ActiveRecord gem
- Connect to a local or remote Turso database
- Define and create models
- Perform basic CRUD operations
- Execute raw SQL queries
- Work with migrations
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
In your Ruby project, add the following gems to your Gemfile:
Then run:
Connect
Create a Ruby file (e.g., database.rb
) to set up the database connection:
Define models
Create model files for your database tables. For example, product.rb
:
Create and execute a migration
Create a migration file (e.g., 001_create_products.rb
):
Execute the migration:
Execute
Perform some basic CRUD operations:
Work with associations
Define associations in your models:
Use associations in your code:
Was this page helpful?