PropertyType

There are various kinds of PropertyType that represent different SQL data-type

Class NameDescriptionFieldProperty applicable?ComputeProperty applicable?Options
PrimaryKeyTypePrimary Key with Auto IncrementYesNo
NumberTypeNullable IntegerYesYes{default?: number }
NumberNotNullTypeNon-nullable IntegerYesYes{default?: number }
DecimalTypeNullable DecimalYesYes{ default?: number, precision?: number, scale?: number }
DecimalNotNullTypeNon-nullable DecimalYesYes{ default?: number, precision?: number, scale?: number }
BooleanTypeNullable BooleanYesYes{default?: boolean }
BooleanNotNullTypeNon-nullable BooleanYesYes{default?: boolean }
StringTypeNullable VarcharYesYes{default?: string, length?: number }
StringNotNullTypeNon-nullable VarcharYesYes{default?: string, length?: number }
DateTypeNullable DateYesYes{ default?: Date }
DateNotNullTypeNon-nullable DateYesYes{ default?: Date }
DateTimeTypeNullable DatetimeYesYes{default?: Date, precision?: number }
DateTimeNotNullTypeNon-nullable DatetimeYesYes{default?: Date, precision?: number }
ObjectTypeNullable ObjectNoYesn/a
ArrayTypeNullable Array of ObjectNoYesn/a

Usage

Define a data-type for a FieldProperty

Example:

class MyModel extends Model {
    //define a non-nullable varchar type data
    prop1 = this.field(StringNotNullType)

    //define a non-nullable varchar type data
    // with max length 50
    prop2 = this.field(new StringNotNullType({length: 50}) )
}
1
2
3
4
5
6
7
8

Define a data-type for a Scalar

Example:

// make a SQL value with type NumberNotNullType
const scalar = context.scalar('5 + 10 + ?', [15], NumberNotNullType)
1
2