pg-structure / Schema

# Class: Schema

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

# Hierarchy

# Properties

# aggregateFunctions

Readonly aggregateFunctions: default<AggregateFunction, name, never, true>

All aggregateFunctions of the schema as an {@link IndexableArray indexable array} ordered by name.

# Example

const functionArray   = schema.aggregateFunctions;
const isAvailable     = schema.aggregateFunctions.has('some_function');
const function        = schema.aggregateFunctions.get('some_function');
const name            = aggregateFunctions.name;

schema.tables.forEach(table => console.log(table.name));

Defined in: pg-structure/schema.ts:162


# 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


# materializedViews

Readonly materializedViews: default<MaterializedView, name, never, true>

All materialized views of the schema as an {@link IndexableArray indexable array} ordered by name.

# Example

const mViewArray   = schema.materializedViews;
const isAvailable  = schema.materializedViews.has('admin_person');
const mView        = schema.materializedViews.get('big_account');
const name         = mView.name;

schema.materializedViews.forEach(mView => console.log(mView.name));

Defined in: pg-structure/schema.ts:91


# name

Readonly name: string

Name of the database object.

Inherited from: DbObject.name

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


# normalFunctions

Readonly normalFunctions: default<NormalFunction, name, never, true>

All normalFunctions of the schema as an {@link IndexableArray indexable array} ordered by name.

# Example

const functionArray   = schema.normalFunctions;
const isAvailable     = schema.normalFunctions.has('some_function');
const function        = schema.normalFunctions.get('some_function');
const name            = normalFunctions.name;

schema.tables.forEach(table => console.log(table.name));

Defined in: pg-structure/schema.ts:136


# oid

Readonly oid: number

Object identifier for the Schema

Defined in: pg-structure/schema.ts:43


# procedures

Readonly procedures: default<Procedure, name, never, true>

All procedures of the schema as an {@link IndexableArray indexable array} ordered by name.

# Example

const functionArray   = schema.procedures;
const isAvailable     = schema.procedures.has('some_procedure');
const function        = schema.procedures.get('some_procedure');
const name            = procedures.name;

schema.tables.forEach(table => console.log(table.name));

Defined in: pg-structure/schema.ts:149


# schema

Readonly schema: Schema

Schema of the object.

Overrides: DbObject.schema

Defined in: pg-structure/schema.ts:214


# sequences

Readonly sequences: default<Sequence, name, never, true>

All sequences of the schema as an {@link IndexableArray indexable array} ordered by name.

# Example

const sequenceArray  = schema.sequences;
const isAvailable    = schema.sequences.has('person_id_seq');
const sequence       = schema.sequences.get('account_id_seq');
const name           = sequence.name;

schema.sequences.forEach(sequence => console.log(sequence.name));

Defined in: pg-structure/schema.ts:104


# tables

Readonly tables: default<Table, name, never, true>

All tables of the schema as an {@link IndexableArray indexable array} ordered by name.

# Example

const tableArray   = schema.tables;
const isAvailable  = schema.tables.has('person');
const table        = schema.tables.get('account');
const name         = table.name;

schema.tables.forEach(table => console.log(table.name));

Defined in: pg-structure/schema.ts:65


# typesIncludingEntities

Readonly typesIncludingEntities: default<Type, name, oid | classOid | internalName, true>

All custom database types of the schema as an {@link IndexableArray indexable array} ordered by name. This list includes types originated from entities such as tables, views and materialized views. Entities are also composite types in PostgreSQL. To exclude types originated from entities use types method.

# Example

const typeArray    = schema.typesIncludingEntities;
const isAvailable  = schema.typesIncludingEntities.has('address');
const type         = schema.typesIncludingEntities.get('address');
const columns      = type.columns;

Defined in: pg-structure/schema.ts:188


# views

Readonly views: default<View, name, never, true>

All views of the schema as an {@link IndexableArray indexable array} ordered by name.

# Example

const viewArray    = schema.views;
const isAvailable  = schema.views.has('admin_person');
const view         = schema.views.get('big_account');
const name         = view.name;

schema.views.forEach(view => console.log(view.name));

Defined in: pg-structure/schema.ts:78


# windowFunctions

Readonly windowFunctions: default<WindowFunction, name, never, true>

All windowFunctions of the schema as an {@link IndexableArray indexable array} ordered by name.

# Example

const functionArray   = schema.windowFunctions;
const isAvailable     = schema.windowFunctions.has('some_function');
const function        = schema.windowFunctions.get('some_function');
const name            = windowFunctions.name;

schema.tables.forEach(table => console.log(table.name));

Defined in: pg-structure/schema.ts:175

# 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


# entities

• get entities(): default<Entity, name, never, true>

All entities (tables and views) of the schema as an {@link IndexableArray indexable array} ordered by name.

Returns: default<Entity, name, never, true>

Defined in: pg-structure/schema.ts:50


# 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 database object including parent name.

Returns: string

Defined in: pg-structure/schema.ts:216


# functions

• get functions(): default<Func, name, never, true>

All {@link Function functions} of the schema as an {@link IndexableArray indexable array} ordered by name.

# Example

const functionArray   = schema.functions;
const isAvailable     = schema.functions.has('some_function');
const function        = schema.functions.get('some_function');
const name            = function.name;

schema.tables.forEach(table => console.log(table.name));

Returns: default<Func, name, never, true>

Defined in: pg-structure/schema.ts:118


# 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


# types

• get types(): default<Type, name, oid | classOid | internalName, true>

All custom database types of the schema as an {@link IndexableArray indexable array} ordered by name. This list excludes types originated from entities such as tables, views and materialized views. Entities are also composite types in PostgreSQL. To get all types including entities use typesIncludingEntities method.

# Example

const typeArray    = schema.types;
const isAvailable  = schema.types.has('address');
const type         = schema.types.get('address');
const columns      = type.columns;

Returns: default<Type, name, oid | classOid | internalName, true>

Defined in: pg-structure/schema.ts:207

# Methods

# get

get(path: string): Column | Entity

Returns table, view or column on given path in schema. Path should be in dot (.) notation.

Note for TypeScript users: Since get() could return one of the many possible types, you may need to specify your expected type using as. i.e. const result = db.get("public.account") as Table;

# Example

const table  = db.get('contact');      // Returns contact table in public schema.
const column = db.get('contact.name'); // Returns name column of the contact table.

# Parameters:

Name Type Description
path string is the path of the requested item in dot (.) notation such as 'public.contact'

Returns: Column | Entity

requested database object.

Defined in: pg-structure/schema.ts:232