0.2.15 • Published 8 months ago

aurora-orm v0.2.15

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

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

  1. Install the npm package: yarn add aurora-orm
  2. 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
0.0.88

10 months ago

0.0.89

9 months ago

0.2.15

8 months ago

0.2.14

8 months ago

0.2.13

8 months ago

0.2.12

8 months ago

0.2.11

8 months ago

0.2.10

8 months ago

0.2.1

9 months ago

0.2.0

9 months ago

0.2.7

8 months ago

0.2.6

8 months ago

0.2.9

8 months ago

0.2.8

8 months ago

0.2.3

9 months ago

0.2.2

9 months ago

0.2.5

9 months ago

0.2.4

9 months ago

0.0.87

11 months ago

0.0.86

11 months ago

0.0.84

11 months ago

0.0.85

11 months ago

0.0.82

1 year ago

0.0.83

1 year ago

0.0.80

1 year ago

0.0.81

1 year ago

0.0.73

2 years ago

0.0.74

2 years ago

0.0.75

2 years ago

0.0.76

2 years ago

0.0.77

2 years ago

0.0.78

2 years ago

0.0.79

2 years ago

0.0.71

2 years ago

0.0.72

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.0.7

2 years ago

0.1.5

2 years ago

0.1.0

2 years ago