Commit Graph

91 Commits

Author SHA1 Message Date
Pekka Enberg
475799b3e9 Unify JavaScript package README files 2025-08-12 19:30:02 +03:00
Pekka Enberg
97ad901d96 Merge 'simple README with warning' from Nikita Sivukhin
Closes #2562
2025-08-12 18:24:53 +03:00
Pekka Enberg
2e79333de4 Merge 'turso-sync: fix schema bug' from Nikita Sivukhin
This PR fixes few issues in turso-sync-engine implementation:
1. One step of `pull` implementation works like this:
   a. Start write WAL session
   b. Revert local changes in WAL
   c. Replay WAL frames from remote DB
   d. Replay WAL frames produced by local changes applied to the remote
DB copy (`synced`)
My initial thinking was that by executing step (d) we will get the same
schema as before (with same schema cookie) and everything will be fine.
With more deep thinking we can see that it's not fine - as after step
(d) tables created locally can change their root pages (if they were
created locally, for example) - and DB will have "broken" schema
2. Sync engine execute few SQL statements and do not run them to
completion - which basically created "orphaned" locks
In order to fix (1) I decided to introduce another `conn_raw_api`
extension which allows to read and write schema cookie directly in the
transaction. So, the process described above adds step (e) which set
schema cookie to the value strictly greater than the value before.
In order to fix (2) I just fixed all places where statement were dropped
before running to completion.
These fixes are merged together because I explored them by fixing one
new test: `test_sync_single_db_many_pulls_big_payloads`

Closes #2561
2025-08-12 18:24:46 +03:00
Nikita Sivukhin
02bb891104 add npm badge 2025-08-12 18:55:39 +04:00
Nikita Sivukhin
35b51d8302 simple README with warning 2025-08-12 18:52:58 +04:00
Nikita Sivukhin
bf2a01866c fix clippy 2025-08-12 18:33:12 +04:00
Nikita Sivukhin
d3a27ee311 fix sync engine 2025-08-12 18:30:16 +04:00
Pekka Enberg
5a65617602 Turso 0.1.4-pre.7 2025-08-12 17:01:47 +03:00
Pekka Enberg
bfefa44632 Merge 'turso-sync: support updates and schema changes' from Nikita Sivukhin
Add support for schema changes and granular updates in the
`DatabaseTape` and turso-sync-engine
Now, schema changes made locally will be replicated to the remote too.
Also, `UPDATE`s made locally will touch only changed columns (before we
did `DELETE` + `INSERT` which can overwrite non-conflicting changes from
another device to the same row).
Note, that schema changes replication for now can be pretty dangerous,
as we can't extract proper schema at some moment in time from turso_cdc
and always use latest schema columns. This means that it's better to
avoid `ALTER TABLE ...` to be executed locally, but basic DDL like
`CREATE TABLE / CREATE INDEX / DROP TABLE / DROP INDEX` will work fine
(as columns only appear/disappear for schema in this case).

Closes #2540
2025-08-12 09:50:26 +03:00
Nikita Sivukhin
aa5de7b8bd fix clippy 2025-08-11 17:02:36 +04:00
Nikita Sivukhin
eb40d4aff6 remove turso-sync as now we have turso-sync-engine 2025-08-11 16:53:39 +04:00
Nikita Sivukhin
372d23b7cc handle schema changes in sync engine 2025-08-11 16:52:18 +04:00
Nikita Sivukhin
5e773d286e support UPDATEs and schema changes in database tape 2025-08-11 16:50:59 +04:00
PThorpe92
84ffed709a Round up allocation for wal frame arena to next page multiple of 64 2025-08-08 10:55:29 -04:00
Pekka Enberg
81da795a66 Turso 0.1.4-pre.6 2025-08-08 16:50:24 +03:00
Nikita Sivukhin
d2a8162e10 sync bootstrapped files in the end 2025-08-08 16:40:29 +04:00
Nikita Sivukhin
2ccdafd2a5 update sync engine wrapper 2025-08-08 16:40:19 +04:00
Nikita Sivukhin
3f0162307f configure cargo for napi-rs 2025-08-08 15:45:05 +04:00
Nikita Sivukhin
d25acf3c2c small adjustments in the sync engine js 2025-08-08 15:44:42 +04:00
Nikita Sivukhin
ca20af6f89 fix package.json 2025-08-08 15:44:42 +04:00
Nikita Sivukhin
4595d5b7a3 fix Cargo.toml 2025-08-08 15:44:42 +04:00
Nikita Sivukhin
50588c5edf cargo fmt 2025-08-08 15:44:42 +04:00
Nikita Sivukhin
572a910c52 add simple example 2025-08-08 15:44:42 +04:00
Nikita Sivukhin
3c181939ad adjust js package 2025-08-08 15:44:42 +04:00
Nikita Sivukhin
e6a3ee59d2 turso-sync-js package 2025-08-08 15:44:41 +04:00
Nikita Sivukhin
405e7f56a6 small adjustments in the sync-engine 2025-08-08 15:40:57 +04:00
Pekka Enberg
b603ee7062 Merge 'JavaScript improvements' from Pekka Enberg
Closes #2467
2025-08-07 14:01:07 +03:00
Nikita Sivukhin
bfacc141b0 remove unnecessary change 2025-08-06 22:09:29 +04:00
Nikita Sivukhin
ae0dff6a55 cargo clippy --tests --fix 2025-08-06 22:09:29 +04:00
Nikita Sivukhin
09daa97150 format fixes 2025-08-06 21:53:03 +04:00
Nikita Sivukhin
b1f1526673 add DB file for tests 2025-08-06 21:47:18 +04:00
Nikita Sivukhin
253b4933f7 more small fixes 2025-08-06 19:30:16 +04:00
Nikita Sivukhin
1763e9bbf9 small fixes 2025-08-06 19:26:55 +04:00
Nikita Sivukhin
b612259a3a more friendly copmletely runtime agnostic turso-sync-engine crate 2025-08-06 19:26:55 +04:00
Pekka Enberg
53acd22950 serverless: Fix Statement.all() in expanded mode 2025-08-06 09:22:35 +03:00
Pekka Enberg
2a36d133e3 serverless: Improve pragma() after close() error 2025-08-06 09:09:47 +03:00
Pekka Enberg
c9cec67d94 serverless: Improve exec() after close() error 2025-08-06 08:08:19 +03:00
Pekka Enberg
f53adab4a8 serverless: Improve error when prepare() called after close() 2025-08-06 07:50:12 +03:00
Nikita Sivukhin
d504f9b1ac fix turso-sync tests 2025-08-06 01:03:49 +04:00
Nikita Sivukhin
2e23230e79 extend raw WAL API with few more methods
- try_wal_watermark_read_page - try to read page from the DB with given WAL watermark value
- wal_changed_pages_after - return set of unique pages changed after watermark WAL position
2025-08-04 16:55:50 +04:00
Nikita Sivukhin
83b1e99a61 fix compilation 2025-08-04 12:53:07 +04:00
Nikita Sivukhin
0adb40534c hind dangerous methods behind conn_raw_api feature 2025-08-04 12:40:28 +04:00
Pekka Enberg
29688e69d1 serverless: v0.1.1 2025-08-01 15:56:39 +03:00
Pekka Enberg
47860b6df5 serverless: Fix bind parameters 2025-08-01 14:21:04 +03:00
Pekka Enberg
335d4a19c8 serverless: Implement Statement.raw() 2025-08-01 14:19:54 +03:00
Pekka Enberg
86581197bf serverless: Fix Statement.get() to return undefined
...aligns with the native bindings semantics.
2025-08-01 14:01:44 +03:00
Pekka Enberg
9bd053033a serverless: Fix Connection.run() implementation 2025-07-30 21:42:45 +03:00
Pekka Enberg
fff7bf52f3 serverless: Add support for named parameters 2025-07-30 21:42:45 +03:00
Pekka Enberg
1b8d95a79f serverless: Implement Connection.close() 2025-07-30 21:42:45 +03:00
Pekka Enberg
d0f57584ad Merge 'turso-sync: bidirectional sync for local db' from Nikita Sivukhin
This PR introduces initial protocol for bidirectional sync with conflict
resolution.
The main addition to the usual `Database` interface are two methods:
1. `push` - push all local changes to the remote. Note, that new changes
from the remote will not be visible during request execution after this
procedure.
2. `pull` - pull all remote changes and apply them locally. Note, that
this procedure require temporary block of writes to the local DB as
internally we will manipulate with opened connections and juggle with
few things under the hood.
## Limitations
* Current implementation exposes only query methods on top of the
**database** - because more careful orchestration will be needed when we
will expose `Connection` and `Statement`
* Schema changes are possible to make through synced Database - but they
are actually not synced to the remote
* Current implementation will amplify storage use by 2x
## Implementation overview
Current approach uses pretty stupid idea to maintain 2 copies of the
database and WAL files:
1. `Draft` - this copy will hold local changes and accept all writes
made to the database
2. `Synced` - this copy will hold DB file and WAL synced with remote
This obviously lead to 2x space amplification, but allow us to implement
sync with conflict resolution without changing `turso-core`.
Under the hood, implementation of main operations looks like this:
1. `push`:
  a. Pull all recent changes from the remote to `Synced` DB
  b. Transfer local changes from `Draft` to `Synced` with the help of
CDC table
  c. Push new WAL frames from `Synced` DB to remote
2. `pull`:
  a. Pull all recent changes from the remote to `Synced` DB
  b. Transfer local changes from `Draft` to `Synced` with the help of
CDC table
  c. Copy `Synced` files (DB and WAL) to the `Draft`
  d. Reset `Synced` WAL in order to remove frames made by local changes
from it
As operation 2.c can't be made safely without extra work - `turso-sync`
package internally maintains `active` database which can be either
`Draft` or `Synced` and switch will happen exactly before/after step 2.c
as we will need to move all requests from `Draft` DB to `Synced` due to
explicit copy which we will need to perform.
This switch between Databases creates additional troubles and that's why
in this PR only `Database::query` and `Database::execute` methods are
exposed without prepared statements.
<img width="2062" height="977" alt="Untitled-2025-07-14-1259"
src="https://github.com/user-
attachments/assets/64eb5046-d7cb-4af2-87a0-810c0db7eeb5" />
<img width="2062" height="977" alt="Untitled-2025-07-14-1259(1)"
src="https://github.com/user-
attachments/assets/5c20360c-41db-4100-b0ff-9e47c2682e56" />

Closes #2334
2025-07-30 16:54:21 +03:00