What is Schema?
Schema is a class that maps to a database table. You can create an schema by defining a new class and mark it with @Schema
/* ./schemas/photo.ts */
import { Schema, Column, Unique, Default } from 'nexorm/decorators';
@Schema
class PhotoSchema {
@Column
@Unique
static photoId = String;
@Column
static photo = Buffer;
@Column
@Default(new Date())
static date = Date;
};
This will create following database table:
+-------------+--------------+----------------------------+
| PhotoSchema |
+-------------+--------------+----------------------------+
| photoId | Text | UNIQUE |
| photo | Blob | |
| date | Date | DEFAULT '2025-01-01' |
+-------------+--------------+----------------------------+
Each schema must be registered in your model:
import Model from 'nexorm/model';
/*
......
......
... */
export default new Model(PhotoSchema);
Last updated