Skip to main content

Types

Normal Types

Normal types are types of data that are stored in the same table and are not relations.

For example

const user = new EzModel('User',{
name: Type.VARCHAR
})
NameDescriptionJS TypeSample
Type.VARCHARA stringstring'hello'
Type.INTAn integernumber1
Type.FLOATA floating point numbernumber1.00
Type.DATEA datestring"2021-08-11T15:36:56.078Z"
Type.JSONA JS objectobject{hello:"world"}

You may need to specify additional restrictions, for example the maximum length of a name. For example

const user = new EzModel('User',{
name: {
type: Type.VARCHAR,
length: 50
}
})

EzBackend uses typeorm with seperate entity definitions under the hood, so all of the additional options available in typeorm are also available in EzBackend

Relation Types

Relation Types are used to reference data from different tables. For relation types it is necessary to specify additional properties so that EzBackend can understand the relationship

For example, in a ONE_TO_ONE relation:

const example = new EzModel('sample',{
detail: {
type: Type.ONE_TO_ONE,
target: 'detail', //Required
cascade: true, //Optional
eager: true, //Optional
joinColumn: true //Optional
}
})
info

For a relation XXX_TO_YYY

XXX - Refers to the current model

YYY - Refers to the other model

NameDescriptionJS TypeSampleRequired PropertiesOptional Properties
Type.ONE_TO_ONEA JS objectobject{hello:"world"}target joinColumncascade eager onDelete onUpdate
Type.ONE_TO_MANYA JS objectobject{hello:"world"}target inverseSidecascade eager onDelete onUpdate
Type.MANY_TO_ONEA JS objectobject{hello:"world"}target inverseSidecascade eager onDelete onUpdate
Type.MANY_TO_MANYA JS objectobject{hello:"world"}target joinTablecascade eager onDelete onUpdate

Furthermore, some relations have required properties:

Relation Required Properties

target (string) - the modelName of the model that is being pointed to, e.g

const detail = new EzModel('detail',{})

const example = new EzModel('sample',{
detail: {
type: Type.ONE_TO_ONE,
target: 'detail'
}
})

inverseSide (string) - the property name on the other model, e.g

const program = new EzModel('program',{
participants: { //HERE THE PROPERTY NAME IS PARTICIPANT(S)
type: Type.ONE_TO_MANY
target: 'participant',
inverseSide: 'program'
}
})

const participant = new EzModel('participant',{
detail: {
type: Type.MANY_TO_ONE,
target: 'program',
inverseSide: 'participants' //NOTICE THE 'S' IN PARTICIPANTS
}
})

joinColumn (boolean) - Specifies that this side of the relation contains the foreign key explanation

joinTable (boolean) - Specified that this side of the relation contains the foreign key to a join table explanation

Relation Optional Properties

OptionDescriptiondefault value
eagerLoads the nested data on GET if truefalse
cascadeUpdates the nested data on PATCH if truefalse
onDeleteRestricts Delete if nested data existsRESTRICT
onDeleteDeletes Nested data if nested data existsRESTRICT