packages/mssql/README.md
MikroORM driver for Microsoft SQL Server databases, built on top of tedious.
npm install @mikro-orm/core @mikro-orm/mssql
import { defineEntity, p, MikroORM } from '@mikro-orm/mssql';
const AuthorSchema = defineEntity({
name: 'Author',
properties: {
id: p.integer().primary(),
name: p.string(),
books: () => p.oneToMany(Book).mappedBy('author'),
},
});
export class Author extends AuthorSchema.class {}
AuthorSchema.setClass(Author);
const BookSchema = defineEntity({
name: 'Book',
properties: {
id: p.integer().primary(),
title: p.string(),
author: () => p.manyToOne(Author).inversedBy('books'),
},
});
export class Book extends BookSchema.class {}
BookSchema.setClass(Book);
const orm = await MikroORM.init({
entities: [Author, Book],
dbName: 'my-db',
host: 'localhost',
port: 1433,
});
const author = orm.em.create(Author, { name: 'Jon Snow' });
orm.em.create(Book, { title: 'My Life on The Wall', author });
await orm.em.flush();
const authors = await orm.em.find(
Author,
{ name: { $like: '%Jon%' } },
{
populate: ['books'],
},
);
tediousSee the official MikroORM documentation and the SQL usage guide.
Copyright © 2018-present Martin Adámek. Licensed under the MIT License.