Skip to content

Commit

Permalink
remove abstract packages
Browse files Browse the repository at this point in the history
  • Loading branch information
tshedor committed Aug 19, 2024
1 parent 124afb3 commit f75c645
Show file tree
Hide file tree
Showing 23 changed files with 19 additions and 459 deletions.

This file was deleted.

This file was deleted.

21 changes: 0 additions & 21 deletions packages/brick_offline_first_with_supabase_abstract/LICENSE

This file was deleted.

147 changes: 0 additions & 147 deletions packages/brick_offline_first_with_supabase_abstract/README.md

This file was deleted.

This file was deleted.

This file was deleted.

19 changes: 0 additions & 19 deletions packages/brick_offline_first_with_supabase_abstract/pubspec.yaml

This file was deleted.

5 changes: 4 additions & 1 deletion packages/brick_supabase/lib/brick_supabase.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export 'package:brick_supabase/src/annotations/supabase.dart';
export 'package:brick_supabase/src/annotations/supabase_serializable.dart';
export 'package:brick_supabase/src/runtime_supabase_column_definition.dart';
export 'package:brick_supabase/src/supabase_adapter.dart';
export 'package:brick_supabase/src/supabase_model.dart';
export 'package:brick_supabase/src/supabase_model_dictionary.dart';
export 'package:brick_supabase/src/supabase_provider.dart';
export 'package:brick_supabase_abstract/brick_supabase_abstract.dart';
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:brick_core/core.dart';
import 'package:brick_supabase/src/supabase_adapter.dart';
import 'package:brick_supabase/src/supabase_model_dictionary.dart';
import 'package:brick_supabase_abstract/brick_supabase_abstract.dart' hide Supabase;
import 'package:supabase_flutter/supabase_flutter.dart';
import 'package:supabase/supabase.dart';

/// Create a prepared SQLite statement for eventual execution. Only [statement] and [values]
/// should be accessed.
Expand Down Expand Up @@ -30,9 +30,7 @@ class QuerySupabaseTransformer<_Model extends SupabaseModel> {
return _destructureAssociation(adapter.fieldsToSupabaseColumns.values).join(',\n ');
}

PostgrestFilterBuilder<List<Map<String, dynamic>>> select() {
final builder = Supabase.instance.client.from(adapter.tableName);

PostgrestFilterBuilder<List<Map<String, dynamic>>> select(SupabaseQueryBuilder builder) {
return (query?.where ?? []).fold(builder.select(selectQuery), (acc, condition) {
final whereStatement = _expandCondition(condition);
for (final where in whereStatement) {
Expand Down
2 changes: 1 addition & 1 deletion packages/brick_supabase/lib/src/supabase_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:brick_supabase/src/supabase_provider.dart';
import 'package:brick_supabase_abstract/brick_supabase_abstract.dart';

/// Constructors that convert app models to and from Supabase
abstract class SupabaseAdapter<TModel extends SupabaseModel> implements Adapter<TModel> {
abstract mixin class SupabaseAdapter<TModel extends SupabaseModel> implements Adapter<TModel> {
/// Used for upserts; forwards to Supabase's `defaultToNull`
bool get defaultToNull;

Expand Down
16 changes: 10 additions & 6 deletions packages/brick_supabase/lib/src/supabase_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import 'package:brick_supabase/src/supabase_model_dictionary.dart';
import 'package:brick_supabase_abstract/brick_supabase_abstract.dart' hide Supabase;
import 'package:logging/logging.dart';
import 'package:meta/meta.dart';
import 'package:supabase_flutter/supabase_flutter.dart';
import 'package:supabase/supabase.dart';

/// Retrieves from an HTTP endpoint
class SupabaseProvider implements Provider<SupabaseModel> {
/// A fully-qualified URL
final String baseEndpoint;

final SupabaseClient client;

/// The glue between app models and generated adapters.
@override
final SupabaseModelDictionary modelDictionary;
Expand All @@ -20,14 +22,15 @@ class SupabaseProvider implements Provider<SupabaseModel> {

SupabaseProvider(
this.baseEndpoint, {
required this.client,
required this.modelDictionary,
}) : logger = Logger('SupabaseProvider');

/// Sends a DELETE request method to the endpoint
@override
Future<bool> delete<TModel extends SupabaseModel>(instance, {query, repository}) async {
final adapter = modelDictionary.adapterFor[TModel]!;
final tableBuilder = Supabase.instance.client.from(adapter.tableName);
final tableBuilder = client.from(adapter.tableName);
final output = await adapter.toSupabase(instance, provider: this, repository: repository);

final queryTransformer =
Expand All @@ -47,9 +50,10 @@ class SupabaseProvider implements Provider<SupabaseModel> {

@override
Future<bool> exists<TModel extends SupabaseModel>({query, repository}) async {
final adapter = modelDictionary.adapterFor[TModel]!;
final queryTransformer =
QuerySupabaseTransformer<TModel>(modelDictionary: modelDictionary, query: query);
final builder = queryTransformer.select();
final builder = queryTransformer.select(client.from(adapter.tableName));

final resp = await builder.count(CountOption.exact);
return resp.count > 0;
Expand All @@ -60,7 +64,7 @@ class SupabaseProvider implements Provider<SupabaseModel> {
final adapter = modelDictionary.adapterFor[TModel]!;
final queryTransformer =
QuerySupabaseTransformer<TModel>(modelDictionary: modelDictionary, query: query);
final builder = queryTransformer.select();
final builder = queryTransformer.select(client.from(adapter.tableName));

final resp = await builder;

Expand All @@ -73,13 +77,13 @@ class SupabaseProvider implements Provider<SupabaseModel> {
@override
Future<TModel> upsert<TModel extends SupabaseModel>(instance, {query, repository}) async {
final adapter = modelDictionary.adapterFor[TModel]!;
final tableBuilder = Supabase.instance.client.from(adapter.tableName);
final output = await adapter.toSupabase(instance, provider: this, repository: repository);

final queryTransformer =
QuerySupabaseTransformer<TModel>(modelDictionary: modelDictionary, query: query);

final builder = adapter.uniqueFields.fold(tableBuilder.upsert(output), (acc, uniqueFieldName) {
final builder = adapter.uniqueFields.fold(client.from(adapter.tableName).upsert(output),
(acc, uniqueFieldName) {
final columnName = adapter.fieldsToSupabaseColumns[uniqueFieldName]!.columnName;
if (output.containsKey(columnName)) {
return acc.eq(columnName, output[columnName]);
Expand Down
4 changes: 2 additions & 2 deletions packages/brick_supabase/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ repository: https://github.com/GetDutchie/brick
version: 0.0.1

environment:
sdk: ">=2.18.0 <4.0.0"
sdk: ">=3.0.0 <4.0.0"

dependencies:
brick_core: ^1.1.1
supabase_flutter: ">=2.6.0 <3.0.0"
supabase: ">=2.3.0 <3.0.0"
logging: ">=1.0.0 <2.0.0"
meta: ">=1.3.0 <2.0.0"
brick_supabase_abstract: ">=0.0.1 <2.0.0"
Expand Down
5 changes: 0 additions & 5 deletions packages/brick_supabase_abstract/CHANGELOG.md

This file was deleted.

21 changes: 0 additions & 21 deletions packages/brick_supabase_abstract/LICENSE

This file was deleted.

Loading

0 comments on commit f75c645

Please sign in to comment.