Skip to content

DbRelation

do- edited this page Mar 30, 2025 · 20 revisions

DbRelation is a DbObject descendant describing a database table like object: a named collection of strictly structured records good to mention in the FROM clause of a SELECT SQL statement, such as:

Properties

See DbObject's Properties

Name Type Description
columns {String: DbColumn / null} Object / function data columns definitions, may be set as a function called with the DbRelation instance available as this
columnsToDrop [String] Calculated list of columns with null definition, presumed to be dropped if found existing
pk [String] the list of column names composing the primary key
keys {String: DbIndex} Object index definitions

Constructor

This class is considered abstract, so the constructor

new DbRelation ({name, columns, pk})

should never be called explicitly.

In the base implementation, it:

  • copies all properties from the given argument to this;
  • builds DbColumn instances for columns from incoming plain Objects or Strings (parsing DSL);
  • if pk came scalar, wraps it into an Array, empty Array for null or undefined pk;
  • for each element of pk, sets nullable: false for the eponymous column, or throws an Error if it's not found.
Clone this wiki locally