Skip to content

Commit 747512e

Browse files
committed
updates
1 parent f743499 commit 747512e

File tree

24 files changed

+107
-35
lines changed

24 files changed

+107
-35
lines changed

docs/offline_first/offline_first_with_supabase_repository.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,14 @@ Field types of classes that `extends OfflineFirstWithSupabaseModel` will automat
138138
```dart
139139
class User extends OfflineFirstWithSupabaseModel {
140140
// The foreign key is a relation to the `id` column of the Address table
141-
@Supabase(name: 'address_id')
142-
// Help the SQLite provider connect the association locally to the one provided from remote
143-
@OfflineFirst(where: {'id': "data['address']['id']"})
141+
@Supabase(foreignKey: 'address_id')
144142
final Address address;
143+
144+
// If the association will be created by the app, specify
145+
// a field that maps directly to the foreign key column
146+
// so that Brick can notify Supabase of the association.
147+
@Sqlite(ignore: true)
148+
String get addressId => address.id;
145149
}
146150
147151
class Address extends OfflineFirstWithSupabaseModel{

docs/supabase/fields.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@ final String lastName;
3131

3232
?> By default, Brick renames fields to be snake case when translating to Supabase, but you can change this default in the `@SupabaseSerializable(fieldRename:)` annotation that [decorates models](models.md).
3333

34-
When the annotated field type extends the model's type, the Supabase column should be a foreign key.
34+
!> **Do not use** `name` when annotating an association. Instead, use `foreignKey`.
35+
36+
### `@Supabase(foreignKey:)`
37+
38+
When the annotated field references a `OfflineFirstWithSupabaseModel`, a foreign key can be specified. Supabase's PostgREST API can usually determine the association without specifying the foreign key. However, [when multiple foreign keys exist](https://supabase.com/docs/guides/database/joins-and-nesting?queryGroups=language&language=dart#specifying-the-on-clause-for-joins-with-multiple-foreign-keys) to the same table, guiding Brick to use the right foreign key is required.
3539

3640
```dart
3741
class User extends OfflineFirstWithSupabaseModel{
38-
// The foreign key is a relation to the `id` column of the Address table
39-
@Supabase(name: 'address_id')
42+
@Supabase(foreignKey: 'address_id')
4043
final Address address;
4144
}
4245

example_supabase/lib/brick/adapters/pizza_adapter.g.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ Future<Map<String, dynamic>> _$PizzaToSupabase(Pizza instance,
1616
'id': instance.id,
1717
'frozen': instance.frozen,
1818
'customer': await CustomerAdapter()
19-
.toSupabase(instance.customer, provider: provider, repository: repository)
19+
.toSupabase(instance.customer, provider: provider, repository: repository),
20+
'customer_id': instance.customerId
2021
};
2122
}
2223

@@ -65,6 +66,11 @@ class PizzaAdapter extends OfflineFirstWithSupabaseAdapter<Pizza> {
6566
columnName: 'customer',
6667
associationType: Customer,
6768
associationIsNullable: false,
69+
foreignKey: 'customer_id',
70+
),
71+
'customerId': const RuntimeSupabaseColumnDefinition(
72+
association: false,
73+
columnName: 'customer_id',
6874
)
6975
};
7076
@override

example_supabase/lib/brick/db/schema.g.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import 'package:brick_sqlite/db.dart';
44
part '20240920034504.migration.dart';
55

66
/// All intelligently-generated migrations from all `@Migratable` classes on disk
7-
final migrations = <Migration>{
8-
const Migration20240920034504(),
9-
};
7+
final migrations = <Migration>{const Migration20240920034504()};
108

119
/// A consumable database structure including the latest generated migration.
1210
final schema = Schema(20240920034504, generatorVersion: 1, tables: <SchemaTable>{

example_supabase/lib/brick/models/pizza.model.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,15 @@ class Pizza extends OfflineFirstWithSupabaseModel {
1313

1414
final bool frozen;
1515

16+
@Supabase(foreignKey: 'customer_id')
1617
final Customer customer;
1718

19+
// If the association will be created by the app, specify
20+
// a field that maps directly to the foreign key column
21+
// so that Brick can notify Supabase of the association.
22+
@Sqlite(ignore: true)
23+
String get customerId => customer.id;
24+
1825
Pizza({
1926
required this.id,
2027
required this.frozen,

example_supabase/lib/main.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import 'package:flutter/material.dart';
22
import 'package:pizza_shoppe/brick/models/pizza.model.dart';
33
import 'package:pizza_shoppe/brick/repository.dart';
44

5-
const supabaseUrl = 'https://aqjyorrxelzrbkgjuyll.supabase.co';
6-
const supabaseAnonKey =
7-
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImFxanlvcnJ4ZWx6cmJrZ2p1eWxsIiwicm9sZSI6ImFub24iLCJpYXQiOjE2OTMxNzM3MzAsImV4cCI6MjAwODc0OTczMH0.MUsslxOyculwfEG5r_yY02pvz3-DN5j6TobL5CsR-mk';
5+
const supabaseUrl = 'SUPABASE_URL';
6+
const supabaseAnonKey = 'SUPABASE_ANON_KEY';
87

98
Future<void> main() async {
109
await Repository.initializeSupabaseAndConfigure(

packages/brick_build/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## Unreleased
22

3+
- Add documentation to increase pub.dev score
4+
35
## 3.2.1
46

57
- Revert `.getDisplayString()` change due to Flutter 3.22 being restricted to analyzer <6.4.1. `meta` is pinned to `1.12` in this version of Flutter, and `analyzer >=6.5.0`, where the change was made, requires `meta >= 1.15`. This change will eventually be re-reverted.

packages/brick_build/lib/src/serdes_generator.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ abstract class SerdesGenerator<FieldAnnotation extends FieldSerializable,
177177
return "'$name': $contents";
178178
}
179179

180+
/// Generates a `repository.getAssociation` invocation
180181
String getAssociationMethod(
181182
DartType argType, {
182183
bool forceNullable = false,

packages/brick_offline_first_with_supabase/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,14 @@ Field types of classes that `extends OfflineFirstWithSupabaseModel` will automat
113113
```dart
114114
class User extends OfflineFirstWithSupabaseModel {
115115
// The foreign key is a relation to the `id` column of the Address table
116-
@Supabase(name: 'address_id')
116+
@Supabase(foreignKey: 'address_id')
117117
final Address address;
118+
119+
// If the association will be created by the app, specify
120+
// a field that maps directly to the foreign key column
121+
// so that Brick can notify Supabase of the association.
122+
@Sqlite(ignore: true)
123+
String get addressId => address.id;
118124
}
119125
120126
class Address extends OfflineFirstWithSupabaseModel{

packages/brick_offline_first_with_supabase_build/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## Unreleased
22

3+
- Add documentation to increase pub.dev score
4+
35
## 1.0.0
46

57
- Stable release

0 commit comments

Comments
 (0)