K
Kysely12mo ago
kika

.withSchema() and raw SQL

when doing sql <ReturnType> SELECT some_function(param);.execute(db) the function is not found because it doesn't exist in the public schema, although db was created with .withSchema('myschema'). If I change the call to SELECT myschema.some_function(param);.execute(db) it still doesn't work, because the function references tables in myschema
3 Replies
kika
kika12mo ago
I think I understand that .withSchema() modifies the query that the QueryBuilder builds and if the query was not built with QB, .withSchema() is a NOOP. But I found no way to build a SELECT random(); query with Kysely Query Builder The ugly workaround is to call the function with explicit schema specification in function name and types (if necessary) and do SET search_path TO myschema in the function itself
koskimas
koskimas12mo ago
We don't parse raw SQL which is what it would take for us to automatically add the schema to raw SQL snippets. And we'll never call something like SET search_path TO myschema under the hood without the user explicitly running that query. In fact, kysely never runs any queries you haven't explicitly written and executed. So withSchema will never have any effect inside your SQL functions.
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server
More Posts