Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface ClientOptions

Hierarchy

  • PgStructureOptions
    • ClientOptions

Index

Properties

Optional client

client: string | Client | ClientConfig

Either a node-postgres client or a configuration object or a connection string to create a node-postgres client.

Optional commentDataToken

commentDataToken: string

Tag name to extract JSON data from from database object's comments. For example by default JSON data between [pg-structure][/pg-structure] is available imn database objects. Data can be retrieved with {@link DbObject.commentData commentData} method.

Example

const config = {
  commentDataToken: "pg-structure"
}

// Assuming `[pg-structure]{ level: 3 }[/pg-structure]` is written in database table comment/description.
const someData = db.get("public.account").commentData; // { level: 3 }

Optional connectionString

connectionString: string

Connection string to connect to the database e.g. postgres://user:password@host:5432/database

Optional database

database: string

Database to connect. Default from environment var: PGDATABASE || DB_DATABASE

Optional envPrefix

envPrefix: string

Environment variable prefix to get database client details. If no client configuration is provided pg-structure tries to get client details from environment variables to populate node-postgres config (See ClientConfig of pg). All keys are built using this prefix in uppercase.

Environment Varibale ClientConfig Key
DB_DATABASE database
DB_USER user
DB_PASSWORD password
DB_HOST host
DB_PORT port
DB_CONNECTION_STRING connectionString
DB_SSL ssl
... ...

Example

const config = { envPrefix: "DB" }

Optional excludeSchemas

excludeSchemas: string | string[]

List of the schemas or a pattern similar to SQL's LIKE to select excluded schemas.

Optional foreignKeyAliasSeparator

foreignKeyAliasSeparator: string

Character to separate {@link ForeignKey.sourceAlias source alias} and {@link ForeignKey.targetAlias target alias} in {@link ForeignKey foreign key} name.

Optional foreignKeyAliasTargetFirst

foreignKeyAliasTargetFirst: boolean

Whether first part of the foreign key aliases contains target alias (i.e company_employees) or source alias (i.e. employee_company).

Optional host

host: string

Database host. Default from environment var: PGHOST || DB_HOST

Optional includeSchemas

includeSchemas: string | string[]

List of the schemas or a pattern similar to SQL's LIKE to select included schemas.

Example 1

const config = { includeSchemas: "public_%" }; // include all schemas starting with "public_"

Example 2

const config = { includeSchemas: ["public", "extra"] };

Optional includeSystemSchemas

includeSystemSchemas: boolean

Whether to include PostgreSQL system schemas (i.e. pg_catalog) from database.

Optional keepConnection

keepConnection: boolean

Prevents pg-structure to close given database connection.

Optional name

name: string

Name of the database. This is inferred if possible from client or connection string.

Optional password

password: string

Database password. Default from environment var: PGPASSWORD || DB_PASSWORD

Optional port

port: string

Database port. Default from environment var: PGPORT || DB_PORT

Optional relationNameFunctions

relationNameFunctions: string | RelationNameFunctions

Optional module that exports functions to generate names for relationships. If not provided, default naming functions are used. All necessary information such as {@link Table table} names, {@link Column columns}, {@link ForeignKey foreign key}, {@link DbObject.commentData comment data} can be accessed via passed {@link Relation relation} parameter.

It is also possible to use one of the builtin naming functions: short, optimal or descriptive.

Example 1

const config = {
  relationNameFunctions: "short",
}

Example 2

const config = {
  relationNameFunctions: "custom-module",
}

Example 3

const config = {
  relationNameFunctions: require.resolve("./my-module"),
}

Example 4

const config = {
  relationNameFunctions: {
    o2m: (relation) => some_func(relation.foreignKey.name),
    m2o: (relation) => some_func(relation.foreignKey.name),
    m2m: (relation) => some_func(relation.foreignKey.name),
  },
}

Optional ssl

ssl: any

Passed directly to node.TLSSocket, supports all tls.connect options

Optional user

user: string

Database username. Default from environment var: PGUSER || USER || DB_USER

Generated using TypeDoc