Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/postgrest/lib/src/postgrest.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ class PostgrestClient {
);
}

/// Select a schema to query or perform an function (rpc) call.
///
/// The schema needs to be on the list of exposed schemas inside Supabase.
PostgrestClient useSchema(String schema) {
return PostgrestClient(
url,
headers: {...headers},
schema: schema,
httpClient: httpClient,
isolate: _isolate,
);
}

/// Perform a stored procedure call.
///
/// ```dart
Expand Down
13 changes: 13 additions & 0 deletions packages/postgrest/test/basic_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@ void main() {
expect(res.length, 5);
});

test('query non-public schema dynamically', () async {
final postgrest = PostgrestClient(rootUrl);
final personalData = await postgrest
.useSchema('personal')
.from('users')
.select<PostgrestList>();
expect(personalData.length, 5);

// confirm that the client defaults to its initialized schema by default.
final publicData = await postgrest.from('users').select<PostgrestList>();
expect(publicData.length, 4);
});

test('on_conflict upsert', () async {
final res = await postgrest.from('users').upsert(
{'username': 'dragarcia', 'status': 'OFFLINE'},
Expand Down
7 changes: 7 additions & 0 deletions packages/supabase/lib/src/supabase_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,13 @@ class SupabaseClient {
);
}

/// Select a schema to query or perform an function (rpc) call.
///
/// The schema needs to be on the list of exposed schemas inside Supabase.
PostgrestClient useSchema(String schema) {
return rest.useSchema(schema);
}

/// Perform a stored procedure call.
PostgrestFilterBuilder rpc(
String fn, {
Expand Down