Active Record Pattern for Mikro-ORM
Go to file
cupcakearmy 5a0c42e1f0
prettier
2020-09-14 15:21:19 +02:00
src prettier 2020-09-14 15:21:19 +02:00
.gitignore initial code 2020-08-28 22:09:55 +02:00
.npmignore ignore files 2020-08-30 13:18:14 +02:00
.prettierrc prettier 2020-09-14 15:21:19 +02:00
LICENSE Initial commit 2020-08-28 18:18:52 +02:00
README.md Update README.md 2020-09-07 17:14:11 +02:00
package.json v1.0.6 2020-09-14 15:21:06 +02:00
tsconfig.json ignore files 2020-08-30 13:18:14 +02:00

README.md

mikro-orm-arp

Active Record(-ish) 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

yarn add mikro-orm-arp
npm install mikro-orm-arp

🚀 Usage

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()
})