-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* move sqlite_async to packages * monorepo updates * move drift package * fix actions * more test fixes * Clean up pubspec and README * Clean up readme * Add detailed usage instructions * Remove older packages links * Fix drift repository url * Fix pana analyze packages * Revert pana script * Fix melos pana analyze --------- Co-authored-by: Mugi Khan <[email protected]>
- Loading branch information
1 parent
ea80324
commit 67acc56
Showing
106 changed files
with
1,877 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,5 +17,6 @@ assets | |
test-db | ||
sqlite-autoconf-* | ||
doc | ||
*.iml | ||
|
||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,5 @@ | ||
# Developing Instructions | ||
|
||
## Testing | ||
|
||
Running tests for the `web` platform requires some preparation to be executed. The `sqlite3.wasm` and `db_worker.js` files need to be available in the Git ignored `./assets` folder. | ||
|
||
See the [test action](./.github/workflows/test.yaml) for the latest steps. | ||
|
||
On your local machine run the commands from the `Install SQLite`, `Compile WebWorker` and `Run Tests` steps. | ||
|
||
## Releases | ||
|
||
Web worker files are compiled and uploaded to draft Github releases whenever tags matching `v*` are pushed. These tags are created when versioning. Releases should be manually finalized and published when releasing new package versions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: sqlite_async_monorepo | ||
|
||
packages: | ||
- packages/** | ||
|
||
scripts: | ||
prepare: melos bootstrap && melos prepare:compile:webworker && melos prepare:sqlite:wasm | ||
|
||
prepare:compile:webworker: | ||
description: Compile Javascript web worker distributable | ||
run: dart compile js -o assets/db_worker.js -O0 packages/sqlite_async/lib/src/web/worker/worker.dart | ||
|
||
prepare:sqlite:wasm: | ||
description: Download SQLite3 WASM binary | ||
run: dart run ./scripts/sqlite3_wasm_download.dart | ||
|
||
format: | ||
description: Format Dart code. | ||
run: dart format . | ||
|
||
format:check:packages: | ||
description: Check formatting of Dart code in packages. | ||
run: dart format --output none --set-exit-if-changed packages | ||
|
||
analyze:packages: | ||
description: Analyze Dart code in packages. | ||
run: dart analyze packages --fatal-infos | ||
|
||
analyze:packages:pana: | ||
description: Analyze Dart packages with Pana | ||
exec: dart pub global run pana --no-warning --exit-code-threshold 0 | ||
packageFilters: | ||
noPrivate: true | ||
|
||
test: | ||
description: Run tests in a specific package. | ||
run: dart test -p chrome,vm | ||
exec: | ||
concurrency: 1 | ||
packageFilters: | ||
dirExists: | ||
- test | ||
# This tells Melos tests to ignore env variables passed to tests from `melos run test` | ||
# as they could change the behaviour of how tests filter packages. | ||
env: | ||
MELOS_TEST: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
## 0.1.0-alpha.1 | ||
|
||
Initial release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Journey Mobile, Inc. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# drift_sqlite_async | ||
|
||
`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: | ||
|
||
```dart | ||
@DriftDatabase(tables: [TodoItems]) | ||
class AppDatabase extends _$AppDatabase { | ||
AppDatabase(SqliteConnection db) : super(SqliteAsyncDriftConnection(db)); | ||
@override | ||
int get schemaVersion => 1; | ||
} | ||
Future<void> main() async { | ||
// The sqlite_async db | ||
final db = SqliteDatabase(path: 'example.db'); | ||
// The Drift db | ||
final appdb = AppDatabase(db); | ||
} | ||
``` | ||
|
||
A full example is in the `examples/` folder. | ||
|
||
For details on table definitions and using the database, see the [Drift documentation](https://drift.simonbinder.eu/). | ||
|
||
## Transactions and concurrency | ||
|
||
sqlite_async uses WAL mode and multiple read connections by default, and this | ||
is also exposed when using the database with Drift. | ||
|
||
Drift's transactions use sqlite_async's `writeTransaction`. The same locks are used | ||
for both, preventing conflicts. | ||
|
||
Read-only transactions are not currently supported in Drift. | ||
|
||
Drift's nested transactions are supported, implemented using SAVEPOINT. | ||
|
||
Select statements in Drift use read operations (`getAll()`) in sqlite_async, | ||
and can run concurrently with writes. | ||
|
||
## Update notifications | ||
|
||
sqlite_async uses SQLite's update_hook to detect changes for watching queries, | ||
and will automatically pick up changes made using Drift. This also includes any updates from custom queries in Drift. | ||
|
||
Changes from sqlite_async are automatically propagated to Drift when using SqliteAsyncDriftConnection. | ||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
targets: | ||
$default: | ||
builders: | ||
drift_dev: | ||
options: | ||
fatal_warnings: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import 'package:drift/drift.dart'; | ||
import 'package:drift_sqlite_async/drift_sqlite_async.dart'; | ||
import 'package:sqlite_async/sqlite_async.dart'; | ||
|
||
part 'main.g.dart'; | ||
|
||
class TodoItems extends Table { | ||
@override | ||
String get tableName => 'todos'; | ||
|
||
IntColumn get id => integer().autoIncrement()(); | ||
TextColumn get description => text()(); | ||
} | ||
|
||
@DriftDatabase(tables: [TodoItems]) | ||
class AppDatabase extends _$AppDatabase { | ||
AppDatabase(SqliteConnection db) : super(SqliteAsyncDriftConnection(db)); | ||
|
||
@override | ||
int get schemaVersion => 1; | ||
} | ||
|
||
Future<void> main() async { | ||
final db = SqliteDatabase(path: 'example.db'); | ||
|
||
// Example where the schema is managed manually | ||
await db.execute( | ||
'CREATE TABLE IF NOT EXISTS todos(id integer primary key, description text)'); | ||
|
||
final appdb = AppDatabase(db); | ||
|
||
// Watch a query on the Drift database | ||
appdb.select(appdb.todoItems).watch().listen((todos) { | ||
print('Todos: $todos'); | ||
}); | ||
|
||
// Insert using the Drift database | ||
await appdb | ||
.into(appdb.todoItems) | ||
.insert(TodoItemsCompanion.insert(description: 'Test Drift')); | ||
|
||
// Insert using the sqlite_async database | ||
await db.execute('INSERT INTO todos(description) VALUES(?)', ['Test Direct']); | ||
|
||
await Future.delayed(const Duration(milliseconds: 100)); | ||
|
||
await appdb.close(); | ||
await db.close(); | ||
} |
Oops, something went wrong.