aurora-orm v0.2.15
Aurora-ORM
Decorator-less, type safe, fast and low overhead ORM for Node.js and TypeScript.
Aurora ORM works both for PostgreSQL and YugabyteDB.
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.
Features
- Support Data Mapper.
- Models and type safe columns mapping.
- Database-specific column types.
- Relations.
- Support functional programming composition pattern.
- Indexes.
- Transactions.
- Migrations.
- Connection pooling.
- Elegant-syntax.
- Logging.
- Connection configuration in json format.
- Supports Postgres / YugabyteDB.
- TypeScript and JavaScript support.
- Support modern transpilers like SWC or ESbuild.
- Produced code is performant, flexible, clean and maintainable.
With Aurora ORM your models look like this:
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)
Installation
- Install the npm package:
yarn add aurora-orm
- Install a database driver:
- for PostgreSQL
yarn add pg
Quick Start
Creating a new connection from the configuration file.
Most of the times you want to store your connection options in a separate configuration file. It makes it convenient and easy to manage. You only need to create a aurora-orm.json
file in the root directory of your application (near package.json), put your configuration there and in your app call connect() without any configuration passed:
{
"driver": "pg", // optinal, default value 'pg'
"host": "localhost",
"port": 5432,
"username": "test",
"password": "test",
"database": "test"
}
Or you can use connectionString
, and if value starts with env:[variable_name]
it will be automatically replaced with the value from the .env
file:
{
"connectionString": "postgres://test:test@localhost:5432/test",
// or if you need environment variable
"connectionString": "env:DATABASE_URL",
}
Connect to database
import { connect } from 'aurora-orm'
// createConnection method will automatically read connection options
// from your aurora-orm.json file
await connect()
Contributors
Before make pull request test library using symlink.
yarn build && (yarn unlink || true) && yarn link
And run Jest tests.
yarn test
10 months ago
9 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
9 months ago
9 months ago
8 months ago
8 months ago
8 months ago
8 months ago
9 months ago
9 months ago
9 months ago
9 months ago
11 months ago
11 months ago
11 months ago
11 months ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago