Db

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

Kind: global class

new Db(args, options)

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

Param Type Default Description
args Object Attributes of the Database instance to be created.
args.name Object Name of the Db instance.
options Object Options to modify behaviour of classes.
[options.cache] boolean true Use cache to memoize calculated results.

db.name : string

Name of the Database.

Kind: instance property of Db
Read only: true

db.fullName : string

Full name of the Database with (.) notation. Since database does not have a parent this equals database name.

Kind: instance property of Db
Read only: true

db.fullCatalogName : string

Full name of the Database with (.) notation including catalog name. Since database does not have a parent this equals database name.

Kind: instance property of Db
Read only: true

db.options : Object

Options passed to during initialization.

Kind: instance property of Db
Read only: true

db.schemas : Map.<Schema>

All Schema instances in the database as a Map. Schemas are ordered by their name.

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

let isAvailable  = db.schemas.has('another_schema');
let schemaNames  = Array.from(db.schemas.keys());           // Use spread operator to get schema names as an array.
let public       = db.schemas.get('public');
let name         = public.name;

for (let schema of db.schemas.values()) {
    console.log(schema.name);
}

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

db.get(path) ⇒ Schema | Table | Column | undefined

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

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

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

Example

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