mirror of
https://github.com/cupcakearmy/mikro-orm-arp.git
synced 2024-12-22 08:06:27 +00:00
Create README.md
This commit is contained in:
parent
067ccf1d12
commit
061d1b2bc4
42
README.md
Normal file
42
README.md
Normal file
@ -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()
|
||||||
|
})
|
||||||
|
```
|
Loading…
Reference in New Issue
Block a user