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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@igojs/db

v6.0.0-beta.3

Published

Igo ORM - Database abstraction layer for MySQL and PostgreSQL

Readme

@igojs/db

Database abstraction layer for MySQL and PostgreSQL with Active Record-style ORM.

Installation

npm install @igojs/db

Note: Database drivers are optional dependencies. Install the one you need:

npm install mysql2  # For MySQL
npm install pg      # For PostgreSQL

Features

  • Active Record ORM - Ruby on Rails-inspired Model API
  • Query Builder - Chainable query API with scopes
  • Associations - has_many, belongs_to relationships
  • Caching - Redis-based query result caching
  • Migrations - SQL file-based migrations
  • Optimized Queries - PaginatedOptimizedQuery for large tables

Quick Start

const { Model } = require('@igojs/db');

const schema = {
  table: 'users',
  columns: ['id', 'email', 'name', 'created_at']
};

class User extends Model(schema) {
  fullName() {
    return `${this.first_name} ${this.last_name}`;
  }
}

// CRUD operations
const user = await User.create({ email: '[email protected]', name: 'John' });
const users = await User.where({ name: 'John' }).list();
await user.update({ name: 'Jane' });
await user.delete();

API

Exports

| Export | Description | |--------|-------------| | Model | Base model class factory | | Query | Query builder class | | CachedQuery | Query with Redis caching | | Schema | Schema definition utilities | | Sql | SQL generation utilities | | Db | Database connection class | | dbs | Database connections manager | | migrations | Migration runner | | DataTypes | Column type definitions | | CacheStats | Cache statistics | | PaginatedOptimizedQuery | Optimized pagination for large tables |

Model Definition

const schema = {
  table: 'users',
  columns: [
    'id',
    'email',
    { name: 'is_active', type: 'boolean' },
    { name: 'settings_json', type: 'json', attr: 'settings' },
  ],
  associations: [
    ['has_many', 'posts', Post, 'id', 'user_id'],
    ['belongs_to', 'country', Country, 'country_id'],
  ],
  scopes: {
    default: (q) => q.order('created_at DESC'),
    active: (q) => q.where({ is_active: true }),
  },
  cache: true, // Enable Redis caching
};

Query API

// Find
const user = await User.find(1);

// Where
const users = await User.where({ status: 'active' }).list();
const users = await User.where('age > ?', [18]).list();

// Chainable
const users = await User
  .where({ status: 'active' })
  .includes('posts')
  .order('name ASC')
  .limit(10)
  .list();

// Scopes
const users = await User.scope('active').list();

// Pagination
const result = await User.page(1, 20);
// => { pagination: {...}, rows: [...] }

// Count
const count = await User.where({ status: 'active' }).count();

Optimized Pagination

For large tables with many joins (100K+ rows), use PaginatedOptimizedQuery:

const result = await User.paginatedOptimized()
  .where({
    status: 'active',
    'company.country.code': 'FR',  // Nested filter
  })
  .join(['company.country'])
  .order('created_at DESC')
  .page(1, 50)
  .execute();

Initialization

When used standalone (without @igojs/server), initialize with dependencies:

const db = require('@igojs/db');

db.init({
  config: { mysql: { host: 'localhost', database: 'myapp' } },
  cache: myRedisCache,
  logger: myLogger,
  utils: { toJSON, fromJSON },
  errorhandler: myErrorHandler,
});

Documentation

See the full documentation.