Sedentary

The base ORM class.

TODO

new Sedentary([options])

Warning

Do not use this constructor directly.

new SedentaryPG(config[, options])

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

sedentary.connect([sync])

  • sync: boolean - default false - Specifies whether to execute the sync process or not.

  • returns a Promise which resolves with void.

Connects to the database and eventually syncs the schema. The value of the sync argument is ignored unless the autoSync option was set to false when new Sedentary was called.

Note

Must be called only once.

sedentary.end()

Closes the connection with the database.

Note

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

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

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

  • fields: AttributesDefinition - required - The object with the fileds 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().

sedentary.DATETIME()

  • returns a DATETIME Type.

It is the Type function to specify DATETIME as type for a field.

sedentary.FKEY(attribute, options)

It is the Type function to specify a foreign key. It can be either Model or a ModelAttribute. If a Model is provided, its primary key is the target attribute.

sedentary.INT(size)

  • size: number - default: 4 - The size of the field at database level.

  • returns an INT Type.

It is the Type function to specify INT as type for a field. If the value of the size argument is 2, a 16 bit INT Type is returned; if 4, a 32 bit INT Type is returned; no other values are accepted.

sedentary.INT8

  • returns an INT Type.

It is the Type function to specify 64 bit INT as type for a field. It is a distinct Type function from sedentary.INT to give the attribute a specific type at TypeScript level. TODO

sedentary.VARCHAR(size)

  • size: number - default undefined- The size of the field at database level.

  • returns an VARCHAR Type.

It is the Type function to specify VARCHAR as type for a field. If a value of the size argument is provided, it is the maximum allowed string size at database level.