Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface Options

Options for the pgStructure.

Hierarchy

  • Options

Index

Properties

Optional commentDataToken

commentDataToken: undefined | 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 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 envPrefix

envPrefix: undefined | 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: undefined | string | string[]

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

Optional foreignKeyAliasSeparator

foreignKeyAliasSeparator: undefined | string

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

Optional foreignKeyAliasTargetFirst

foreignKeyAliasTargetFirst: undefined | boolean

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

Optional includeSchemas

includeSchemas: undefined | 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: undefined | boolean

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

Optional keepConnection

keepConnection: undefined | boolean

Prevents pg-structure to close given database connection.

Optional name

name: undefined | string

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

Optional relationNameFunctions

relationNameFunctions: undefined | 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 table names, columns, foreign key, comment data can be accessed via passed 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),
  },
}

Generated using TypeDoc