Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Column

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

Hierarchy

Index

Properties

Readonly arrayDimension

arrayDimension: number

If type is an array, this is the dimension of the array. Otherwise this is 0. NOTE: Array columns in views has dimension of 1 regardless of the actual dimension. Currently we could not find a way to determine array dimensions in views.

Readonly attributeNumber

attributeNumber: number

The number of the column. Ordinary columns are numbered from 1 up. Since dropped columns have an attribute number too, attribute number may be different from array index number.

Optional Readonly comment

comment: undefined | string

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

Readonly defaultWithTypeCast

defaultWithTypeCast: null | string

Default expression of the column with typecast. PostgreSQL returns default values with typecast. Default values includes single quotes except sql functions and numeric values. Also sql functions and numeric values do not contain type cast.

Numeric values are returned as string too. Please see: https://github.com/brianc/node-postgres/issues/1300

Example

const table = db('crm').schema('public').table('contact');
const defaultName = table.get("name").default;                     // "'George'"
const defaultNameWithCast = table.get("name").defaultWithTypeCast; // "'George'::character varying"
const defaultAge = table.get("age").default;                       // 20
const defaultStamp = table.get("created_at").default;              // "now()"
see

Column.default for accessing default values without typecast.

Optional Readonly length

length: undefined | number

Length of the column.

  • For data type identified as a character or bit string type, this is the declared maximum length. If column is an array, same rule applies data type of the array.
  • For character arrays or bit string type arrays, this is the declared maximum length of the array's data type.
  • For arrays atttypmod records type-specific data supplied at table creation time (for example, the maximum length of a varchar column). It is passed to type-specific input functions and length coercion functions.
  • This value is undefined for all other data types or if no maximum length was declared.

Optional Readonly maxValue

maxValue: undefined | number

Maximum value of the column (only for integer types).

Optional Readonly minValue

minValue: undefined | number

Minimum value of the column (only for integer types).

Readonly name

name: string

Name of the database object.

Readonly notNull

notNull: boolean

true if column is not allowed to be null.

Readonly parent

Parent database object this column belongs to.

Optional Readonly precision

precision: undefined | number
  • If data type identifies a numeric type, this contains the (declared or implicit) precision of the type for this column. The precision indicates the number of significant digits.
  • If data type identifies a date, time, timestamp, or interval type, this column contains the (declared or implicit) fractional seconds precision of the type for this attribute, that is, the number of decimal digits maintained following the decimal point in the seconds value.
  • If data type is an array. Same rules apply for the data type of the array, and this value would become precision of the data type of the array.
  • For all other data types, this is undefined. For example: The number 23.5141 has a precision of 6 and a scale of 4.

Optional Readonly scale

scale: undefined | number
  • If data type identifies an exact numeric type, this contains the (declared or implicit) scale of the type for this attribute. The scale indicates the number of significant digits to the right of the decimal point.
  • If data type is an array. Same rule applies for the data type of the array, and this value would become scale of the data type of the array.
  • For all other data types, this is undefined. For example: The number 23.5141 has a precision of 6 and a scale of 4. Integers can be considered to have a scale of zero.

Readonly type

type: Type

Data type of the column.

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

default

  • get default(): null | string | number | boolean
  • Default value without typecast. Default values includes single quotes except sql functions and numeric values.

    Numeric values are returned as string too. Please see: https://github.com/brianc/node-postgres/issues/1300

    Example

    const table = db('crm').schema('public').table('contact');
    const defaultName = table.get("name").default;                     // "'George'"
    const defaultNameWithCast = table.get("name").defaultWithTypeCast; // "'George'::character varying"
    const defaultAge = table.get("age").default;                       // 20
    const defaultStamp = table.get("created_at").default;              // "now()"
    
    see

    Column.defaultWithTypeCast for default values with typecast as returned by PostgreSQL

    Returns null | string | number | boolean

entity

  • get entity(): undefined | Entity
  • Entity this column belongs to if it belongs to a table or view.

    Example

    const entity = column.entity; // Entity instance
    

    Returns undefined | Entity

foreignKeys

  • get foreignKeys(): default<ForeignKey, "name", never, true>
  • [[IndexableArray]] of foreign keys which column is part of.

    Returns 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 = column.fullName; // public.member.name
    

    Returns string

indexes

  • get indexes(): default<Index, "name", never, true>
  • IndexableArray of indexes, which column is part of.

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

isForeignKey

  • get isForeignKey(): boolean
  • Whether this column is part of a foreign key. Please note that a foreign key may contain more than one column and a column may part of more than one foreign key.

    Returns boolean

isPrimaryKey

  • get isPrimaryKey(): boolean
  • Whether column is part of a primary key. Please note that a primary key may contain more than one column.

    Returns boolean

isSerial

  • get isSerial(): boolean
  • Whether this column has nextval() default value or one of serial (auto incremented) types.

    Returns boolean

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

parentalName

  • get parentalName(): string
  • Name of the object with '.' notation including its parent Table name.

    Example

    const parentalName = column.parentalName; // member.name
    

    Returns string

referencedColumns

  • get referencedColumns(): default<Column, "name", never, true>
  • All referenced columns in all foreign keys by this column.

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

schema

  • Schema this column belongs to.

    Returns Schema

separator

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

    Returns string

table

  • get table(): undefined | Table
  • Table this column belongs to if it belongs to a table.

    Example

    const table = column.table; // Table instance
    

    Returns undefined | Table

uniqueIndexes

  • get uniqueIndexes(): default<Index, "name", never, true>
  • [[IndexableArray]] of unique indexes, which column is part of. PostgreSQL already creates a unique index for unique constraints. So there is no need to look for unique constraints which will result duplicates.

    see

    Column.uniqueIndexesNoPk for unique indexes excluding primary key indexes.

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

uniqueIndexesNoPk

  • get uniqueIndexesNoPk(): default<Index, "name", never, true>
  • [[IndexableArray]] of unique indexes, which column is part of. Excludes primary key indexes. PostgreSQL already creates a unique index for unique constraints. So there is no need to look for unique constraints which will result duplicates.

    see

    Column.uniqueIndexes for all unique indexes including primary key indexes.

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

view

  • get view(): undefined | View
  • View this column belongs to if it belongs to a view.

    Example

    const table = column.view; // Table instance
    

    Returns undefined | View

Generated using TypeDoc