Skip to content

Commit c1452ed

Browse files
committed
Merge branch 'develop' into new-query-builder
2 parents 3635f8b + 6406f62 commit c1452ed

241 files changed

Lines changed: 5830 additions & 1719 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/actions/prepare/action.yml‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,21 @@ name: Prepare
22
description: Prepare CI environment to test a component of drift
33

44
inputs:
5-
dart_version:
6-
description: Dart version, to restore the dependency cache
5+
flutter_version:
6+
description: Flutter version to use.
77
required: true
88

99
runs:
1010
using: "composite"
1111
steps:
12-
- uses: dart-lang/setup-dart@v1
12+
- name: Set up Flutter
13+
uses: subosito/flutter-action@v2
14+
with:
15+
channel: stable
16+
flutter-version: ${{ inputs.flutter_version }}
17+
cache: true
18+
cache-key: "flutter-:os:-:channel:-:version:-:arch:-:hash:"
19+
cache-path: "${{ runner.tool_cache }}/flutter/:channel:-:version:-:arch:"
1320

1421
# Setup sqlite3
1522
- name: Download sqlite3
@@ -31,9 +38,9 @@ runs:
3138
- uses: actions/cache@v4
3239
with:
3340
path: "${{ env.PUB_CACHE }}"
34-
key: dart-dependencies-${{ inputs.dart_version }}-${{ hashFiles('**/pubspec.yaml') }}
41+
key: dart-dependencies-${{ inputs.flutter_version }}-${{ hashFiles('**/pubspec.yaml') }}
3542
restore-keys: |
36-
dart-dependencies-${{ inputs.dart_version }}-
43+
dart-dependencies-${{ inputs.flutter_version }}-
3744
dart-dependencies-
3845
- name: Setup melos
3946
run: dart pub global activate melos && dart pub get

‎.github/workflows/main.yml‎

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,15 @@ jobs:
2525
- uses: actions/checkout@v4
2626
- uses: ./.github/actions/prepare
2727
with:
28-
dart_version: ${{ needs.setup.outputs.dart_version }}
29-
- name: Setup Flutter
30-
uses: subosito/flutter-action@v2
31-
with:
32-
flutter-version: 3.27
33-
cache: true
34-
cache-key: "flutter-:os:-:channel:-:version:-:arch:-:hash:"
35-
cache-path: "${{ runner.tool_cache }}/flutter/:channel:-:version:-:arch:"
28+
flutter_version: ${{ needs.setup.outputs.flutter_version }}
3629
- name: Bootstrap Dart packages
3730
run: melos bootstrap --scope drift_docs,drift,app
3831
working-directory: .
3932
- name: Run build
4033
env:
4134
IS_RELEASE: ${{ github.event_name == 'push' && github.event.ref == 'refs/heads/latest-release' }}
4235
run: |
36+
dart pub global activate webdev
4337
chmod +x ./docs.sh
4438
./docs.sh build
4539
- name: Analyze Dart and Drift sources
@@ -89,7 +83,7 @@ jobs:
8983
- uses: actions/checkout@v4
9084
- uses: ./.github/actions/prepare
9185
with:
92-
dart_version: ${{ needs.setup.outputs.dart_version }}
86+
flutter_version: ${{ needs.setup.outputs.flutter_version }}
9387
- run: melos bootstrap --scope drift
9488
working-directory: .
9589
# analysis
@@ -121,7 +115,7 @@ jobs:
121115
- uses: actions/checkout@v4
122116
- uses: ./.github/actions/prepare
123117
with:
124-
dart_version: ${{ needs.setup.outputs.dart_version }}
118+
flutter_version: ${{ needs.setup.outputs.flutter_version }}
125119
- run: melos bootstrap --scope drift
126120
working-directory: .
127121
# Using build_runner test allows compiling the tests with ddc, which is much faster than
@@ -146,7 +140,7 @@ jobs:
146140
# - uses: actions/checkout@v4
147141
# - uses: ./.github/actions/prepare
148142
# with:
149-
# dart_version: ${{ needs.setup.outputs.dart_version }}
143+
# flutter_version: ${{ needs.setup.outputs.flutter_version }}
150144
# - run: melos bootstrap --scope drift
151145
# working-directory: .
152146
# - run: dart test -p ${{ matrix.browser }} --compiler dart2js --total-shards 4 --shard-index ${{ matrix.shard }}
@@ -159,14 +153,15 @@ jobs:
159153
working-directory: drift
160154
strategy:
161155
matrix:
162-
browser: [chrome, firefox]
156+
browser: [chrome] # Dart 3.7 unfortunately broke tests with dart2wasm on Firefox
157+
# browser: [chrome, firefox]
163158
name: "Drift web unit tests, dart2wasm, ${{ matrix.browser }}"
164159
steps:
165160
# setup
166161
- uses: actions/checkout@v4
167162
- uses: ./.github/actions/prepare
168163
with:
169-
dart_version: ${{ needs.setup.outputs.dart_version }}
164+
flutter_version: ${{ needs.setup.outputs.flutter_version }}
170165
- run: melos bootstrap --scope drift
171166
working-directory: .
172167
- run: dart test -p ${{ matrix.browser }} --compiler dart2wasm
@@ -183,7 +178,7 @@ jobs:
183178
- uses: actions/checkout@v4
184179
- uses: ./.github/actions/prepare
185180
with:
186-
dart_version: ${{ needs.setup.outputs.dart_version }}
181+
flutter_version: ${{ needs.setup.outputs.flutter_version }}
187182
- run: melos bootstrap --scope drift_dev --scope drift
188183
working-directory: .
189184
# analysis
@@ -204,7 +199,7 @@ jobs:
204199
- uses: actions/checkout@v4
205200
- uses: ./.github/actions/prepare
206201
with:
207-
dart_version: ${{ needs.setup.outputs.dart_version }}
202+
flutter_version: ${{ needs.setup.outputs.flutter_version }}
208203
- run: dart pub upgrade
209204
# analysis
210205
- run: dart format -o none --set-exit-if-changed .
@@ -248,7 +243,7 @@ jobs:
248243
- uses: actions/checkout@v4
249244
- uses: ./.github/actions/prepare
250245
with:
251-
dart_version: ${{ needs.setup.outputs.dart_version }}
246+
flutter_version: ${{ needs.setup.outputs.flutter_version }}
252247
- run: melos bootstrap --no-flutter
253248
working-directory: .
254249
- name: Postgres integration tests
@@ -284,7 +279,9 @@ jobs:
284279
needs: [setup]
285280
strategy:
286281
matrix:
287-
flutter: ["3.27"]
282+
# We currently don't support <3.35.1 because we depend on melos v7, which needs Dart 3.9.0.
283+
# Generally, we try to support the latest two stable Flutter releases.
284+
flutter: ["3.35.1"]
288285

289286
steps:
290287
- uses: actions/checkout@v4
@@ -327,17 +324,22 @@ jobs:
327324
working-directory: examples/app
328325
- run: flutter analyze
329326
working-directory: examples/app
327+
- run: flutter analyze
328+
working-directory: drift_flutter
329+
- run: flutter test
330+
working-directory: drift_flutter
330331
- run: flutter test
331332
working-directory: examples/app
332333
migration_integration_tests:
333334
name: "Integration tests for migration tooling"
334335
needs: [setup]
335336
runs-on: ubuntu-latest
337+
timeout-minutes: 5
336338
steps:
337339
- uses: actions/checkout@v4
338340
- uses: ./.github/actions/prepare
339341
with:
340-
dart_version: ${{ needs.setup.outputs.dart_version }}
342+
flutter_version: ${{ needs.setup.outputs.flutter_version }}
341343
- run: melos bootstrap --scope migrations_example
342344
working-directory: .
343345
- name: Run build
@@ -360,17 +362,18 @@ jobs:
360362
name: "Web integration tests"
361363
needs: [drift]
362364
runs-on: ubuntu-latest
365+
timeout-minutes: 15
363366
steps:
364367
- uses: actions/checkout@v4
365368
- uses: ./.github/actions/prepare
366369
with:
367-
dart_version: ${{ needs.setup.outputs.dart_version }}
370+
flutter_version: ${{ needs.setup.outputs.flutter_version }}
368371
- uses: nanasess/setup-chromedriver@v2
369372
- run: melos bootstrap --scope web_wasm
370373
working-directory: .
371374
- name: Test
372375
working-directory: extras/integration_tests/web_wasm
373-
run: dart test
376+
run: dart test -P gh_actions
374377
# upload_coverage:
375378
# runs-on: ubuntu-20.04
376379
# needs: [moor, sqlparser]

‎.github/workflows/setup.yml‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
on:
22
workflow_call:
33
outputs:
4-
dart_version:
5-
description: Version of the Dart SDK used during the setup run, useful for dependency restoring
6-
value: ${{ jobs.dart_dependencies.outputs.dart_version }}
4+
flutter_version:
5+
description: Version of the Flutter SDK used during the setup run.
6+
value: ${{ jobs.dart_dependencies.outputs.flutter_version }}
77

88
jobs:
99
# Compile the latest sqlite3 library, which will be used to run tests in drift
@@ -47,22 +47,22 @@ jobs:
4747
name: Get and cache Dart dependencies
4848
runs-on: ubuntu-latest
4949
outputs:
50-
dart_version: ${{ steps.dart_version.outputs.version }}
50+
flutter_version: ${{ steps.setup_flutter.outputs.VERSION }}
5151
steps:
5252
- uses: actions/checkout@v4
53-
- uses: dart-lang/setup-dart@v1
54-
- name: Get Dart version
55-
id: dart_version
56-
run: |
57-
version=`cat $DART_HOME/version`
58-
echo "Running on Dart $version"
59-
echo "version=$version" >> $GITHUB_STATE
53+
- name: Set up Flutter
54+
id: setup_flutter
55+
uses: subosito/flutter-action@v2
56+
with:
57+
cache: true
58+
cache-key: "flutter-:os:-:channel:-:version:-:arch:-:hash:"
59+
cache-path: "${{ runner.tool_cache }}/flutter/:channel:-:version:-:arch:"
6060
- uses: actions/cache@v4
6161
with:
6262
path: "${{ env.PUB_CACHE }}"
63-
key: dart-dependencies-${{ steps.dart_version.outputs.version }}-${{ hashFiles('**/pubspec.yaml') }}
63+
key: dart-dependencies-${{ steps.setup_flutter.outputs.VERSION }}-${{ hashFiles('**/pubspec.yaml') }}
6464
restore-keys: |
65-
dart-dependencies-${{ steps.dart_version.outputs.version }}-
65+
dart-dependencies-${{ steps.setup_flutter.outputs.VERSION }}-
6666
dart-dependencies-
6767
- name: Setup melos
6868
run: dart pub global activate melos && dart pub get

‎docs/README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ Folder Structure:
1111
- `mkdocs` Contains the MkDocs configuration.
1212

1313
### Building the Documentation
14+
1415
You will need to make the `docs.sh` script executable before you can run it. You can do this by running the following command:
1516

1617
```bash
1718
chmod +x docs.sh
19+
20+
# Also, make sure webdev is installed:
21+
dart pub global activate webdev
1822
```
1923

2024
Run the following command to build the documentation:

‎docs/build.yaml‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ targets:
4444
drift_dev:analyzer:
4545
enabled: true
4646
options: &options
47-
sql:
48-
dialect: sqlite
49-
options:
47+
dialects:
48+
sqlite:
5049
version: "3.39"
5150
databases:
5251
main_db: "lib/snippets/dart_api/manager.dart"

‎docs/docs.sh‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ run_webdev(){
3535
# The below command will compile the dart code in `/web` to js & run build_runner
3636
if [ $1 -eq 1 ]; then
3737
echo "Running dev build"
38-
dart run webdev build -o web:build/web -- --delete-conflicting-outputs
38+
dart pub global run webdev build -o web:build/web -- --delete-conflicting-outputs
3939
else
40-
dart run webdev build -o web:build/web -- --delete-conflicting-outputs --release
40+
dart pub global run webdev build -o web:build/web -- --delete-conflicting-outputs --release
4141
fi
4242
if [ $? -ne 0 ]; then
4343
echo "Failed to build the project"

‎docs/docs/Examples/existing_databases.md‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ flutter:
3838
3939
To initialize the database before using drift, you need to extract the asset from your
4040
app onto the device.
41-
In drift, you can use a [LazyDatabase](https://pub.dev/documentation/drift/latest/drift/LazyDatabase-class.html)
42-
to perform that work just before your drift database is opened:
4341
4442
```dart
4543
import 'package:drift/drift.dart';
@@ -79,6 +77,21 @@ LazyDatabase _openConnection() {
7977
}
8078
```
8179

80+
=== "Using `drift_flutter`"
81+
82+
{{ load_snippet('(full)','lib/snippets/examples/existing_databases_flutter.dart.excerpt.json',indent=4) }}
83+
84+
=== "Using `package:drift/native.dart`"
85+
86+
In drift, you can use a [LazyDatabase](https://pub.dev/documentation/drift/latest/drift/LazyDatabase-class.html)
87+
to perform that work just before your drift database is opened:
88+
89+
{{ load_snippet('(full)','lib/snippets/examples/existing_databases_native.dart.excerpt.json',indent=4) }}
90+
91+
92+
!!! warning
93+
This snippet only works on native platforms. See [existing databases on the web](../Platforms/web.md#using-existing-databases) for web support.
94+
8295
Finally, use that method to open your database:
8396

8497
```dart

‎docs/docs/Examples/server_sync.md‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,37 @@ in which he shares the approach used by Visible to sync local changes to the ser
3535
Additional approaches are also discussed in [this issue](https://github.com/simolus3/drift/issues/136) and
3636
[here](https://github.com/simolus3/drift/discussions/2880).
3737

38+
Jan Zimola has published [a demo](https://github.com/Musta-Pollo/custom_supabase_drift_doc_sync) for data
39+
sync using the WatermelonDB protocol for synchronization (with a Dart implementation for clients and a pgSQL-based
40+
implementation for servers). The server code is generic and does not depend on the actual tables, only on their interface.
41+
It uses code generation to automate most of the client logic.
42+
43+
## PowerSync
44+
45+
<small>
46+
_Disclosure_: Drift maintainer Simon Binder [works at the team maintaining PowerSync](https://www.powersync.com/blog/simon-binder-joins-powersync).
47+
While this page only reflects his personal opinion, please keep that in mind and perhaps consult other sources on sync options for Dart too.
48+
</small>
49+
50+
PowerSync is sync solution with [stable and official Flutter support](https://docs.powersync.com/client-sdk-references/flutter).
51+
Using a sync service available as a managed cloud offering or for self-hosting, you define buckets of data to make available to individual users.
52+
A client SDK for Dart/Flutter connects to this service to automatically sync changes from backend databases in real-time.
53+
54+
While PowerSync automatically collects client-side changes, you're still responsible for uploading these to your backend (which can then validate them).
55+
For managed Postgres databases such as Supabase, using row-level security and [direct uploads from clients](https://docs.powersync.com/integration-guides/supabase-+-powersync)
56+
avoids the use of a separate backend.
57+
58+
PowerSync also offers a [package for drift support](https://docs.powersync.com/client-sdk-references/flutter/flutter-orm-support#example-implementation) (currently in Alpha)
59+
that will make your query streams update in real-time for changes from the backend.
60+
[This example](https://github.com/powersync-ja/powersync.dart/tree/main/demos/supabase-todolist-drift) shows how PowerSync can be integrated into a drift app.
61+
3862
## ElectricSQL
3963

64+
!!! note "This section may be outdated"
65+
66+
The Dart package for Electric referenced here refers to an [older version of Electric SQL](https://legacy.electric-sql.com/),
67+
the current version of Electric does not appear to be available to Dart apps.
68+
4069
[ElectricSQL](https://electric-sql.com/) is a solution you can self-host to synchronize PostgreSQL databases
4170
with clients.
4271
Instead of having to deal with changes manually, a service receives updates from the PostgreSQL server and

0 commit comments

Comments
 (0)