mikro-orm-arp/README.md

44 lines
844 B
Markdown
Raw Normal View History

2020-08-30 12:48:26 +00:00
# mikro-orm-arp
2020-09-07 15:13:36 +00:00
Active Record(-ish) Pattern for Mikro-ORM.
2020-08-30 12:48:26 +00:00
Ads the own repository functions to the class as static functions so you don't have to always retrieve them.
## 🏗 Installation
```bash
2020-09-07 15:14:11 +00:00
yarn add mikro-orm-arp
2020-08-30 12:48:26 +00:00
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()
})
```