morsecoder
morsecoder

Reputation: 1649

Knex/Bookshelf: How to Use Postgres Schema in All Queries/Commands

I am writing an application with Knex, Bookshelf, and Postgres. I would like all Postgres commands issued from my application to be on tables in one schema. Is there a way I can accomplish this without specifying .withSchema('my_schema_name') for each individual query/command?

Ideally, I could specify the schema in the knexfile.js, but I don't see a way to do this.

I have already tried:

Both of these resulted in various errors.

Upvotes: 4

Views: 5121

Answers (2)

morsecoder
morsecoder

Reputation: 1649

The solution was actually to pretend the tableName with 'my_schema.'. (Notice the dot)

The error I had seen when I tried this initially was due to something else.

Upvotes: 4

Boris Schegolev
Boris Schegolev

Reputation: 3701

Your connection should call SET search_path TO my_schema, public; after being initialized. This is a connection (session) property and it should do what you are asking for.

Upvotes: 1

Related Questions