简体   繁体   中英

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:

  • prepending the table name with 'my_schema_name.'
  • issuing a USE SCHEMA command at the launch of my application

Both of these resulted in various errors.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM