Skip to content

Drift web support #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,23 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline

Packages with breaking changes:

- There are no breaking changes in this release.
- There are no breaking changes in this release.

Packages with other changes:

- [`sqlite_async` - `v0.8.1`](#sqlite_async---v081)
- [`drift_sqlite_async` - `v0.1.0-alpha.3`](#drift_sqlite_async---v010-alpha3)
- [`sqlite_async` - `v0.8.1`](#sqlite_async---v081)
- [`drift_sqlite_async` - `v0.1.0-alpha.4`](#drift_sqlite_async---v010-alpha4)

Packages with dependency updates only:

> Packages listed below depend on other packages in this workspace that have had changes. Their versions have been incremented to bump the minimum dependency versions of the packages they depend upon in this project.

- `drift_sqlite_async` - `v0.1.0-alpha.3`
#### `drift_sqlite_async` - `v0.1.0-alpha.4`

- **FEAT**: web support.

---

#### `sqlite_async` - `v0.8.1`

- **FEAT**: use navigator locks.

- **FEAT**: use navigator locks.
6 changes: 5 additions & 1 deletion packages/drift_sqlite_async/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
## 0.1.0-alpha.4

- Import `sqlite3_common` instead of `sqlite3` for web support.

## 0.1.0-alpha.3

- Update a dependency to the latest release.
- Update a dependency to the latest release.

## 0.1.0-alpha.2

Expand Down
24 changes: 22 additions & 2 deletions packages/drift_sqlite_async/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
`drift_sqlite_async` allows using drift on an sqlite_async database - the APIs from both can be seamlessly used together in the same application.

Supported functionality:

1. All queries including select, insert, update, delete.
2. Transactions and nested transactions.
3. Table updates are propagated between sqlite_async and Drift - watching queries works using either API.
4. Select queries can run concurrently with writes and other select statements.


## Usage

Use `SqliteAsyncDriftConnection` to create a DatabaseConnection / QueryExecutor for Drift from the sqlite_async SqliteDatabase:
Expand Down Expand Up @@ -59,4 +59,24 @@ These events are only sent while no write transaction is active.

Within Drift's transactions, Drift's own update notifications will still apply for watching queries within that transaction.

Note: There is a possibility of events being duplicated. This should not have a significant impact on most applications.
Note: There is a possibility of events being duplicated. This should not have a significant impact on most applications.

## Web

Note: Web support is currently in Beta.

Web support requires Sqlite3 WASM and web worker Javascript files to be accessible. These file need to be put into the `web/` directory of your app.

The compiled web worker files can be found in our Github [releases](https://github.com/powersync-ja/sqlite_async.dart/releases)
The `sqlite3.wasm` asset can be found [here](https://github.com/simolus3/sqlite3.dart/releases)

In the end your `web/` directory will look like the following

```
web/
├── favicon.png
├── index.html
├── manifest.json
├── db_worker.js
└── sqlite3.wasm
```
2 changes: 1 addition & 1 deletion packages/drift_sqlite_async/lib/src/executor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'dart:async';

import 'package:drift/backends.dart';
import 'package:drift_sqlite_async/src/transaction_executor.dart';
import 'package:sqlite_async/sqlite3.dart';
import 'package:sqlite_async/sqlite3_common.dart';
import 'package:sqlite_async/sqlite_async.dart';

class _SqliteAsyncDelegate extends DatabaseDelegate {
Expand Down
10 changes: 9 additions & 1 deletion packages/drift_sqlite_async/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: drift_sqlite_async
version: 0.1.0-alpha.3
version: 0.1.0-alpha.4
homepage: https://github.com/powersync-ja/sqlite_async.dart
repository: https://github.com/powersync-ja/sqlite_async.dart
description: Use Drift with a sqlite_async database, allowing both to be used in the same application.
Expand All @@ -23,3 +23,11 @@ dev_dependencies:
sqlite3: ^2.4.0
test: ^1.25.2
test_api: ^0.7.0

platforms:
android:
ios:
linux:
macos:
windows:
web:
Loading