@forgeframework/orm
v0.3.0
Published
A type-safe ORM for the Forge Framework.
Maintainers
Readme
@forgeframework/orm
A type-safe ORM for the Forge Framework.
Part of the Forge Framework — a TypeScript framework for backend microservices and web applications.
Installation
npm install @forgeframework/ormUsage
import { DatabaseConnection, EntityManager, Entity, Column, PrimaryKey, HasMany } from '@forgeframework/orm';
const db = new DatabaseConnection({
type: 'postgres',
host: 'localhost',
port: 5432,
database: 'myapp',
username: 'admin',
password: config.get('db.password'),
pool: { min: 2, max: 10 },
});
await db.connect();
const em = new EntityManager(db);
const users = await em.find(User)
.where('isActive', '=', true)
.include('posts', 'profile')
.orderBy('createdAt', 'desc')
.paginate(1, 20);
const user = await em.create(User, {
email: '[email protected]',
name: 'John Doe',
});
await em.transaction(async (trx) => {
const order = await trx.create(Order, orderData);
await trx.update(Product, productId, { stock: raw('stock - 1') });
});Documentation
Full API reference and guides: https://carbonforge.io/framework/docs/db/orm
(Documentation site launching soon.)
License
MIT © Carbon Forge
