Sedentary

The base ORM class.

new Sedentary([options])

Warning

Do not use this constructor directly.

new SedentaryPG(connection[, options])

  • connection: pg.PoolConfig - required - The connection configuration object.

  • options?: SedentaryOptions - default {} - The global options.

  • returns the SedentaryPG object to interact with the database.

SedentaryPG uses pg.Pool to connect to the database; please refer to pg and its pg-documentation for details about the connection object.

sedentary.client()

(Only on SedentaryPG.)

Acquires a client from the connection pool for raw SQL queries. Remember to release() the client when done.

sedentary.connect([sync])

  • sync: boolean - optional - When autoSync is false, overrides whether to run the sync process for this connect (true = sync, false = skip). Ignored when autoSync is true.

  • returns a Promise which resolves with void.

Connects to the database and eventually syncs the schema.

Note

Must be called only once.

sedentary.end()

Closes the connection with the database.

Note

Must be called only once, after sedentary.connect().

sedentary.begin()

Begins a new transaction.

sedentary.sync()

Manually runs the sync process to align the database schema with the configured Models.

sedentary.model(name, attributes[, options [, methods]])

  • name: string - required - The name of the model.

  • attributes: AttributesDefinition - required - The object with the attribute definitions.

  • options?: ModelOptions - default {} - The options of the model.

  • methods?: Methods - default {} - The JavaScript level methods of the model.

  • returns a new class Model to interact with the table.

Defines one model. Should be called once for each model/table to be configured.

Note

Must be called before sedentary.connect().

Type functions

All type functions accept an optional AttributeOptions object. Functions that support a size option (Int, Float, VarChar) use AttributeOptionsSize instead.

sedentary.Boolean([options])

sedentary.DateTime([options])

sedentary.FKey(attribute[, options])

  • attribute: Model attribute - required - The foreign key target attribute (must be unique).

  • options?: ForeignKeyOptions - default {} - The foreign key options.

  • returns the Type of the target attribute.

It is the type function to specify a foreign key. Pass the target model’s primary key attribute (e.g. Foo.id) or any unique attribute.

sedentary.Float([options])

sedentary.Int([options])

sedentary.Int8([options])

sedentary.JSON([options])

sedentary.None([options])

  • options?: AttributeOptions - optional - Attribute options.

  • returns a NONE Type (virtual attribute, no database column).

sedentary.Number([options])

  • options?: AttributeOptions - optional - Attribute options.

  • returns a NUMBER Type (arbitrary precision).

sedentary.VarChar([options])