aurora-orm
v0.2.58
Published
Near-zero runtime ORM and migration tool for PostgreSQL with TypeScript and Node.js
Downloads
643
Readme
Aurora-ORM
Near-zero runtime ORM for Node.js and TypeScript
Aurora ORM support PostgreSQL.
The library is made to solve the author personal problems, and is not intended to be a truly open source
Aurora ORM is an ORM that can run in NodeJS and can be used with TypeScript and JavaScript environment. Its goal is to always use only native JavaScript features and provide additional features like Data migration tool that help you to develop applications that uses databases.
Aurora ORM supports only Data Mapper pattern. And don't use unstable features like decorators and reflect-metadata that give you the ability to use modern JavaScript/TypeScript transpilers like SWC or ESbuild to speed up development.
Benchmarks
These are the results from running the benchmarks on a Macbook Pro 2,4 GHz Intel Core i9 with Postgres 16.3 installation and Node 22.3.0.
You can run this benchmark yourself: pnpm benchmark
higher is better
Features
- Models and type safe columns mapping
- Database-specific column types
- Transactions
- Relations
- Indexes
- Logging
- Migrations
- Connection pooling
- TypeScript and JavaScript support
- Support functional programming composition pattern
- Produced code is performant, flexible, clean and maintainable
- Support modern transpilers like SWC or ESbuild
Installation
- Install the npm package:
pnpm add aurora-orm
- Install a database driver:
pnpm add [pg|postgres]
Quick Start
Connect to database
import {connect, Drivers} from 'aurora-orm'
await connect({
config: {
// optional, default value 'Drivers.PG'
driver: Drivers.PG,
connectionString: 'postgres://test:test@localhost:5432/test',
// or
host: 'localhost',
port: 5432,
username: 'test',
password: 'test',
database: 'test',
},
})
Run migrations
Create migrator script:
import {runMigrationsAndExit, Drivers} from 'aurora-orm'
// Some code to load connectionString
const connectionString = 'postgres://test:test@localhost:5432/test'
const direction = process.argv[2] as 'down' | 'up'
await runMigrationsAndExit({
config: {driver: Drivers.PG, connectionString},
direction,
})
And add to package.json
scripts:
{
"scripts": {
"migrator:down": "tsx ./src/migrator.ts down",
"migrator:up": "tsx ./src/migrator.ts up",
"migrator:create": "aurora-orm create"
},
}
Define model
import {createModel} from 'aurora-orm'
export interface User {
id: number
name: string
age: number | null
password: string
addictions: number[]
}
export const UserModel = createModel<User>({
table: 'users',
mapping: {
// Type Safe columns mapping
id: 'id',
name: 'name',
age: 'age',
password: {
name: 'password',
hidden: true,
},
addictions: 'addictions',
},
})
And your domain logic looks like this:
const user = await UserModel.create({
name: 'John',
age: 26,
password: 'iLoveCats',
addictions: [4],
})
const allUsers = await UserModel.findAll()
const firstUser = await UserModel.findOne(1) // find by id
const john = await UserModel.findOne({
name: 'John',
age: 26,
}) // find by name and age
await UserModel.delete(john)