Describes a field on a model.
Multiple options can be passed to the decorator:
primaryKey
unique
nullable
default
type
index
{ primaryKey: false, unique: false, nullable: !primaryKey,} Copy
{ primaryKey: false, unique: false, nullable: !primaryKey,}
class User extends Model { @Field({ primaryKey: true }) id: number @Field({ unique: true }) username: string @Field({ default: 0 }) balance: number @Field({ default: () => new Date() }) createdAt: Date @Field({ index: false }) profilePicture: Blob} Copy
class User extends Model { @Field({ primaryKey: true }) id: number @Field({ unique: true }) username: string @Field({ default: 0 }) balance: number @Field({ default: () => new Date() }) createdAt: Date @Field({ index: false }) profilePicture: Blob}
Describes a field on a model.
Multiple options can be passed to the decorator:
primaryKey: Whether the field is the primary key of the model, if multiple fields are marked as primary key, their combination will be the key.unique: Whether the field has an unique constraint. This will be enforced by the database.nullable: Whether the field can be null, primary keys cannot be nullable.default: The default value of the field, it can be a value or a function that returns the value.type: The type of the field, it is automatically inferred with typescript.index: Whether the field should be indexed, it is recommended to keep it unless the type isn't indexable (eg. a Blob).