# Class: Table

Class which represent a table. Provides attributes and methods for details of the table. Tables may have relationships with other tables.

Below is a database schema which is used in code examples. Database Schema

# Hierarchy

Entity

Table

# Properties

# columns

columns: IndexableArray‹Column, "name", "attributeNumber", true› = IndexableArray.throwingFrom( [], "name", "attributeNumber" )

Inherited from Entity.columns

Defined in pg-structure/base/entity.ts:55

All columns of the entity as an {@link IndexableArray indexable array} ordered by same order they are defined in database entity.

# Example

const isAvailable  = table.columns.has('id');
const columnNames  = table.columns.map(column => column.name);
const column       = table.columns.get('user_id');
const name         = column.name;

table.columns.forEach(column => console.log(column.name));

name Entity#columns


# Optional comment

comment? : undefined | string

Inherited from DbObject.comment

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

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


# constraints

constraints: IndexableArray‹Constraint, "name", never, true› = IndexableArray.throwingFrom([], "name")

Defined in pg-structure/entity/table.ts:29

All constraints in the table as an [[IndexableArray]] ordered by name.


# foreignKeysToThis

foreignKeysToThis: IndexableArray‹ForeignKey, "name", never, true› = IndexableArray.throwingFrom([], "name")

Defined in pg-structure/entity/table.ts:36

All foreign keys which are referring to this table as an [[IndexableArray]].

see Table.o2mRelations, Table.m2oRelations, Table.m2mRelations to get more details about relations.


# indexes

indexes: IndexableArray‹Index, "name", never, true› = IndexableArray.throwingFrom([], "name")

Defined in pg-structure/entity/table.ts:41

All indexes in the table as an [[IndexableArray]], ordered by name.


# name

name: string

Inherited from DbObject.name

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

Name of the database object.


# oid

oid: number

Inherited from Entity.oid

Defined in pg-structure/base/entity.ts:25

Object identifier for the Entity


# schema

schema: Schema

Inherited from Entity.schema

Overrides DbObject.schema

Defined in pg-structure/base/entity.ts:40

Schema of the object.

# Accessors

# belongsToManyTables

get belongsToManyTables(): IndexableArray‹Table, "name", never, true›

Defined in pg-structure/entity/table.ts:161

Tables which this table has many to many relationship, ordered by table name Please note that same table will appear more than once if there are more than one relationship between tables or same named tables from different schemas (i.e. public.account may have relations with public.contact and vip.contact).

# Example

// Cart (id) has many products (id) through line_item join table.
cartTable.belongsToManyTables.forEach(table => console.log(table.name));
cartTable.belongsToManyTables.getAll("contact"); // All related tables named contact.

see Example schema

Returns: IndexableArray‹Table, "name", never, true›


# belongsToManyTablesPk

get belongsToManyTablesPk(): IndexableArray‹Table, "name", never, true›

Defined in pg-structure/entity/table.ts:178

Tables which this table has many to many relationship joined by primary keys only in join table, ordered by table name Please note that same table will appear more than once if there are more than one relationship between tables or same named tables from different schemas (i.e. public.account may have relations with public.contact and vip.contact).

# Example

// Cart (id) has many products (id) through line_item join table.
cartTable.belongsToManyTablesPk.forEach(table => console.log(table.name));
cartTable.belongsToManyTablesPk.getAll("contact"); // All related tables named contact.

see Example schema, {@link IndexableArray}

Returns: IndexableArray‹Table, "name", never, true›


# belongsToTables

get belongsToTables(): IndexableArray‹Table, "name", never, true›

Defined in pg-structure/entity/table.ts:145

Tables, which this table has belongs to relationship (a.k.a. many to one) which is reverse direction of one to many relationship (a.k.a one to many), ordered by table name. Please note that same table will appear more than once if there are more than one relationship between tables or same named tables from different schemas (i.e. public.account may have relations with public.contact and vip.contact).

# Example

productTable.belongsToTables.forEach(table => console.log(table.name));
productTable.belongsToTables.getAll("contact"); // All related tables named contact.

see Example schema, {@link IndexableArray}

Returns: IndexableArray‹Table, "name", never, true›


# checkConstraints

get checkConstraints(): IndexableArray‹CheckConstraint, "name", never, true›

Defined in pg-structure/entity/table.ts:98

All check constraints in the table as an [[IndexableArray]] ordered by name.

Returns: IndexableArray‹CheckConstraint, "name", never, true›


# commentData

get commentData(): JSONData | undefined

Inherited from DbObject.commentData

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

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

# 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: JSONData | undefined


# commentWithoutData

get commentWithoutData(): string | undefined

Inherited from DbObject.commentWithoutData

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

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: string | undefined


# db

get db(): Db

Inherited from DbObject.db

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

Database of the database object.

Returns: Db


# exclusionConstraints

get exclusionConstraints(): IndexableArray‹ExclusionConstraint, "name", never, true›

Defined in pg-structure/entity/table.ts:105

All exclusion constraints in the table as an [[IndexableArray]] ordered by name.

Returns: IndexableArray‹ExclusionConstraint, "name", never, true›


# foreignKeys

get foreignKeys(): IndexableArray‹ForeignKey, "name", never, true›

Defined in pg-structure/entity/table.ts:84

All foreign keys in the table as an [[IndexableArray]] ordered by name.

see o2mRelations, m2oRelations, m2mRelations to get more details about relations.

Returns: IndexableArray‹ForeignKey, "name", never, true›


# fullCatalogName

get fullCatalogName(): string

Inherited from DbObject.fullCatalogName

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

Full name of the database object including database name.

Returns: string


# fullName

get fullName(): string

Inherited from Entity.fullName

Overrides DbObject.fullName

Defined in pg-structure/base/entity.ts:33

Full name of the object with '.' notation including Schema name.

# Example

const fullName = entity.fullName; // public.member

Returns: string


# hasManyTables

get hasManyTables(): IndexableArray‹Table, "name", never, true›

Defined in pg-structure/entity/table.ts:130

Tables, which this table has one to many relationship, ordered by table name. Please note that same table will appear more than once if there are more than one relationship between tables or same named tables from different schemas (i.e. public.account may have relations with public.contact and vip.contact).

# Example

vendorTable.hasManyTables.forEach(table => console.log(table.name));
vendorTable.hasManyTables.getAll("contact"); // All related tables named contact.

see Example schema, {@link IndexableArray}

Returns: IndexableArray‹Table, "name", never, true›


# m2mRelations

get m2mRelations(): IndexableArray‹M2MRelation, "name", never, true›

Defined in pg-structure/entity/table.ts:188

Array of many to many relationships of the table. Many to many relationships resembles has many through and belongs to many relations in ORMs. It has some useful methods and information for generating ORM classes.

Returns: IndexableArray‹M2MRelation, "name", never, true›


# m2mRelationsPk

get m2mRelationsPk(): IndexableArray‹M2MRelation, "name", never, true›

Defined in pg-structure/entity/table.ts:200

Array of many to many relationships of the table. Different from m2mRelations, this only includes relations joined by Primary Foreign Keys in join table. Primary Foreign Key means foreign key of join table which are also primary key of join table at the same time. M2MRelation resembles has many through and belongs to many relations in ORMs. It has some useful methods and information for generating ORM classes.

Returns: IndexableArray‹M2MRelation, "name", never, true›


# m2oRelations

get m2oRelations(): IndexableArray‹M2ORelation, "name", never, true›

Defined in pg-structure/entity/table.ts:218

Array of many to one relationships of the table. M2ORelation resembles belongs to relations in ORMs. It has some useful methods and information for generating ORM classes.

Returns: IndexableArray‹M2ORelation, "name", never, true›


# nameCaseType

get nameCaseType(): CaseType

Inherited from DbObject.nameCaseType

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

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


# o2mRelations

get o2mRelations(): IndexableArray‹O2MRelation, "name", never, true›

Defined in pg-structure/entity/table.ts:209

Array of one to many relationships of the table. O2MRelation resembles has many relations in ORMs. It has some useful methods and information for generating ORM classes.

Returns: IndexableArray‹O2MRelation, "name", never, true›


# primaryKey

get primaryKey(): PrimaryKey | undefined

Defined in pg-structure/entity/table.ts:116

Primary key of this table.

# Example

table.primaryKey.columns.forEach(colunn => console.log(column.name));

see {@link Table.primaryKeyColumns primaryKeyColumns} to get primary key columns directly.

Returns: PrimaryKey | undefined


# relations

get relations(): IndexableArray‹O2MRelation | M2ORelation | M2MRelation, "name", never, true›

Defined in pg-structure/entity/table.ts:226

List of all relationships of the table. They are sort by type (O2MRelation, M2ORelation, M2MRelation).

Returns: IndexableArray‹O2MRelation | M2ORelation | M2MRelation, "name", never, true›


# separator

get separator(): string

Inherited from DbObject.separator

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

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

Returns: string


# uniqueConstraints

get uniqueConstraints(): IndexableArray‹UniqueConstraint, "name", never, true›

Defined in pg-structure/entity/table.ts:91

All unique constraints in the table as an [[IndexableArray]] ordered by name.

Returns: IndexableArray‹UniqueConstraint, "name", never, true›

# Methods

# get

get(column: string): Column

Overrides Entity.get

Defined in pg-structure/entity/table.ts:274

Returns column with given name from table.

# Example

const column = entity.get('contact'),  // Returns contact column from entity.

Parameters:

Name Type
column string

Returns: Column

requested columns.


# getForeignKeysFrom

getForeignKeysFrom(from: Table | string): IndexableArray‹ForeignKey, "name", never, true›

Defined in pg-structure/entity/table.ts:60

Returns foreign keys from given table to this table.

Parameters:

Name Type Description
from Table | string is table to get foreign keys targeting this table. It could be name, full name or table object.

Returns: IndexableArray‹ForeignKey, "name", never, true›

foreign keys from given table to this table.


# getForeignKeysTo

getForeignKeysTo(target: Table | string): IndexableArray‹ForeignKey, "name", never, true›

Defined in pg-structure/entity/table.ts:49

Returns foreign keys from this table to target table.

Parameters:

Name Type Description
target Table | string is target table to get foreign keys for. It could be name, full name or table object.

Returns: IndexableArray‹ForeignKey, "name", never, true›

foreign keys from this table to target table.


# getJoinTablesTo

getJoinTablesTo(target: Table | string): IndexableArray‹Table, "name", never, true›

Defined in pg-structure/entity/table.ts:70

Returns joıin tables between this table and target table.

Parameters:

Name Type Description
target Table | string is target table to get join tables for. It could be name, full name or table object.

Returns: IndexableArray‹Table, "name", never, true›