packages/sql/README.md
Shared SQL driver base for MikroORM, built on top of Kysely. Provides the QueryBuilder, SQL connection management, and schema generation used by all SQL driver packages.
This package is automatically installed as a dependency of SQL driver packages (@mikro-orm/postgresql, @mikro-orm/mysql, etc.). You typically don't need to install it directly.
npm install @mikro-orm/core @mikro-orm/postgresql # installs @mikro-orm/sql automatically
import { MikroORM } from '@mikro-orm/postgresql';
const orm = await MikroORM.init({ ... });
const em = orm.em;
// Type-safe query builder
const qb = em.createQueryBuilder(Author);
const authors = await qb
.select('*')
.where({ books: { title: { $like: '%ORM%' } } })
.orderBy({ name: 'asc' })
.limit(10)
.getResult();
Access the type-safe Kysely query builder directly for advanced queries:
const result = await em
.getKysely()
.selectFrom('author')
.innerJoin('book', 'book.author_id', 'author.id')
.select(['author.name', 'book.title'])
.execute();
raw() and sql tagged template helpersSee the official MikroORM documentation and the Kysely integration guide.
Copyright © 2018-present Martin Adámek. Licensed under the MIT License.