Sedentary
The base ORM class.
new Sedentary([options])
options?: SedentaryOptions - default{}- The global options.returns the Sedentary object to interact with the database.
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 isfalse, overrides whether to run the sync process for this connect (true= sync,false= skip). Ignored whenautoSyncistrue.
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()
returns a Promise which resolves to a Transaction object.
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])
options?: AttributeOptions - optional - Attribute options.returns a
BOOLEANType.
sedentary.DateTime([options])
options?: AttributeOptions - optional - Attribute options (e.g.defaultValuefor dates). See Entries initialization.returns a
DATETIMEType.
sedentary.FKey(attribute[, options])
attribute: Model attribute - required - The foreign key target attribute (must beunique).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])
options?: AttributeOptionsSize - optional -size:4(32-bit) or8(64-bit), default8.returns a
FLOATType.
sedentary.Int([options])
options?: AttributeOptionsSize - optional -size:2(16-bit) or4(32-bit), default4.returns an
INTType.
sedentary.Int8([options])
options?: AttributeOptions - optional - Attribute options.returns an
INT8Type (64-bit integer, maps to BigInt in JavaScript).
sedentary.JSON([options])
options?: AttributeOptions - optional - Attribute options.returns a
JSONType.
sedentary.None([options])
options?: AttributeOptions - optional - Attribute options.returns a
NONEType (virtual attribute, no database column).
sedentary.Number([options])
options?: AttributeOptions - optional - Attribute options.returns a
NUMBERType (arbitrary precision).
sedentary.VarChar([options])
options?: AttributeOptionsSize - optional -size: max string length at database level.returns a
VARCHARType.