From 061d1b2bc4b90050c289812618ce85aa57172afa Mon Sep 17 00:00:00 2001 From: Nicco Date: Sun, 30 Aug 2020 14:48:26 +0200 Subject: [PATCH] Create README.md --- README.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..792af24 --- /dev/null +++ b/README.md @@ -0,0 +1,42 @@ +# mikro-orm-arp + +Active Record Pattern for Mikro-ORM. + +Ads the own repository functions to the class as static functions so you don't have to always retrieve them. + +## 🏗 Installation + +```bash +npm install mikro-orm-arp +``` + +## 🚀 Usage + +```js +import { MikroORM, Entity, Property } from '@mikro-orm/core' +import { register, BaseEntity } from 'mikro-orm-arp' + +@Entity() +export class Book extends BaseEntity { + @Property() + name: string = '' +} + +MikroORM.init({ + entities: [Book, BaseEntity], + // ... +}).then(async (db) => { + register(db) + + // Find one + const book: Book = await Book.findOneOrFail({ name: 'Journey to the center of the earth' }) + + // Create and save + const newBook = Book.create({ name: '' }) + Book.persist(newBook) + await Book.flush + + // Repo + const bookRepo = Book.getRepo() +}) +```