npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

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

results chart

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

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