Last active
April 30, 2019 16:24
-
-
Save B4nan/8f49351879f70d4413d58863ef62cbf0 to your computer and use it in GitHub Desktop.
Using entity repository in MikroORM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { QueryOrder } from 'mikro-orm'; | |
const booksRepository = orm.em.getRepository(Book); | |
// with sorting, limit and offset parameters, populating author references | |
const books = await booksRepository.find({ author: '...' }, ['author'], { title: QueryOrder.DESC }, 2, 1); | |
// or with options object | |
const books = await booksRepository.find({ author: '...' }, { | |
populate: ['author'], | |
limit: 1, | |
offset: 2, | |
sort: { title: QueryOrder.DESC }, | |
}); | |
console.log(books); // Book[] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment