Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: stream with a different schema (#661)
- Loading branch information
Showing
4 changed files
with
98 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class Counter { | ||
int _value = 0; | ||
|
||
int get value => _value; | ||
|
||
int increment() { | ||
return _value++; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import 'package:http/http.dart'; | ||
import 'package:supabase/supabase.dart'; | ||
import 'package:yet_another_json_isolate/yet_another_json_isolate.dart'; | ||
|
||
import 'counter.dart'; | ||
|
||
/// Used to perform [rpc] and [from] operations with a different schema than in [SupabaseClient]. | ||
class SupabaseQuerySchema { | ||
final Counter _counter; | ||
final String _restUrl; | ||
final Map<String, String> _headers; | ||
final String _schema; | ||
final YAJsonIsolate _isolate; | ||
final Client? _authHttpClient; | ||
final RealtimeClient _realtime; | ||
final PostgrestClient _rest; | ||
|
||
SupabaseQuerySchema({ | ||
required Counter counter, | ||
required String restUrl, | ||
required Map<String, String> headers, | ||
required String schema, | ||
required YAJsonIsolate isolate, | ||
required Client? authHttpClient, | ||
required RealtimeClient realtime, | ||
required PostgrestClient rest, | ||
}) : _counter = counter, | ||
_restUrl = restUrl, | ||
_headers = headers, | ||
_schema = schema, | ||
_isolate = isolate, | ||
_authHttpClient = authHttpClient, | ||
_realtime = realtime, | ||
_rest = rest; | ||
|
||
/// Perform a table operation. | ||
SupabaseQueryBuilder from(String table) { | ||
final url = '$_restUrl/$table'; | ||
return SupabaseQueryBuilder( | ||
url, | ||
_realtime, | ||
headers: {..._rest.headers, ..._headers}, | ||
schema: _schema, | ||
table: table, | ||
httpClient: _authHttpClient, | ||
incrementId: _counter.increment(), | ||
isolate: _isolate, | ||
); | ||
} | ||
|
||
/// Perform a stored procedure call. | ||
PostgrestFilterBuilder<T> rpc<T>( | ||
String fn, { | ||
Map<String, dynamic>? params, | ||
}) { | ||
_rest.headers.addAll({..._rest.headers, ..._headers}); | ||
return _rest.rpc(fn, params: params); | ||
} | ||
|
||
SupabaseQuerySchema useSchema(String schema) { | ||
final newRest = _rest.useSchema(schema); | ||
return SupabaseQuerySchema( | ||
counter: _counter, | ||
restUrl: _restUrl, | ||
headers: _headers, | ||
schema: schema, | ||
isolate: _isolate, | ||
authHttpClient: _authHttpClient, | ||
realtime: _realtime, | ||
rest: newRest, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters