pg-structure / Options

# Interface: Options

Options for the pgStructure.

# Hierarchy

  • Options

# Table of contents

# Properties

# Properties

# commentDataToken

Optional 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 }

Defined in: types/index.ts:204


# envPrefix

Optional 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 (opens new window) of pg). All keys are built using this prefix in uppercase.

Environment Varibale ClientConfig (opens new window) 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" }

Defined in: types/index.ts:130


# excludeSchemas

Optional excludeSchemas: undefined | string | string[]

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

Defined in: types/index.ts:147


# foreignKeyAliasSeparator

Optional foreignKeyAliasSeparator: undefined | string

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

Defined in: types/index.ts:153


# foreignKeyAliasTargetFirst

Optional 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).

Defined in: types/index.ts:156


# includeSchemas

Optional 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"] };

Defined in: types/index.ts:144


# includeSystemSchemas

Optional includeSystemSchemas: undefined | boolean

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

Defined in: types/index.ts:150


# keepConnection

Optional keepConnection: undefined | boolean

Prevents pg-structure to close given database connection.

Defined in: types/index.ts:207


# name

Optional name: undefined | string

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

Defined in: types/index.ts:133


# relationNameFunctions

Optional 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, 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),
  },
}

Defined in: types/index.ts:190