Sedentary
The base ORM class.
TODO
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(config[, options])
config
: pg.PoolConfig - required - The connection configuration object.options?
: SedentaryOptions - default{}
- The global optionsreturns 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 config
object.
sedentary.connect([sync])
sync
: boolean - defaultfalse
- Specifies whether to execute the sync process or not.
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)
attribute
: - Model | ModelAttribute - required - The foreign key target attribute.options
: - ForeignKeyOptions - default{}
- The foreign key options.returns the Type of the target attribute.
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)
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)
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.