Databases for Ruby multi-tenant AI Apps.
Turso · Docs · Blog & Tutorials
- 🔌 Works offline with Embedded Replicas
- 🌎 Works with remote Turso databases
- ✨ Works with Turso AI & Vector Search
Warning
This SDK is currently in technical preview. Join us in Discord to report any issues.
gem install turso_libsql
The example below uses Embedded Replicas and syncs data every 1000ms from Turso.
require_relative 'turso_libsql'
db =
Libsql::Database.new(
path: 'local.db',
url: ENV['TURSO_DATABASE_URL'],
auth_token: ENV['TURSO_AUTH_TOKEN'],
sync_interval: 1000
)
db.sync
db.connect do |conn|
conn.execute_batch <<-SQL
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT
);
INSERT INTO users (name) VALUES ('Iku');
SQL
rows = conn.query 'SELECT * FROM users'
print "Users: #{rows.to_a}\n"
rows.close
end
Example | Description |
---|---|
local | Uses libsql with a local SQLite file. Creates database, inserts data, and queries. |
remote | Connects to a remote database. Requires environment variables for URL and auth token. |
sync | Demonstrates synchronization between local and remote databases. |
transactions | Shows transaction usage: starting, performing operations, and committing/rolling back. |
memory | Uses an in-memory SQLite database for temporary storage or fast access. |
vector | Works with vector embeddings, storing and querying for similarity search. |
encryption | Creates and uses an encrypted SQLite database, demonstrating setup and data operations. |
Visit our official documentation.
Join us on Discord to get help using this SDK. Report security issues via email.
See the contributing guide to learn how to get involved.