libsql2 0.1.3-x86_64-darwin
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +161 -0
- data/lib/libsql/3.4/libsql2.bundle +0 -0
- data/lib/libsql/4.0/libsql2.bundle +0 -0
- data/lib/libsql/blob.rb +10 -0
- data/lib/libsql/connection.rb +15 -0
- data/lib/libsql/database.rb +37 -0
- data/lib/libsql/version.rb +5 -0
- data/lib/libsql2.rb +7 -0
- metadata +56 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: d81d65215eb52ef44c5c2024fb70f1b8e26c7199f0f6788ae31cd1a21b032cd8
|
|
4
|
+
data.tar.gz: d2702e8d3741ddc8ed684baff753b35e8d71da70709de6b2161734b8bbeb1e02
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 1e81c70f905e13fd8e3e53a566ebcf74146c02ef1d6ee0ac32fe285121629a6ca1ae71fae66467616f1fa29c8a5de8dc5a208233ac9fea00bf0ddbac02e0503f
|
|
7
|
+
data.tar.gz: 9b0612d82ac1ebada8134c074e854d46694ab08e9329df4f36c1cf224adbee7d47970c068bbde5585c522d52156b800c208ac5482b4dfca6f7516344023e9327
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 speria-jp
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# libsql2
|
|
2
|
+
|
|
3
|
+
An alternative to [turso_libsql](https://github.com/tursodatabase/libsql-ruby) with a native Rust extension.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Native Rust extension** — no FFI overhead
|
|
8
|
+
- **Full libSQL support** — local files, in-memory, remote (Turso Cloud), and Embedded Replicas
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
Add to your Gemfile:
|
|
13
|
+
|
|
14
|
+
```ruby
|
|
15
|
+
gem "libsql2"
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Then run:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
bundle install
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
### Opening a Database
|
|
27
|
+
|
|
28
|
+
```ruby
|
|
29
|
+
require "libsql2"
|
|
30
|
+
|
|
31
|
+
# Local file
|
|
32
|
+
db = Libsql::Database.open("/path/to/file.db")
|
|
33
|
+
|
|
34
|
+
# In-memory
|
|
35
|
+
db = Libsql::Database.open(":memory:")
|
|
36
|
+
|
|
37
|
+
# Remote (Turso Cloud)
|
|
38
|
+
db = Libsql::Database.open("libsql://xxx.turso.io", auth_token: "xxx")
|
|
39
|
+
|
|
40
|
+
# Embedded Replica
|
|
41
|
+
db = Libsql::Database.open("libsql://xxx.turso.io",
|
|
42
|
+
auth_token: "xxx",
|
|
43
|
+
local_path: "/path/to/replica.db",
|
|
44
|
+
sync_interval: 60,
|
|
45
|
+
read_your_writes: true
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
# Block form (auto-close)
|
|
49
|
+
Libsql::Database.open(":memory:") do |db|
|
|
50
|
+
# ...
|
|
51
|
+
end
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Querying
|
|
55
|
+
|
|
56
|
+
```ruby
|
|
57
|
+
db.connect do |conn|
|
|
58
|
+
conn.execute("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, age INTEGER)")
|
|
59
|
+
conn.execute("INSERT INTO users (name, age) VALUES (?, ?)", ["Alice", 30])
|
|
60
|
+
|
|
61
|
+
rows = conn.query("SELECT * FROM users WHERE age > ?", [20])
|
|
62
|
+
rows.columns #=> ["id", "name", "age"]
|
|
63
|
+
rows.types #=> ["INTEGER", "TEXT", "INTEGER"]
|
|
64
|
+
rows.each { |row| puts row["name"] }
|
|
65
|
+
end
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Execute (no result set)
|
|
69
|
+
|
|
70
|
+
```ruby
|
|
71
|
+
conn.execute("INSERT INTO users (name) VALUES (?)", ["Alice"])
|
|
72
|
+
conn.changes #=> 1
|
|
73
|
+
conn.last_insert_rowid #=> 42
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Batch Execution
|
|
77
|
+
|
|
78
|
+
```ruby
|
|
79
|
+
conn.execute_batch(<<~SQL)
|
|
80
|
+
CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT);
|
|
81
|
+
CREATE TABLE posts (id INTEGER PRIMARY KEY, user_id INTEGER, title TEXT);
|
|
82
|
+
SQL
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Prepared Statements
|
|
86
|
+
|
|
87
|
+
```ruby
|
|
88
|
+
stmt = conn.prepare("SELECT * FROM users WHERE name = ?")
|
|
89
|
+
stmt.bind(["Alice"])
|
|
90
|
+
rows = stmt.query
|
|
91
|
+
stmt.close
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Transactions
|
|
95
|
+
|
|
96
|
+
```ruby
|
|
97
|
+
conn.transaction do |tx|
|
|
98
|
+
tx.execute("UPDATE accounts SET balance = balance - 100 WHERE id = ?", [1])
|
|
99
|
+
tx.execute("UPDATE accounts SET balance = balance + 100 WHERE id = ?", [2])
|
|
100
|
+
# Commits on normal exit, rolls back on exception
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# With behavior
|
|
104
|
+
conn.transaction(:immediate) do |tx|
|
|
105
|
+
tx.execute("INSERT INTO orders (item) VALUES (?)", ["widget"])
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# Nested transactions (SAVEPOINT)
|
|
109
|
+
conn.transaction do |tx|
|
|
110
|
+
tx.execute("INSERT INTO users (name) VALUES (?)", ["Alice"])
|
|
111
|
+
tx.transaction do |tx2|
|
|
112
|
+
tx2.execute("INSERT INTO users (name) VALUES (?)", ["Bob"])
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Embedded Replica Sync
|
|
118
|
+
|
|
119
|
+
```ruby
|
|
120
|
+
db.sync # Manual sync
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Fork Safety (Puma / Unicorn)
|
|
124
|
+
|
|
125
|
+
```ruby
|
|
126
|
+
# puma.rb
|
|
127
|
+
on_worker_boot do
|
|
128
|
+
$db.discard! if $db
|
|
129
|
+
$db = Libsql::Database.open(...)
|
|
130
|
+
end
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Type Mapping
|
|
134
|
+
|
|
135
|
+
| libSQL Type | Ruby Type | Notes |
|
|
136
|
+
|---|---|---|
|
|
137
|
+
| INTEGER | `Integer` | Signed 64-bit |
|
|
138
|
+
| REAL | `Float` | Double precision |
|
|
139
|
+
| TEXT | `String` | UTF-8 encoded |
|
|
140
|
+
| BLOB | `Libsql::Blob` | `String` subclass with `ASCII-8BIT` encoding |
|
|
141
|
+
| NULL | `nil` | |
|
|
142
|
+
|
|
143
|
+
## Development
|
|
144
|
+
|
|
145
|
+
Requirements: Ruby >= 3.4, Rust >= 1.74, and a C compiler.
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
bundle install # Install Ruby dependencies
|
|
149
|
+
rake compile # Compile the Rust extension
|
|
150
|
+
rake spec # Run tests
|
|
151
|
+
rake lint # Run all linters (RuboCop + Clippy)
|
|
152
|
+
rake fmt # Auto-format all code
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Contributing
|
|
156
|
+
|
|
157
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/speria-jp/libsql-ruby2.
|
|
158
|
+
|
|
159
|
+
## License
|
|
160
|
+
|
|
161
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
Binary file
|
|
Binary file
|
data/lib/libsql/blob.rb
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Libsql
|
|
4
|
+
class Connection
|
|
5
|
+
def transaction
|
|
6
|
+
execute("BEGIN")
|
|
7
|
+
result = yield self
|
|
8
|
+
execute("COMMIT")
|
|
9
|
+
result
|
|
10
|
+
rescue Exception # rubocop:disable Lint/RescueException
|
|
11
|
+
execute("ROLLBACK")
|
|
12
|
+
raise
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Libsql
|
|
4
|
+
class Database
|
|
5
|
+
class << self
|
|
6
|
+
alias _open open
|
|
7
|
+
|
|
8
|
+
def open(path, **opts)
|
|
9
|
+
db = opts.empty? ? _open(path) : _open(path, opts)
|
|
10
|
+
if block_given?
|
|
11
|
+
begin
|
|
12
|
+
yield db
|
|
13
|
+
ensure
|
|
14
|
+
db.close
|
|
15
|
+
end
|
|
16
|
+
else
|
|
17
|
+
db
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
alias _connect connect
|
|
23
|
+
|
|
24
|
+
def connect
|
|
25
|
+
conn = _connect
|
|
26
|
+
if block_given?
|
|
27
|
+
begin
|
|
28
|
+
yield conn
|
|
29
|
+
ensure
|
|
30
|
+
conn.close
|
|
31
|
+
end
|
|
32
|
+
else
|
|
33
|
+
conn
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
data/lib/libsql2.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: libsql2
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.3
|
|
5
|
+
platform: x86_64-darwin
|
|
6
|
+
authors:
|
|
7
|
+
- speria-jp
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-03-17 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Native Ruby bindings for libSQL database, built with Rust (magnus + libsql
|
|
14
|
+
crate)
|
|
15
|
+
email:
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- LICENSE
|
|
21
|
+
- README.md
|
|
22
|
+
- lib/libsql/3.4/libsql2.bundle
|
|
23
|
+
- lib/libsql/4.0/libsql2.bundle
|
|
24
|
+
- lib/libsql/blob.rb
|
|
25
|
+
- lib/libsql/connection.rb
|
|
26
|
+
- lib/libsql/database.rb
|
|
27
|
+
- lib/libsql/version.rb
|
|
28
|
+
- lib/libsql2.rb
|
|
29
|
+
homepage: https://github.com/speria-jp/libsql-ruby2
|
|
30
|
+
licenses:
|
|
31
|
+
- MIT
|
|
32
|
+
metadata:
|
|
33
|
+
rubygems_mfa_required: 'true'
|
|
34
|
+
post_install_message:
|
|
35
|
+
rdoc_options: []
|
|
36
|
+
require_paths:
|
|
37
|
+
- lib
|
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
39
|
+
requirements:
|
|
40
|
+
- - ">="
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: '3.4'
|
|
43
|
+
- - "<"
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: 4.1.dev
|
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
47
|
+
requirements:
|
|
48
|
+
- - ">="
|
|
49
|
+
- !ruby/object:Gem::Version
|
|
50
|
+
version: '0'
|
|
51
|
+
requirements: []
|
|
52
|
+
rubygems_version: 3.5.23
|
|
53
|
+
signing_key:
|
|
54
|
+
specification_version: 4
|
|
55
|
+
summary: Ruby bindings for libSQL
|
|
56
|
+
test_files: []
|