I want to use postgresql to support a multi-tenant environment, so each customer will have its own schema.
When I make a sql query, can I change the schema dynamically when using Slick?
If so, how?
You can parameterize your Table classes and TableQuery factories.
trait Schema{
def name: String
}
case object Customer1 extends Schema{
def name = "CUSTOMER_1"
}
case object Customer2 extends Schema{
def name = "CUSTOMER_2"
}
class MyTable(tag: Tag, schema: Option[String]) extends Table[...](tag, schema){
...
}
def myTable(schema: Schema) = new TableQuery( new MyTable(_,Some(schema.name)) )
myTable(Customer1).filter(_.id == 5).run
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With