mikependon / RepoDB

A hybrid ORM library for .NET.
Apache License 2.0
1.7k stars 124 forks source link

Enhancement: Dynamic Postgres Schema #710

Open TimCorwin opened 3 years ago

TimCorwin commented 3 years ago

Describe the enhancement

My organization uses postgres Schemas for tenant isolation.

As such, we need to be able to dynamically connect to a requested schema; when using raw npgsql, we can just add SearchPath=tenant, and interact with tables directly. because this changes the connection string it forces npg to pool the connection properly.

However, going through RepoDb, we hit PostgreSqlDbHelper.GetFields, which explicitly retrieves the schema from the table attribute or static value on DbSettings.

That means if I've set the searchPath to something other than public, it will still look for the fields in public, find nothing, and throw.

if it was possible to provide an instance rather than static value of the schema, it would be possible to pass or set the desired schema when constructing Repositories.

mikependon commented 3 years ago

Thanks for reporting and also for explaining your situation/problem. We will do assess and look for the ways on how to solve this in the near future.