pg-structure / Domain

# Class: Domain

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

# Hierarchy

# Constructors

# constructor

+ new Domain(args: DomainConstructorArgs): Domain

# Parameters:

Name Type
args DomainConstructorArgs

Returns: Domain

Defined in: pg-structure/type/domain.ts:18

# Properties

# arrayDimension

Readonly arrayDimension: number

If type is an array, this is the dimension of the array. Otherwise this is 0.

Defined in: pg-structure/type/domain.ts:77


# arrayOid

Readonly arrayOid: number

If typarray is not 0 then it identifies another row in pg_type, which is the array type having this type as element.

Inherited from: Type.arrayOid

Defined in: pg-structure/base/type.ts:53


# category

category: TypeCategory

An arbitrary classification of PostgreSQL data types that is used by the PostgreSQL parser to determine which implicit casts should be “preferred”. See related doc here (opens new window)

Inherited from: Type.category

Defined in: pg-structure/base/type.ts:98


# checkConstraints

Readonly checkConstraints: default<CheckConstraint, name, never, true>

All constraints of the constraint as an [[IndexableArray]] ordered by name.

Defined in: pg-structure/type/domain.ts:97


# classOid

Readonly classOid: number

Object identifier of PostgreSQL class (pg_catalog.pg_class) for the Entity

Inherited from: Type.classOid

Defined in: pg-structure/base/type.ts:56


# comment

Optional Readonly comment: undefined | string

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

Inherited from: Type.comment

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


# default

Readonly default: null | string | number | boolean

Default value without typecast. Default values includes single quotes except sql functions and numeric values.

Please note numeric values which may not be represented by JavaScript values are returned as strings. See here (opens new window)

# 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 [[Domain.defaultWithTypeCast]] for default values with typecast as returned by PostgreSQL

Defined in: pg-structure/type/domain.ts:92


# hasLength

hasLength: boolean

Whether the type has length property.

Inherited from: Type.hasLength

Defined in: pg-structure/base/type.ts:101


# hasPrecision

hasPrecision: boolean

Whether the type has precision property.

Inherited from: Type.hasPrecision

Defined in: pg-structure/base/type.ts:107


# hasScale

hasScale: boolean

Whether the type has scale property.

Inherited from: Type.hasScale

Defined in: pg-structure/base/type.ts:104


# internalName

Optional Readonly internalName: undefined | string

Internal name of type. Available for some builtin types.

# Example

const name = doublePrecisionType.name; // double precision
const shortName = doublePrecisionType.internalName; // float8

Inherited from: Type.internalName

Defined in: pg-structure/base/type.ts:80


# length

Optional Readonly length: undefined | number

If base type is a character type, then this is the length of the type.

Defined in: pg-structure/type/domain.ts:51


# name

Readonly name: string

Name of the database object.

Inherited from: Type.name

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


# notNull

Readonly notNull: boolean

true if domain is not allowed to be null.

Defined in: pg-structure/type/domain.ts:43


# numericType

Optional numericType: undefined | Integer | Exact | Floating

If type is a numeric type, its numerical type. If type is non-numeric this is undefined. For TypeScript it is an enum of NumericType.Integer, NumericType.Exact or NumericType.Floating. For JavaScript ir is a string of Integer, Exact or Floating.

Inherited from: Type.numericType

Defined in: pg-structure/base/type.ts:114


# oid

Readonly oid: number

Object identifier for the Entity

Inherited from: Type.oid

Defined in: pg-structure/base/type.ts:50


# precision

Optional Readonly precision: undefined | number

  • If base 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 base 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 base 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 base 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/type/domain.ts:64


# scale

Optional Readonly scale: undefined | number

  • If base 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 base 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 base 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/type/domain.ts:74


# schema

schema: Schema

Schema this type belongs to.

Inherited from: Type.schema

Defined in: pg-structure/base/type.ts:61


# shortName

Optional Readonly shortName: undefined | string

Short name of type. Available for some builtin types.

# Example

const name = timetzType.name; // time with time zone
const shortName = timetzType.shortName; // time with time zone
const name2 = varcharType.name; // character varying
const shortName2 = varcharType.name; // varchar

Inherited from: Type.shortName

Defined in: pg-structure/base/type.ts:91

# 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


# 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 = type.fullName; // public.phone_number

Returns: string

Defined in: pg-structure/base/type.ts:69


# 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


# 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


# type

• get type(): Type

Data type of the domain.

Returns: Type

Defined in: pg-structure/type/domain.ts:46