https://github.com/tursodatabase/libsql-ruby
Ruby bindings for libSQL
https://github.com/tursodatabase/libsql-ruby
Last synced: 8 months ago
JSON representation
Ruby bindings for libSQL
- Host: GitHub
- URL: https://github.com/tursodatabase/libsql-ruby
- Owner: tursodatabase
- Created: 2024-10-11T00:25:02.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-10-22T14:27:59.000Z (about 1 year ago)
- Last Synced: 2024-10-23T16:42:26.946Z (about 1 year ago)
- Language: Ruby
- Size: 57.3 MB
- Stars: 10
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
libSQL Ruby
Databases for Ruby multi-tenant AI Apps.
Turso ยท
Docs ยท
Blog & Tutorials
## Features
- ๐ Works offline with [Embedded Replicas](https://docs.turso.tech/features/embedded-replicas/introduction)
- ๐ Works with remote Turso databases
- โจ Works with Turso [AI & Vector Search](https://docs.turso.tech/features/ai-and-embeddings)
> [!WARNING]
> This SDK is currently in technical preview. Join us in Discord to report any issues.
## Install
```bash
gem install turso_libsql
```
## Quickstart
The example below uses Embedded Replicas and syncs data every 1000ms from Turso.
```rb
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](examples/local.rb) | Uses libsql with a local SQLite file. Creates database, inserts data, and queries. |
| [remote](examples/remote.rb) | Connects to a remote database. Requires environment variables for URL and auth token. |
| [sync](examples/sync.rb) | Demonstrates synchronization between local and remote databases. |
| [transactions](examples/transactions.rb) | Shows transaction usage: starting, performing operations, and committing/rolling back. |
| [memory](examples/memory.rb) | Uses an in-memory SQLite database for temporary storage or fast access. |
| [vector](examples/vector.rb) | Works with vector embeddings, storing and querying for similarity search. |
| [encryption](examples/encryption.rb) | Creates and uses an encrypted SQLite database, demonstrating setup and data operations. |
## Documentation
Visit our [official documentation](https://docs.turso.tech).
## Support
Join us [on Discord](https://tur.so/discord-ruby) to get help using this SDK. Report security issues [via email](mailto:security@turso.tech).
## Contributors
See the [contributing guide](CONTRIBUTING.md) to learn how to get involved.
