diff --git a/packages/postgrest/lib/src/postgrest.dart b/packages/postgrest/lib/src/postgrest.dart index 08fdf5d0..399cd84d 100644 --- a/packages/postgrest/lib/src/postgrest.dart +++ b/packages/postgrest/lib/src/postgrest.dart @@ -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 diff --git a/packages/postgrest/test/basic_test.dart b/packages/postgrest/test/basic_test.dart index e96d2c51..1c6a75f5 100644 --- a/packages/postgrest/test/basic_test.dart +++ b/packages/postgrest/test/basic_test.dart @@ -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(); + expect(personalData.length, 5); + + // confirm that the client defaults to its initialized schema by default. + final publicData = await postgrest.from('users').select(); + expect(publicData.length, 4); + }); + test('on_conflict upsert', () async { final res = await postgrest.from('users').upsert( {'username': 'dragarcia', 'status': 'OFFLINE'}, diff --git a/packages/supabase/lib/src/supabase_client.dart b/packages/supabase/lib/src/supabase_client.dart index 909cb972..39e8b0d7 100644 --- a/packages/supabase/lib/src/supabase_client.dart +++ b/packages/supabase/lib/src/supabase_client.dart @@ -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, {