pg-structure / Column
# Class: Column
Class which represent a column. Provides attributes and methods for details of the column.
# Hierarchy
-
↳ Column
# Properties
# arrayDimension
• Readonly
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.
Defined in: pg-structure/column.ts:154
# attributeNumber
• Readonly
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.
Defined in: pg-structure/column.ts:58
# comment
• Optional
Readonly
comment: undefined | string
Comment of the database object defined in database including {@link DbObject#commentData comment data}.
Inherited from: DbObject.comment
Defined in: pg-structure/base/db-object.ts:75
# defaultWithTypeCast
• Readonly
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.
Defined in: pg-structure/column.ts:171
# length
• Optional
Readonly
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.
Defined in: pg-structure/column.ts:235
# maxValue
• Optional
Readonly
maxValue: undefined | number
Maximum value of the column (only for integer types).
Defined in: pg-structure/column.ts:245
# minValue
• Optional
Readonly
minValue: undefined | number
Minimum value of the column (only for integer types).
Defined in: pg-structure/column.ts:240
# name
• Readonly
name: string
Name of the database object.
Defined in: pg-structure/base/db-object.ts:42
# notNull
• Readonly
notNull: boolean
true
if column is not allowed to be null.
Defined in: pg-structure/column.ts:116
# parent
• Readonly
parent: Entity | CompositeType
Parent database object this column belongs to.
Defined in: pg-structure/column.ts:63
# precision
• Optional
Readonly
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.
Defined in: pg-structure/column.ts:147
# scale
• Optional
Readonly
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.
Defined in: pg-structure/column.ts:134
# type
• Readonly
type: Type
Data type of the column.
Defined in: pg-structure/column.ts:119
# 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
# db
• get db(): Db
Database of the database object.
Returns: Db
Defined in: pg-structure/base/db-object.ts:68
# 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
Defined in: pg-structure/column.ts:186
# 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
Defined in: pg-structure/column.ts:71
# foreignKeys
• get foreignKeys(): default<ForeignKey, name, never, true>
[[IndexableArray]] of foreign keys which column is part of.
Returns: default<ForeignKey, name, never, true>
Defined in: pg-structure/column.ts:194
# 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 object with '.' notation including Schema name.
# Example
const fullName = column.fullName; // public.member.name
Returns: string
Defined in: pg-structure/column.ts:111
# indexes
• get indexes(): default<Index, name, never, true>
IndexableArray of indexes, which column is part of.
Returns: default<Index, name, never, true>
Defined in: pg-structure/column.ts:204
# 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
Defined in: pg-structure/column.ts:215
# 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
Defined in: pg-structure/column.ts:222
# isSerial
• get isSerial(): boolean
Whether this column has nextval()
default value or one of serial
(auto incremented) types.
Returns: boolean
Defined in: pg-structure/column.ts:122
# 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
# parentalName
• get parentalName(): string
Name of the object with '.' notation including its parent Table name.
# Example
const parentalName = column.parentalName; // member.name
Returns: string
Defined in: pg-structure/column.ts:101
# referencedColumns
• get referencedColumns(): default<Column, name, never, true>
All referenced columns in all foreign keys by this column.
Returns: default<Column, name, never, true>
Defined in: pg-structure/column.ts:251
# schema
• get schema(): Schema
Schema this column belongs to.
Returns: Schema
Defined in: pg-structure/column.ts:263
# 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
# 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
Defined in: pg-structure/column.ts:81
# 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>
Defined in: pg-structure/column.ts:285
# 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>
Defined in: pg-structure/column.ts:274
# 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
Defined in: pg-structure/column.ts:91