Schema

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

Kind: global class

new Schema(args)

Constructor function. You don't need to call constructor manually. pg-structure handles this.

Param Type Description
args Object Attributes of the Schema instance to be created.
args.parent Db Parent Db of the Schema.
args.name string Name of the Schema.
args.description string Description of the Schema.

schema.name : string

Name of the schema.

Kind: instance property of Schema
Read only: true

schema.fullName : string

Full name of the Schema. For schema it is equal to schema name.

Kind: instance property of Schema
Read only: true
Example

var fullName = schema.fullName; // public

schema.fullCatalogName : string

Full name of the Schema with (.) notation including catalog name.

Kind: instance property of Schema
Read only: true
Example

var fullCatalogName = schema.fullCatalogName; // crm.public

schema.db : Db

Db this schema belongs to.

Kind: instance property of Schema
Read only: true
See: Aliases parent
Example

var db = schema.db; // Db instance

schema.parent : Db

Db this schema belongs to.

Kind: instance property of Schema
Read only: true
See: Aliases db
Example

var db = schema.parent; // Db instance

schema.comment : string

Comment of the schema.

Kind: instance property of Schema
Read only: true
See: Aliases description

schema.description : string

Comment of the schema.

Kind: instance property of Schema
Read only: true
See: Aliases comment

schema.tables : Map.<Table>

All Table instances of the schema as a Map. They are ordered by their name.

Kind: instance property of Schema
Read only: true
See: Map
Example

let isAvailable  = schema.tables.has('person');
let tableNames   = Array.from(schema.tables.keys());        // Use spread operator to get table names as an array.
let table        = schema.tables.get('account');
let name         = table.name;

for (let table of schema.tables.values()) {
    console.log(table.name);
}

for (let [name, table] of schema.tables) {
    console.log(name, table.name);
}

schema.types : Map.<Type>

All Type instances of the schema as a Map. They are ordered by their name.

Kind: instance property of Schema
Read only: true
See: Map
Example

let isAvailable  = schema.types.has('address');
let typeNames    = Array.from(schema.types.keys());        // Use spread operator to get table names as an array.
let type         = schema.types.get('address');
let columns         = type.columns;

schema.get(path) ⇒ Table | Column | undefined

Returns Table or Column on given path relative to Schema. Path should be in dot (.) notation.

Kind: instance method of Schema
Returns: Table | Column | undefined - - Requested item.

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

Example

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