Skip to content

Instantly share code, notes, and snippets.

@B4nan
Last active February 6, 2022 12:11
Show Gist options
  • Save B4nan/4ee91759ffc175920ab16499401562f4 to your computer and use it in GitHub Desktop.
Save B4nan/4ee91759ffc175920ab16499401562f4 to your computer and use it in GitHub Desktop.
import { expr } from '@mikro-orm/core';
const res1 = await em.find(Book, {
// the type argument is optional, use it to get autocomplete on the entity properties
[expr<Book>(['price', 'createdAt'])]: { $lte: [100, new Date()] },
});
// will issue query similar to this:
// select `b0`.* from `book` as `b0` where (`b0`.`price`, `b0`.`created_at`) <= (?, ?)
const res2 = await em.find(Book, {
// the type argument is optional, use it to get autocomplete on the entity properties
[expr(as => `lower(${as}.name)`)]: 'jon',
});
// will issue query similar to this:
// select `b0`.* from `book` as `b0` where lower(b0.name) = ?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment