beagle-turso 0.1.2-x86_64-linux → 0.2.0-x86_64-linux

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d56ea88bf691a9947919b8a865b14e960692b2381225a4e75fb4083be2a9e75a
4
- data.tar.gz: 9679039fe4536f780c57a61388c4a75cc0e236b0522d74c3688f861361588e3c
3
+ metadata.gz: c9a414905622147215ada0d6468ba75ea3ccc1c7ad1161011356bed522d1cb47
4
+ data.tar.gz: 3907e2eeff8f6e946fabf5fc51bfa2320c2dc8afebbde9ae0a25dcbb2c04a83a
5
5
  SHA512:
6
- metadata.gz: edce357863a3860a808e41a30d5ef5a1cfc91069a766d08f5d00029da871dc32e4763518e38ef034229de9f4247ca67cba9f37074e6b3b4f9b364b2c0f7fb06f
7
- data.tar.gz: ace7af300cc06e1fe4dfe89d21af57444a911f29561e8ea9a5376133172682257b372277ba16da751604303936328d6eab0d2bc1fa4d5d61d6df3ff974457493
6
+ metadata.gz: 486be1702ab47bec0f78693a94f8a7e946c45566fca0188a52d93bf7ed54fcdc6551f0837586f39c4fc6c5701ce368660896c2236be84cf6caae956123149e52
7
+ data.tar.gz: 2e154353c97bafe378bd278ea74af7de472c3c6a5b747ff592ee8be0dd863011f66c40d3a343e2f08d2d3defc952dd3423d81f384293853815d3a0963dbf8be9
data/README.md CHANGED
@@ -68,7 +68,8 @@ db.pull # pull remote changes down to the local file (returns true/false)
68
68
  `Database.open` also accepts `bootstrap_if_empty:` (defaults to `true`),
69
69
  which pulls all remote data down on first open if the local file is new/empty.
70
70
  Calling `push`/`pull` on a database opened via `open_local` (or via `open`
71
- without both `remote_url:` and `auth_token:`) raises `RuntimeError`.
71
+ without both `remote_url:` and `auth_token:`) raises
72
+ `Beagle::Turso::NotSyncedError`.
72
73
 
73
74
  ### Durability note: writes commit on-sync, not synchronously
74
75
 
@@ -79,6 +80,78 @@ called; `push` is not called automatically after every write. Until a
79
80
  `push` succeeds, a write that's durable locally is not yet visible to other
80
81
  replicas of the same remote database.
81
82
 
83
+ ## Which Turso database?
84
+
85
+ Point a synced database at a Turso database **dedicated to this engine** —
86
+ ideally a fresh, empty one. On first open of an empty local replica,
87
+ `bootstrap_if_empty` pulls the remote down; against a fresh remote that's a
88
+ clean start, and the engine then manages its own state in that database (it
89
+ creates `turso_cdc`, `__turso_internal_*`, and `turso_sync_last_change_id`
90
+ tables and takes an **exclusive lock** on the local replica file — only one
91
+ OS process may hold a given replica open at a time).
92
+
93
+ Two things to avoid:
94
+
95
+ - **Don't co-host a synced database with the legacy libSQL/Hrana driver.**
96
+ This engine (Turso's newer Rust core) and the classic libSQL client have
97
+ different write/sync models; running both against the same remote database
98
+ at once risks corrupting its sync state. Give this engine its own database.
99
+ - **Migrating an existing, populated libSQL database into the synced engine
100
+ is not validated.** A fresh database is the supported, tested path. If you
101
+ must adopt existing data, treat it as unproven — test push/pull round-trips
102
+ before relying on it.
103
+
104
+ A single remote database, dedicated to this engine and written by one process
105
+ at a time, is the model it's built for.
106
+
107
+ ## Errors
108
+
109
+ Every error the driver raises is a `Beagle::Turso::Error`, a `RuntimeError`
110
+ subclass: `OpenError`, `ConnectError`, `QueryError`, `SyncError`,
111
+ `NotSyncedError` (push/pull on a local-only database), `BusyError` (another
112
+ session or process holds the database), `ClosedError` and `ForkedError`. An
113
+ unsupported bind parameter type raises Ruby's `TypeError`. Auth, network and
114
+ protocol failures during sync all arrive as `SyncError` (or `OpenError` at
115
+ open): the engine does not distinguish them. Messages never contain the auth
116
+ token.
117
+
118
+ Busy conditions now raise `BusyError` with a message beginning
119
+ `database is busy:` (0.1.x said `query failed:` / `sync failed:`); it is
120
+ still a `RuntimeError`. A replica file already held by another process raises
121
+ `OpenError` ("... File is locked by another process").
122
+
123
+ ## Threads, fibers and fork
124
+
125
+ - One `Database` may be shared by threads. Give each thread its own
126
+ `Connection`; a shared `Connection` works but serializes its callers.
127
+ - `open`, `connect`, `push` and `pull` release the GVL, so other threads keep
128
+ running while they wait on the network. Queries keep it; they are local and
129
+ fast.
130
+ - While one thread pushes, `closed?` returns immediately on other threads, and
131
+ queries on other connections proceed.
132
+ - On a synced database, `connect` called while another thread is pushing waits
133
+ inside the engine until the push finishes (about the push's duration); the
134
+ GVL is released while it waits, so other threads and fibers keep running.
135
+ Open connections up front (e.g. at boot / pool warm-up) rather than per
136
+ request.
137
+ - `close` during an in-flight `push` is safe: the push finishes or raises, and
138
+ later calls raise `ClosedError`.
139
+ - A blocked native call cannot be interrupted: `Timeout` and `Thread#kill`
140
+ take effect when it returns.
141
+ - **Falcon / Async:** on Ruby 4.0+ with `async` 2.25+ (enable its worker pool
142
+ with `ASYNC_SCHEDULER_WORKER_POOL=true` or
143
+ `Async::Scheduler.new(worker_pool: true)`), a fiber scheduler runs these
144
+ calls on a worker thread, so the reactor keeps serving other requests during
145
+ a sync. On Ruby 3.3/3.4 the GVL is still released, but the scheduler's own
146
+ thread blocks. Run sync from a dedicated thread there. Run one Falcon
147
+ process per replica (`--count 1`): the replica file is locked to one
148
+ process.
149
+ - **Fork:** handles are bound to the process that opened them. In a forked
150
+ child, `open`, `connect`, `push`, `pull` and queries on an inherited handle
151
+ raise `ForkedError`; open a new database there. `close` is a no-op and
152
+ `closed?` is safe (it reports the handle as closed if it can't be inspected),
153
+ so inherited handles need no cleanup in the child.
154
+
82
155
  ## Credential safety
83
156
 
84
157
  `auth_token` is never included in `inspect` output or in error messages —
@@ -0,0 +1,19 @@
1
+ module Beagle
2
+ module Turso
3
+ # Base class for every error the native driver raises. A RuntimeError so
4
+ # code written against 0.1.x, which raised bare RuntimeErrors, still rescues.
5
+ class Error < RuntimeError; end
6
+
7
+ class OpenError < Error; end
8
+ class ConnectError < Error; end
9
+ class QueryError < Error; end
10
+ class SyncError < Error; end
11
+ # push/pull on a database opened without remote_url:/auth_token:.
12
+ class NotSyncedError < Error; end
13
+ # The engine reported the database busy (another session or process holds it).
14
+ class BusyError < Error; end
15
+ class ClosedError < Error; end
16
+ # A handle opened in a parent process was used after fork; open a new one.
17
+ class ForkedError < Error; end
18
+ end
19
+ end
@@ -1,5 +1,5 @@
1
1
  module Beagle
2
2
  module Turso
3
- VERSION = "0.1.2"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
data/lib/beagle/turso.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require_relative "turso/version"
2
+ require_relative "turso/errors"
2
3
 
3
4
  # Load the native extension. Precompiled ("fat") gems ship the .so under a
4
5
  # per-Ruby-ABI subdir (lib/beagle_turso/<major.minor>/beagle_turso.so); a
@@ -1,4 +1,4 @@
1
1
  [diffend] Oversized file quarantined before diffing.
2
2
  name: data/lib/beagle_turso/3.3/beagle_turso.so
3
- size: 35938528 bytes
4
- sha256: 52b12b9b3b58fb0f3f6438be08068270f54ff18179179a611670c144dabe8aba
3
+ size: 38708488 bytes
4
+ sha256: 57e4e18e36c8b5550807b59e7384df1a82f3c655544ebbe7040514c16f91f00a
@@ -1,4 +1,4 @@
1
1
  [diffend] Oversized file quarantined before diffing.
2
2
  name: data/lib/beagle_turso/3.4/beagle_turso.so
3
- size: 35937424 bytes
4
- sha256: b9db8588042725da1badc5086fb4a3d9e0c31c841b08648e7a96aa2a54a95913
3
+ size: 38707144 bytes
4
+ sha256: 834b26f7b9909eb50695ca0243106837d6f2e853644b57fec475cacebb9ad853
@@ -1,4 +1,4 @@
1
1
  [diffend] Oversized file quarantined before diffing.
2
2
  name: data/lib/beagle_turso/4.0/beagle_turso.so
3
- size: 35937392 bytes
4
- sha256: 575c528845059b116e9d93a2a9913529296fc1d5f41d7754177501a04a63ec71
3
+ size: 38707136 bytes
4
+ sha256: 02cef85a056b22d560ac68916f12379efc3ef26d9e4437211b2cb838072313f8
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beagle-turso
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: x86_64-linux
6
6
  authors:
7
7
  - BeagleSoftwareUK
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-08-08 00:00:00.000000000 Z
11
+ date: 2026-10-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  A Ruby driver for Turso's database engine, backed by a native Rust
@@ -24,6 +24,7 @@ extra_rdoc_files: []
24
24
  files:
25
25
  - README.md
26
26
  - lib/beagle/turso.rb
27
+ - lib/beagle/turso/errors.rb
27
28
  - lib/beagle/turso/version.rb
28
29
  - lib/beagle_turso/3.3/beagle_turso.so
29
30
  - lib/beagle_turso/3.4/beagle_turso.so