com-lihaoyi / scalasql

Scala ORM to query SQL databases from Scala via concise, type-safe, and familiar case classes and collection operations. Connects to Postgres, MySql, H2, and Sqlite out of the box
194 stars 22 forks source link

How to select database schema? #14

Closed dangdennis closed 3 months ago

dangdennis commented 5 months ago

I have tables in schemas other than Postgres's public. schema. How would I define a Table with a different schema?

lihaoyi commented 5 months ago

does override def tableName = "schemaname.tablename on the table companion object work?

dangdennis commented 5 months ago

I tried that prior and it didn’t work.

The issue was that the generated query used “auth.users0” in place of the actual name table.

I’ll try again to confirm.

santanaraphael commented 3 months ago

@dangdennis did you ever get a solution? I'm having the same issue, my schema is source and table is invoice. I tried setting the tableName as source.invoice, but whenever creating the selects, it tries to alias that table as source.invoice0, which is invalid SQL.

santanaraphael commented 3 months ago

hey @lihaoyi do you know of another workarounds?

lihaoyi commented 3 months ago

@santanaraphael I don't have any other workarounds off the top of my head, we might need to patch scalasql to add support for this

lihaoyi commented 3 months ago

Should be fixed by https://github.com/com-lihaoyi/scalasql/pull/23. I tagged 0.1.6 which should go out soon