Skip to content

Commit

Permalink
feat(supabase): add supabase integration (#418)
Browse files Browse the repository at this point in the history
  • Loading branch information
tshedor authored Sep 20, 2024
2 parents dfc0d22 + d625f06 commit b925741
Show file tree
Hide file tree
Showing 128 changed files with 8,228 additions and 580 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/brick_offline_first_with_supabase.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Brick Offline First with Supabase
on:
push:
branches:
- main
pull_request:
paths:
- "packages/brick_offline_first_with_supabase/**"
- ".github/workflows/brick_offline_first_with_supabase.yaml"

env:
PUB_ENVIRONMENT: bot.github

jobs:
analyze_format_test:
uses: ./.github/workflows/reusable-dart-analyze-format-test.yaml
with:
package: brick_offline_first_with_supabase
18 changes: 18 additions & 0 deletions .github/workflows/brick_offline_first_with_supabase_build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Brick Offline First with Supabase Build
on:
push:
branches:
- main
pull_request:
paths:
- "packages/brick_offline_first_with_supabase_build/**"
- ".github/workflows/brick_offline_first_with_supabase_build.yaml"

env:
PUB_ENVIRONMENT: bot.github

jobs:
analyze_format_test:
uses: ./.github/workflows/reusable-dart-analyze-format-test.yaml
with:
package: brick_offline_first_with_supabase_build
18 changes: 18 additions & 0 deletions .github/workflows/brick_supabase.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Brick Supabase
on:
push:
branches:
- main
pull_request:
paths:
- "packages/brick_supabase/**"
- ".github/workflows/brick_supabase.yaml"

env:
PUB_ENVIRONMENT: bot.github

jobs:
analyze_format_test:
uses: ./.github/workflows/reusable-dart-analyze-format-test.yaml
with:
package: brick_supabase
18 changes: 18 additions & 0 deletions .github/workflows/brick_supabase_generators.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Brick Supabase Generators
on:
push:
branches:
- main
pull_request:
paths:
- "packages/brick_supabase_generators/**"
- ".github/workflows/brick_supabase_generators.yaml"

env:
PUB_ENVIRONMENT: bot.github

jobs:
analyze_format_test:
uses: ./.github/workflows/reusable-dart-analyze-format-test.yaml
with:
package: brick_supabase_generators
6 changes: 3 additions & 3 deletions .github/workflows/reusable-dart-analyze-format-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ jobs:
with:
sdk: ${{ matrix.sdk_version }}
- name: Cache Pub hosted dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: "~/.pub-cache/hosted"
key: ${{ runner.os }}-${{ inputs.package }}-v1-${{ matrix.sdk_version }}-${{ hashFiles(format('packages/{0}/pubspec.yaml', inputs.package)) }}
restore-keys: |
${{ runner.os }}-${{ inputs.package }}-v1-${{ matrix.sdk_version }}
- id: checkout
uses: actions/checkout@v3
- uses: actions/checkout@v4

- run: dart pub get && dart run melos bootstrap --scope="${{ inputs.package }}"

Expand Down
19 changes: 12 additions & 7 deletions .github/workflows/reusable-flutter-analyze-format-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
flutter_analyze_format_test:
runs-on: ubuntu-latest
container:
image: cirrusci/flutter:${{ matrix.flutter_version }}
image: ghcr.io/cirruslabs/flutter:${{ matrix.flutter_version }}
strategy:
fail-fast: false
matrix:
Expand All @@ -25,24 +25,29 @@ jobs:
run: sudo apt-get update && sudo apt-get -y install sqlite3 libsqlite3-dev

- name: Cache Pub hosted dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: "~/.pub-cache/hosted"
key: ${{ runner.os }}-${{ inputs.package }}-v1-${{ matrix.flutter_version }}-${{ hashFiles(format('packages/{0}/pubspec.yaml', inputs.package)) }}
restore-keys: |
${{ runner.os }}-${{ inputs.package }}-v1-${{ matrix.flutter_version }}
- id: checkout
uses: actions/checkout@v3
- uses: actions/checkout@v4

- run: flutter pub get
working-directory: packages/${{ inputs.package }}

- run: dart analyze --fatal-infos lib test
- run: dart analyze --fatal-infos lib
working-directory: packages/${{ inputs.package }}

- run: dart format --output=none --line-length 100 --set-exit-if-changed lib test
- run: if [ -d "test" ]; then dart analyze --fatal-infos test; fi
working-directory: packages/${{ inputs.package }}

- run: flutter test
- run: dart format --output=none --line-length 100 --set-exit-if-changed lib
working-directory: packages/${{ inputs.package }}

- run: if [ -d "test" ]; then dart format --output=none --line-length 100 --set-exit-if-changed test; fi
working-directory: packages/${{ inputs.package }}

- run: if [ -d "test" ]; then flutter test; fi
working-directory: packages/${{ inputs.package }}
98 changes: 51 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ An intuitive way to work with persistent data in Dart.

## Why Brick?

* Out-of-the-box [offline access](packages/brick_offline_first) to data
* [Handle and hide](packages/brick_build) complex serialization/deserialization logic
* Single [access point](docs/data/repositories.md) and opinionated DSL
* Automatic, [intelligently-generated migrations](docs/sqlite.md#intelligent-migrations)
* Legible [querying interface](docs/data/query.md)
- Out-of-the-box [offline access](packages/brick_offline_first) to data
- [Handle and hide](packages/brick_build) complex serialization/deserialization logic
- Single [access point](docs/data/repositories.md) and opinionated DSL
- Automatic, [intelligently-generated migrations](docs/sqlite.md#intelligent-migrations)
- Legible [querying interface](docs/data/query.md)

## What is Brick?

Expand All @@ -19,51 +19,55 @@ Brick is an extensible query interface for Dart applications. It's an [all-in-on
## Quick Start

1. Add the packages:
```yaml
dependencies:
# Or brick_offline_first_with_graphql
brick_offline_first_with_rest:
sqflite: # optional
dev_dependencies:
# Or brick_offline_first_with_graphql_build: any
brick_offline_first_with_rest_build:
build_runner:
```
```yaml
dependencies:
# Or brick_offline_first_with_graphql
# Or brick_offline_first_with_supabase
brick_offline_first_with_rest:
sqflite: # optional
dev_dependencies:
# Or brick_offline_first_with_graphql_build: any
# Or brick_offline_first_with_supabase_build: any
brick_offline_first_with_rest_build:
build_runner:
```
1. Configure your app directory structure to match Brick's expectations:
```bash
mkdir -p lib/brick/adapters lib/brick/db;
```
```bash
mkdir -p lib/brick/adapters lib/brick/db;
```
1. Add [models](docs/data/models.md) that contain your app logic. Models **must be** saved with the `.model.dart` suffix (i.e. `lib/brick/models/person.model.dart`).
1. Run `dart run build_runner build` to generate your models and [sometimes migrations](docs/sqlite.md#intelligent-migrations). Rerun after every new model change or `dart run build_runner watch` for automatic generations. You'll need to run this again after your first migration.
1. Extend [an existing repository](docs/data/repositories.md) or create your own:
```dart
// lib/brick/repository.dart
import 'package:brick_offline_first_with_rest/brick_offline_first_with_rest.dart';
import 'package:brick_rest/brick_rest.dart';
import 'package:brick_sqlite/brick_sqlite.dart';
import 'package:my_app/brick/brick.g.dart';
import 'package:sqflite/sqflite.dart' show databaseFactory;
import 'package:my_app/brick/db/schema.g.dart';
export 'package:brick_core/query.dart' show And, Or, Query, QueryAction, Where, WherePhrase;

class Repository extends OfflineFirstWithRestRepository {
Repository()
: super(
migrations: migrations,
restProvider: RestProvider(
'http://0.0.0.0:3000',
modelDictionary: restModelDictionary,
),
sqliteProvider: SqliteProvider(
_DB_NAME,
databaseFactory: databaseFactory,
modelDictionary: sqliteModelDictionary,
),
offlineQueueManager: RestRequestSqliteCacheManager(
'brick_offline_queue.sqlite',
databaseFactory: databaseFactory,
),
);
}
```
```dart
// lib/brick/repository.dart
import 'package:brick_offline_first_with_rest/brick_offline_first_with_rest.dart';
import 'package:brick_rest/brick_rest.dart';
import 'package:brick_sqlite/brick_sqlite.dart';
import 'package:my_app/brick/brick.g.dart';
import 'package:sqflite/sqflite.dart' show databaseFactory;
import 'package:my_app/brick/db/schema.g.dart';
export 'package:brick_core/query.dart' show And, Or, Query, QueryAction, Where, WherePhrase;
class Repository extends OfflineFirstWithRestRepository {
Repository()
: super(
migrations: migrations,
restProvider: RestProvider(
'http://0.0.0.0:3000',
modelDictionary: restModelDictionary,
),
sqliteProvider: SqliteProvider(
_DB_NAME,
databaseFactory: databaseFactory,
modelDictionary: sqliteModelDictionary,
),
offlineQueueManager: RestRequestSqliteCacheManager(
'brick_offline_queue.sqlite',
databaseFactory: databaseFactory,
),
);
}
```

1. Profit.
5 changes: 5 additions & 0 deletions docs/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
- [Fetching data](data/query.md)
- [Providers](data/providers.md)
- [Repositories](data/repositories.md)
- [Supabase](supabase/repository.md)
- [Model Config](supabase/models.md)
- [Field Config](supabase/fields.md)
- [Querying](supabase/query.md)
- [Testing](supabase/testing.md)
- [GraphQL](graphql/fields.md)
- [Model Config](graphql/models.md)
- [Field Config](graphql/fields.md)
Expand Down
Loading

0 comments on commit b925741

Please sign in to comment.