Commit Graph

56 Commits

Author SHA1 Message Date
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
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
Nikita Sivukhin
f3da874fd5 fix clippy 2025-07-30 14:38:29 +04:00
Nikita Sivukhin
aad0460bd1 rename methods 2025-07-30 14:23:18 +04:00
Nikita Sivukhin
16ed251cc5 remove turso_assert 2025-07-30 14:18:47 +04:00
Nikita Sivukhin
2b5dbba2df set tokio_unstable cfg at workspace root
- cargo commands invoked from workspace root do not capture custom configuration of RUSTFLAGS
  from workspace members
- see relevant issue https://github.com/rust-lang/cargo/issues/7004
2025-07-30 14:13:41 +04:00
Nikita Sivukhin
b78ce17022 properly configure TLS and use default features for rustls/hyper-rustls deps 2025-07-30 11:47:36 +04:00
Nikita Sivukhin
d341ac1d10 fix clippy 2025-07-30 02:10:18 +04:00
Nikita Sivukhin
979299d5b7 add binary asset 2025-07-30 01:56:57 +04:00
Nikita Sivukhin
7cf296c7ab update deps 2025-07-30 00:58:36 +04:00
Nikita Sivukhin
63968ff522 add simple example 2025-07-30 00:58:36 +04:00
Nikita Sivukhin
f08417af6c add lib 2025-07-30 00:58:36 +04:00
Nikita Sivukhin
43bbc34455 add public interface for synced database 2025-07-30 00:58:36 +04:00
Nikita Sivukhin
fedecd8e60 add main implementation of synced database 2025-07-30 00:58:36 +04:00
Nikita Sivukhin
a47582c62b add more errors specific to sync 2025-07-30 00:58:36 +04:00
Nikita Sivukhin
7481573cf1 add test to the DatabaseTape 2025-07-30 00:58:36 +04:00
Nikita Sivukhin
4269a1fe7a add helper WalSession RAII-wrapper 2025-07-30 00:58:36 +04:00
Nikita Sivukhin
e0aeb032f0 add sync server module 2025-07-30 00:58:36 +04:00
Nikita Sivukhin
241cad65cd add filesystem module 2025-07-30 00:58:36 +04:00
Nikita Sivukhin
da287f84b1 add blocking implementation of filesystem for tests 2025-07-30 00:58:36 +04:00
Nikita Sivukhin
904eef7628 add tokio-based implementation of filesystem 2025-07-30 00:58:36 +04:00
Nikita Sivukhin
649cc3f367 add local implementation of sync server for tests 2025-07-30 00:58:36 +04:00
Nikita Sivukhin
9c5a849f19 add implementation of TursoSyncServer 2025-07-30 00:58:36 +04:00
Nikita Sivukhin
949801951e add local database metadata 2025-07-30 00:58:36 +04:00
Nikita Sivukhin
db2f8fa61c add TestContext in order to simplify fault injection 2025-07-30 00:58:36 +04:00
Pekka Enberg
c34f9de4ea serverless: Add URL validation on Connection constructor 2025-07-29 16:09:49 +03:00
Pekka Enberg
f48b22a52f Merge 'Javascript API improvements' from Pekka Enberg
Various improvements:
- Make promise API the default for `@tursodatabase/turso`
- Add a compatibility test suite for database, serverless, and better-
sqlite3
- Improve serverless driver a bit to be more compatible.

Closes #2322
2025-07-29 15:55:53 +03:00
Pekka Enberg
ee58a0bf32 serverless: Implement Connection.pragma() 2025-07-29 15:00:23 +03:00
Pekka Enberg
4841bfd78a serverless: Fix Connection.exec()
We need to use sequence requests to handle multiple SQL statements for exec():

```
  DatabaseError {
    message: 'SQL string contains more than one statement',
  }
```
2025-07-29 14:56:14 +03:00
Pekka Enberg
43fd44aa1a serverless: Rename execute() to exec()
Let's follow the main JavaScript API convention. Note that libSQL compatibility stays the same.
2025-07-29 14:39:16 +03:00
Nikita Sivukhin
4d6fe905b8 fix clippy 2025-07-29 14:42:10 +04:00
Nikita Sivukhin
4b893d1631 small fixes 2025-07-29 14:42:09 +04:00
Nikita Sivukhin
4dc217c41a fix clippy 2025-07-29 14:41:35 +04:00
Nikita Sivukhin
134d5e8e2e add simple readme 2025-07-29 14:41:35 +04:00
Nikita Sivukhin
58134052e6 cleanup cargo.toml 2025-07-29 14:41:35 +04:00
Nikita Sivukhin
ea2f9faa13 fix build 2025-07-29 14:41:10 +04:00
Nikita Sivukhin
40ded34ef6 add internal DatabaseTape types 2025-07-29 14:40:14 +04:00