packages/pglite/README.md
MikroORM driver for PGlite — a WASM build of PostgreSQL that runs in Node.js, the browser, Bun and Deno without a separate database server.
npm install @mikro-orm/core @mikro-orm/pglite
import { defineEntity, p, MikroORM } from '@mikro-orm/pglite';
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);
// In-memory (default)
const orm = await MikroORM.init({
entities: [Author, Book],
});
// Persisted to a Node.js directory
const orm = await MikroORM.init({
entities: [Author, Book],
dbName: './my-db',
});
// Browser, persisted in IndexedDB
const orm = await MikroORM.init({
entities: [Author, Book],
dbName: 'idb://my-db',
});
const author = orm.em.create(Author, { name: 'Jon Snow' });
orm.em.create(Book, { title: 'My Life on The Wall', author });
await orm.em.flush();
@mikro-orm/postgresql SQL/schema/migrations stack via @mikro-orm/sql@mikro-orm/postgresql if you need cursor-based streaming.See the official MikroORM documentation and the PGlite usage guide.
Copyright © 2018-present Martin Adámek. Licensed under the MIT License.