I was searching the documentation of pg-promise specifically in the creation of the client. But I wasn't able to find the option to set the default schema to be used in the connection, it always uses public
schema. How do I set it?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
Normally, one sets the default schema(s) for the database or the role, as explained here:
It is only if you want to do it without persisting the change, you might want to set the schema(s) dynamically, just for the current process.
You can do so within pg-promise, by overriding event connect, and then executing the required query directly, for each fresh connection:
And starting from version 8.3.0, the library supports option
schema
within Initialization Options:making it easier to set the dynamic schema(s).
Examples
Making your own schema visible along with the default
public
schema:Using the callback to set schema based on the database context (see Database constructor):
UPDATE
Version 8.4.0 replaced parameter
isFresh
withuseCount
for event connect, so it is best to just use the latest version and optionschema
.