pg-structure / ForeignKey

# Class: ForeignKey

Class which represent a foreign key. Provides attributes and methods for details of the foreign key.

# Hierarchy

# Properties

# columns

Readonly columns: default<Column, name, never, true>

{@link IndexableArray Indexable array} of columns this foreign key has. Columns are in order their ordinal position within the foreign key.

Defined in: pg-structure/constraint/foreign-key.ts:72


# comment

Optional Readonly comment: undefined | string

Comment of the database object defined in database including {@link DbObject#commentData comment data}.

Inherited from: Constraint.comment

Defined in: pg-structure/base/db-object.ts:75


# index

Readonly index: Index

The @{link Index index}} supporting this constraint.

Defined in: pg-structure/constraint/foreign-key.ts:66


# mandatoryParent

Readonly mandatoryParent: boolean

Whether all foreign key columns are mandatory at parent table.

# Example

// account table: (PK) id [NN]
// contact table: (PK) id [NN], (FK) account_id [NN]
contactTable.foreignKeys[0].mandatoryParent; // true, because all foreign keys (account_id) is not null.

Defined in: pg-structure/constraint/foreign-key.ts:44


# matchType

Readonly matchType: MatchType

Match option of ForeignKey. One of FULL, PARTIAL, NONE. TypeScript developers should use {@link MatchOption} enum.

Defined in: pg-structure/constraint/foreign-key.ts:49


# name

Readonly name: string

Name of the database object.

Inherited from: Constraint.name

Defined in: pg-structure/base/db-object.ts:42


# onDelete

Readonly onDelete: Action

Delete action for foreign keys. One of CASCADE, SET NULL, SET DEFAULT, RESTRICT, NO ACTION. TypeScript developers should use Action enum.

Defined in: pg-structure/constraint/foreign-key.ts:61


# onUpdate

Readonly onUpdate: Action

Update action for foreign keys. One of CASCADE, SET NULL, SET DEFAULT, RESTRICT, NO ACTION. TypeScript developers should use Action enum.

Defined in: pg-structure/constraint/foreign-key.ts:55


# table

Readonly table: Table

Table which this constraint defined in.

Defined in: pg-structure/constraint/foreign-key.ts:108

# Accessors

# commentData

• get commentData(): undefined | null | string | number | boolean | JSONObject | JSONArray

Data which is extracted from database object's comment. Data is extracted from text between special case-insensitive tag (default: [pg-structure][/pg-structure]) and converted to JavaScript object using JSON5 (opens new window). Token name can be specified by using commentDataToken arguments. For details of JSON5 (opens new window), see it's web site: https://json5.org (opens new window).

# Example

// "Account details. [pg-structure]{ extraData: 2 }[/pg-structure] Also used for logging."
table.comment;               // "Account details. [pg-structure]{ extraData: 2 }[/pg-structure] Also used for logging."
table.commentWithoutData;    // "Account details.  Also used for logging."
table.commentData;           // { extraData: 2 }
table.commentData.extraData; // 2

Returns: undefined | null | string | number | boolean | JSONObject | JSONArray

Defined in: pg-structure/base/db-object.ts:102


# commentWithoutData

• get commentWithoutData(): undefined | string

Description or comment of the database object defined in database. If comment contains {@link DbObject#commentData comment data}, it is removed.

# Example

// "Account details. [pg-structure]{ extraData: 2 }[/pg-structure] Also used for logging."
table.commentWithoutData;    // "Account details.  Also used for logging."

Returns: undefined | string

Defined in: pg-structure/base/db-object.ts:85


# correspondingForeignKeys

• get correspondingForeignKeys(): default<ForeignKey, name, never, true>

List of other foreign keys which has same source table and target table.

Returns: default<ForeignKey, name, never, true>

Defined in: pg-structure/constraint/foreign-key.ts:101


# db

• get db(): Db

Database of the database object.

Returns: Db

Defined in: pg-structure/base/db-object.ts:68


# fullCatalogName

• get fullCatalogName(): string

Full name of the database object including database name.

Returns: string

Defined in: pg-structure/base/db-object.ts:35


# fullName

• get fullName(): string

Full name of the constraint including table name.

Returns: string

Defined in: pg-structure/constraint/foreign-key.ts:113


# nameCaseType

• get nameCaseType(): CaseType

Letter casing (i.e snakeCase or camelCase) of the database object name.

# Example

const name = entity.name;                        // ProductDetail
const caseType = entity.nameCaseType;            // camelCase

const otherEntity = otherEntity.name;            // member_protocol
const otherCaseType = otherEntity.nameCaseType;  // snakeCase

Returns: CaseType

Defined in: pg-structure/base/db-object.ts:54


# referencedColumns

• get referencedColumns(): default<Column, name, never, true>

{@link IndexableArray Indexable array} of columns this foreign key refers. Columns are in order their ordinal position within the foreign key.

Returns: default<Column, name, never, true>

Defined in: pg-structure/constraint/foreign-key.ts:87


# referencedColumnsBy

• get referencedColumnsBy(): { column: Column ; references: Column }[]

Array of columns this foreign key has and refers to.

Returns: { column: Column ; references: Column }[]

Defined in: pg-structure/constraint/foreign-key.ts:94


# referencedTable

• get referencedTable(): Table

This is Table instance this foreign key refers to.

Returns: Table

Defined in: pg-structure/constraint/foreign-key.ts:77


# schema

• get schema(): Schema

Schema of the constraint's table defined in.

Returns: Schema

Defined in: pg-structure/constraint/foreign-key.ts:120


# separator

• get separator(): string

Separator used in database object name. Empty string for came case and underscore for (_) snake case.

Returns: string

Defined in: pg-structure/base/db-object.ts:61