undeexcepturi
Version:
TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.
70 lines (64 loc) • 1.39 kB
JavaScript
const { Collection, EntitySchema } = require('@mikro-orm/core');
const { BaseEntity4 } = require('./index').BaseEntity4;
/**
* @property {number} id
* @property {Date} createdAt
* @property {Date} updatedAt
* @property {string} title
* @property {Author3} author
* @property {Publisher3} publisher
* @property {Collection<BookTag3>} tags
*/
class Book3 extends BaseEntity4 {
/**
* @param {string} title
* @param {Author3} author
*/
constructor(title, author) {
super();
this.createdAt = new Date();
this.updatedAt = new Date();
this.title = title;
this.author = author;
this.tags = new Collection(this);
}
}
const schema = new EntitySchema({
class: Book3,
extends: 'BaseEntity4',
properties: {
createdAt: {
type: 'Date',
nullable: true,
},
updatedAt: {
type: 'Date',
nullable: true,
onUpdate: () => new Date(),
},
title: {
type: 'string',
default: '',
},
author: {
kind: 'm:1',
type: 'Author3',
},
publisher: {
kind: 'm:1',
type: 'Publisher3',
nullable: true,
},
tags: {
kind: 'm:n',
owner: true,
fixedOrder: true,
inversedBy: 'books',
type: 'BookTag3',
},
},
path: __filename,
});
module.exports.Book3 = Book3;
module.exports.entity = Book3;
module.exports.schema = schema;