brick_supabase 0.1.0 copy "brick_supabase: ^0.1.0" to clipboard
brick_supabase: ^0.1.0 copied to clipboard

Supabase connector for Brick, a data persistence library. Includes annotations, adapter, model, and provider.

brick_supabase workflow

Supabase Provider #

Connecting Brick with Supabase.

Supported Query Configuration #

providerArgs: #

  • 'limit' e.g. {'limit': 10}
  • 'limitByReferencedTable' forwards to Supabase's referencedTable` property https://supabase.com/docs/reference/dart/limit
  • 'orderBy' Use field names not column names and always specify direction.For example, given a final DateTime createdAt; field: {'orderBy': 'createdAt ASC'}. If the column cannot be found for the first value before a space, the value is left unchanged.
  • 'orderByReferencedTable' forwards to Supabase's referencedTable property https://supabase.com/docs/reference/dart/order

Models #

@SupabaseSerializable(tableName:) #

The Supabase table name must be specified to connect from, upsert and delete invocations:

@SupabaseSerializable(tableName: 'users')
class User
copied to clipboard

@SupabaseSerializable(fieldRename:) #

By default, Brick assumes the Dart field name is the camelized version of the Supabase column name (i.e. final String lastName => 'last_name'). However, this can be changed to rename all fields.

@SupabaseSerializable(fieldRename: FieldRename.pascal)
class User
copied to clipboard

fieldRename is only the default transformation. Naming can be overriden on a field-by-field basis with @Supabase(name:).

@SupabaseSerializable(defaultToNull:) #

Forwards to Supabase's defaultToNull during upsert operations.

@SupabaseSerializable(ignoreDuplicates:) #

Forwards to Supabase's ignoreDuplicates during upsert operations.

@SupabaseSerializable(onConflict:) #

Forwards to Supabase's onConflict during upsert operations.

Fields #

@Supabase(unique:) #

Connect Supabase's primary key (or any other index) to your application code. This is useful for upsert and delete logic when mutating instances.

@Supabase(unique: true, name: 'uuid')
final String supabaseUuid;
copied to clipboard

@Supabase(foreignKey:) #

Specify the foreign key to use on the table when fetching for a remote association.

For example, given the orders table has a customer_id column that associates the customers table, an Order class in Dart may look like:

@SupabaseSerializeable(tableName: 'orders')
class Order {
  @Supabase(foreignKey: 'customer_uuid')
  final Customer customer;
}

@SupabaseSerializeable(tableName: 'customers')
class Customer {
  @Supabase(unique: true)
  final String uuid;
}
copied to clipboard

@Supabase(enumAsString:) #

Brick by default assumes enums from a REST API will be delivered as integers matching the index in the Flutter app. However, if your API delivers strings instead, the field can be easily annotated without writing a custom generator.

Given the API:

{ "user": { "hats": ["bowler", "birthday"] } }
copied to clipboard

Simply convert hats into a Dart enum:

enum Hat { baseball, bowler, birthday }

...

@Supabase(enumAsString: true)
final List<Hat> hats;
copied to clipboard

@Supabase(name:) #

REST keys can be renamed per field. This will override the default set by SupabaseSerializable#fieldRename.

@Supabase(
  name: "full_name"  // "full_name" is used in from and to requests to REST instead of "last_name"
)
final String lastName;
copied to clipboard

@Supabase(ignoreFrom:) and @Supabase(ignoreTo:) #

When true, the field will be ignored by the (de)serializing function in the adapter.

Unsupported Field Types #

The following are not serialized to REST. However, unsupported types can still be accessed in the model as non-final fields.

  • Nested List<> e.g. <List<List<int>>>
  • Many-to-many associations
10
likes
0
points
2.23k
downloads

Publisher

unverified uploader

Weekly Downloads

2024.09.10 - 2025.03.25

Supabase connector for Brick, a data persistence library. Includes annotations, adapter, model, and provider.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

brick_core, logging, meta, supabase

More

Packages that depend on brick_supabase