Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Db

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

Hierarchy

  • Db

Index

Properties

Readonly id

id: number = ...

Random assigned id to db.

Readonly name

name: string

Name of database.

Private queryResults

queryResults: QueryResults

SQL query results returned from database to build pg-structure.

Readonly schemas

schemas: default<Schema, "name", "oid", true> = ...

All schemas in the database as an {@link IndexableArray indexable array} ordered by their name.

Example

const schemaArray  = db.schemas;
const isAvailable  = db.schemas.has('another_schema');
const public       = db.schemas.get('public');
const name         = public.name;
const names = db.schemas.map(schema => schema.name);

Readonly serverVersion

serverVersion: string

Version of the PostgreSQL Engine

Accessors

allTypes

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

entities

  • get entities(): default<Entity, "name", "oid", true>
  • All entities of the database. Returned array have all objects, you may loop over them. However two PostgreSQL schemas may have same named entity. get method of {@link IndexableArray https://www.npmjs.com/package/indexable-array} returns first one. You may also use getAll or get(1234, { key: oid }).

    Returns default<Entity, "name", "oid", true>

functions

  • get functions(): default<Func, "name", "oid", true>
  • All entities of the database. Returned array have all objects, you may loop over them. However two PostgreSQL schemas may have same named entity. get method of {@link IndexableArray https://www.npmjs.com/package/indexable-array} returns first one. You may also use getAll or get(1234, { key: oid }).

    Returns default<Func, "name", "oid", true>

indexes

  • get indexes(): default<Index, "name", "oid", true>
  • All indexes of the database. Returned array have all objects, you may loop over them. However two PostgreSQL schemas may have same named index. get method of {@link IndexableArray https://www.npmjs.com/package/indexable-array} returns first one. You may also use getAll or get(1234, { key: oid }).

    Returns default<Index, "name", "oid", true>

relationNameCollisions

  • Name collisions of table relations if there are any, otherwise undefined.

    Returns undefined | CollisionsByTable

systemTypes

  • get systemTypes(): default<Type, "name", "oid" | "classOid" | "arrayOid" | "internalName", true>
  • All system types of the database. Returned array have all objects, you may loop over them. However two PostgreSQL schemas may have same named type. get method of {@link IndexableArray https://www.npmjs.com/package/indexable-array} returns first one. You may also use getAll or get(1234, { key: oid }).

    see

    types, typesIncludingEntities, allTypes

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

tables

  • get tables(): default<Table, "name", "oid", true>
  • All tables of the database. Returned array have all objects, you may loop over them. However Returned array have all objects, you may loop over them. However two PostgreSQL schemas may have same named table. get method of {@link IndexableArray https://www.npmjs.com/package/indexable-array} returns first one. You may also use getAll or get(1234, { key: oid }).

    Returns default<Table, "name", "oid", true>

types

  • get types(): default<Type, "name", "oid" | "classOid" | "arrayOid" | "internalName", true>
  • All user defined types of the database excluding entities such as table, {@link Views view}, materialized view and sequence types. Entities are also composite types in PostgreSQL. To get all types including entities use typesIncludingEntities method. Returned array have all objects, you may loop over them. However two PostgreSQL schemas may have same named type. get method of {@link IndexableArray https://www.npmjs.com/package/indexable-array} returns first one. You may also use getAll or get(1234, { key: oid }).

    see

    typesIncludingEntities, systemTypes, allTypes

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

typesIncludingEntities

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

Methods

get

  • Returns schema, table or column for given path. Path should be in dot (.) notation. If no schema is provided looks into public schema as PostgreSQL does.

    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") as Schema;

    Example

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

    Parameters

    • path: string

      is the path of the requested item in dot (.) notation such as public.contact

    Returns Column | Entity | Schema

    requested database object.

serialize

  • serialize(): string
  • Serializes object.

    CAVEATS:

    • Serialized data may or may not be deserialized with another version of pg-structure. (Even between minor versions are not guaranteed).
    • Serialized data is not direct stringified version of objects.
    • Ignores relation name function provided using relationNameFunctions args, if it is not a module name.

      Example

      import pgStructure, { deserialize } from "pg-structure";
      const db = await pgStructure({ database: "db", user: "u", password: "pass" });
      const serialized = db.serialize();
      const otherDb = deserialize(serialized);
      

    Returns string

Generated using TypeDoc