Skip to content

Instantly share code, notes, and snippets.

@B4nan
Last active April 30, 2019 16:24
Show Gist options
  • Save B4nan/8f49351879f70d4413d58863ef62cbf0 to your computer and use it in GitHub Desktop.
Save B4nan/8f49351879f70d4413d58863ef62cbf0 to your computer and use it in GitHub Desktop.
Using entity repository in MikroORM
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