Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Index

Properties

Readonly columns

columns: default<Column, "name", "attributeNumber", true> = ...

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 Readonly comment

comment: undefined | string

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

Readonly constraints

constraints: default<Constraint, "name", never, true> = ...

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

Readonly foreignKeysToThis

foreignKeysToThis: default<ForeignKey, "name", never, true> = ...

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.

Readonly indexes

indexes: default<Index, "name", never, true> = ...

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

Readonly name

name: string

Name of the database object.

Readonly oid

oid: number

Object identifier for the Entity

Readonly schema

schema: Schema

Schema of the object.

Readonly triggers

triggers: default<Trigger, "name", never, true> = ...

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

Accessors

belongsToManyTables

  • get belongsToManyTables(): default<Table, "name", never, true>
  • 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 default<Table, "name", never, true>

belongsToManyTablesPk

  • get belongsToManyTablesPk(): default<Table, "name", never, true>
  • 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 default<Table, "name", never, true>

belongsToTables

  • get belongsToTables(): default<Table, "name", never, true>
  • 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 default<Table, "name", never, true>

checkConstraints

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. 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 undefined | null | string | number | boolean | JSONObject | JSONArray

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

db

  • get db(): Db
  • Database of the database object.

    Returns Db

exclusionConstraints

foreignKeys

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

fullCatalogName

  • get fullCatalogName(): string
  • Full name of the database object including database name.

    Returns string

fullName

  • get fullName(): string
  • Full name of the object with '.' notation including Schema name.

    Example

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

    Returns string

hasManyTables

  • get hasManyTables(): default<Table, "name", never, true>
  • 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 default<Table, "name", never, true>

m2mRelations

  • get m2mRelations(): default<M2MRelation, "name", never, true>

m2mRelationsPk

  • get m2mRelationsPk(): default<M2MRelation, "name", never, true>
  • 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 default<M2MRelation, "name", never, true>

m2oRelations

  • get m2oRelations(): default<M2ORelation, "name", never, true>
  • 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 default<M2ORelation, "name", never, true>

nameCaseType

  • 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(): default<O2MRelation, "name", never, true>
  • 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 default<O2MRelation, "name", never, true>

primaryKey

  • Primary key of this table.

    Example

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

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

    Returns undefined | PrimaryKey

relations

separator

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

    Returns string

uniqueConstraints

Methods

get

  • Returns column with given name from table.

    Example

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

    Parameters

    • column: string

    Returns Column

    requested columns.

getForeignKeysFrom

  • getForeignKeysFrom(from: string | Table): default<ForeignKey, "name", never, true>
  • Returns foreign keys from given table to this table.

    Parameters

    • from: string | Table

      is table to get foreign keys targeting this table. It could be name, full name or table object.

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

    foreign keys from given table to this table.

getForeignKeysTo

  • getForeignKeysTo(target: string | Table): default<ForeignKey, "name", never, true>
  • Returns foreign keys from this table to target table.

    Parameters

    • target: string | Table

      is target table to get foreign keys for. It could be name, full name or table object.

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

    foreign keys from this table to target table.

getJoinTablesTo

  • getJoinTablesTo(target: string | Table): default<Table, "name", never, true>
  • Returns join tables between this table and target table.

    Parameters

    • target: string | Table

      is target table to get join tables for. It could be name, full name or table object.

    Returns default<Table, "name", never, true>

Private getThroughConstraints

  • Returns through constraints.

    Parameters

    • onlyPk: boolean = false

      is whether to include only PK column constraints.

    Returns { toOther: ForeignKey; toThis: ForeignKey }[]

    through constraints and their details.

Generated using TypeDoc