quaerateum
Version:
Simple 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 JS.
52 lines (37 loc) • 1.15 kB
text/typescript
import { ObjectID } from 'mongodb';
import { Cascade, Collection, Entity, ManyToMany, ManyToOne, PrimaryKey, Property } from '../../lib';
import { Publisher } from './Publisher';
import { Author } from './Author';
import { BookTag } from './book-tag';
import { BaseEntity3 } from './BaseEntity3';
({ collection: 'books-table' })
export class Book extends BaseEntity3 {
()
_id: ObjectID;
()
title: string;
()
author: Author;
({ cascade: [Cascade.PERSIST, Cascade.REMOVE] })
publisher: Publisher;
({ entity: () => BookTag.name, inversedBy: 'books' })
tags = new Collection<BookTag>(this);
()
metaObject: object;
()
metaArray: any[];
()
metaArrayOfStrings: string[];
constructor(title: string, author: Author) {
super();
this.title = title;
this.author = author;
}
toJSON(strict = true, strip = ['metaObject', 'metaArray', 'metaArrayOfStrings'], ...args: any[]): { [p: string]: any } {
const o = this.toObject(...args);
if (strict) {
strip.forEach(k => delete o[k]);
}
return o;
}
}