Skip to content

tursodatabase/libsql-ruby

Repository files navigation

libSQL Ruby

libSQL Ruby

Databases for Ruby multi-tenant AI Apps.

Turso · Docs · Blog & Tutorials

MIT License Discord Contributors Examples

Features

Warning

This SDK is currently in technical preview. Join us in Discord to report any issues.

Install

gem install turso_libsql

Quickstart

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

Examples

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.

Documentation

Visit our official documentation.

Support

Join us on Discord to get help using this SDK. Report security issues via email.

Contributors

See the contributing guide to learn how to get involved.

Contributors

good first issue

About

Ruby bindings for libSQL

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published