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

guruorm

v2.0.0

Published

A powerful, elegant Node.js ORM inspired by Laravel and Illuminate

Readme

guruORM

A powerful, elegant Node.js ORM inspired by Laravel and Illuminate

npm version License: MIT TypeScript JavaScript

🎯 Features

  • 🚀 Fluent Query Builder - Elegant and expressive query building
  • 🔥 Eloquent ORM - Active Record implementation for Node.js
  • 🗃️ Multiple Databases - MySQL, PostgreSQL, SQLite, SQL Server support
  • 🔄 Migrations - Version control for your database schema
  • 🌱 Seeding - Populate your database with test data
  • 🔗 Relationships - Full relationship support (One-to-One, One-to-Many, Many-to-Many, Polymorphic)
  • 📦 JavaScript & TypeScript - Works with both! Full type safety optional
  • 🛠️ CLI Tools - Powerful command-line interface
  • Zero Config - Works out of the box with JavaScript projects

👉 Complete Features List - See what's working and what's planned
👉 Complete Database Drivers Guide - MySQL, PostgreSQL, SQLite, SQL Server examples

🙏 Acknowledgment

Inspired by Laravel and Illuminate Database.

📦 Installation

npm install guruorm

🚀 Quick Start

Works with Both JavaScript & TypeScript!

TypeScript:

import { Capsule } from 'guruorm';

const capsule = new Capsule();

capsule.addConnection({
  driver: 'mysql',
  host: 'localhost',
  port: 3306,
  database: 'mydb',
  username: 'root',
  password: 'password',
});

capsule.setAsGlobal();
capsule.bootEloquent();

JavaScript (CommonJS):

const { Capsule } = require('guruorm');

const capsule = new Capsule();

capsule.addConnection({
  driver: 'mysql',
  host: 'localhost',
  database: 'mydb',
  username: 'root',
  password: 'password',
});

capsule.setAsGlobal();
capsule.bootEloquent();

Your First Query

JavaScript:

const { DB, Schema } = require('guruorm');

// Create schema
await Schema.create('users', (table) => {
  table.id();
  table.string('name');
  table.string('email').unique();
  table.boolean('active').defaultTo(true);
  table.timestamps();
});

// Raw SQL queries
const users = await DB.select('SELECT * FROM users WHERE active = ?', [true]);

// Query builder
const activeUsers = await DB.table('users')
  .where('active', true)
  .orderBy('name')
  .get();

// Insert data
await DB.insert('INSERT INTO users (name, email) VALUES (?, ?)', [
  'John Doe',
  '[email protected]'
]);

// Or using query builder
await DB.table('users').insert({
  name: 'Jane Smith',
  email: '[email protected]'
});

Your First Model

JavaScript:

const { Model } = require('guruorm');

class User extends Model {
  constructor() {
    super();
    this.table = 'users';
    this.fillable = ['name', 'email', 'password'];
  }
  
  // Define relationship
  posts() {
    return this.hasMany(Post);
  }
}

// Use it
const user = await User.create({
  name: 'John Doe',
  email: '[email protected]'
});

const users = await User.where('active', true).get();

TypeScript:

import { Model } from 'guruorm';

class User extends Model {
  protected table = 'users';
  protected fillable = ['name', 'email', 'password'];
  
  // Define relationship
  posts() {
    return this.hasMany(Post);
  }
}

// Use it
const user = await User.find(1);
const users = await User.where('active', true).get();
const newUser = await User.create({ 
  name: 'John Doe', 
  email: '[email protected]' 
});

👉 See Complete Getting Started Guide


📖 Documentation

GuruORM provides comprehensive, easy-to-follow documentation.

Core Concepts

  • Getting Started - Installation, setup, and basic configuration
  • Query Builder - Build complex database queries with a fluent, expressive API
  • Eloquent ORM - Work with your database using elegant Active Record models
  • Relationships - Define and query model relationships (One-to-One, One-to-Many, Many-to-Many)
  • Migrations - Version control for your database schema
  • Seeding - Populate your database with test data

Additional Topics

  • Collections - Work with collections of data
  • Events & Observers - Hook into model lifecycle events
  • Mutators & Casting - Transform model attributes
  • Advanced Queries - Subqueries, unions, and raw expressions
  • Testing - Test your database interactions

💡 Examples

Query Builder Examples

// Basic where clauses
const users = await DB.table('users')
  .where('votes', '>', 100)
  .orWhere('name', 'John')
  .get();

// Joins
const users = await DB.table('users')
  .join('contacts', 'users.id', '=', 'contacts.user_id')
  .select('users.*', 'contacts.phone')
  .get();

// Aggregates
const count = await DB.table('users').count();
const max = await DB.table('users').max('votes');

// Chunking results for large datasets
await DB.table('users').chunk(100, async (users) => {
  for (const user of users) {
    // Process user
  }
});

Eloquent Model Examples

// Define models
class User extends Model {
  protected fillable = ['name', 'email'];
  
  posts() {
    return this.hasMany(Post);
  }
  
  roles() {
    return this.belongsToMany(Role);
  }
}

// Basic CRUD
const user = await User.create({ name: 'John', email: '[email protected]' });
const user = await User.find(1);
await user.update({ name: 'Jane' });
await user.delete();

// Query scopes
const popularUsers = await User.where('votes', '>', 100)
  .orderBy('name')
  .get();

// Eager loading relationships
const users = await User.with(['posts', 'roles']).get();

// Constrained lazy eager loading (v1.12.0)
await user.load({
  posts: query => query.where('published', true).orderBy('created_at', 'desc')
});

// Querying relationships
const userPosts = await user.posts()
  .where('published', true)
  .orderBy('created_at', 'desc')
  .get();

// Touch timestamps (v1.11.0)
await user.touch(); // Update updated_at
await comment.touchOwners(); // Update parent timestamps

// Model observers (v1.10.0)
User.observe({
  creating: (user) => console.log('Creating user...'),
  created: (user) => console.log('User created!'),
  updating: (user) => console.log('Updating user...'),
  updated: (user) => console.log('User updated!')
});

Migration Examples

// Create table
await Schema.create('flights', (table) => {
  table.id();
  table.string('name');
  table.string('airline');
  table.timestamps();
});

// Modify table
await Schema.table('users', (table) => {
  table.string('avatar').nullable();
  table.index('email');
});

// Foreign keys
await Schema.create('posts', (table) => {
  table.id();
  table.foreignId('user_id').constrained().onDelete('cascade');
  table.string('title');
  table.text('body');
  table.timestamps();
});

🔧 CLI Commands

GuruORM provides a powerful command-line interface:

Available Commands

| Command | Description | |---------|-------------| | npx guruorm migrate | Run migrations | | npx guruorm migrate:rollback | Rollback migrations | | npx guruorm migrate:fresh | Drop all & re-migrate | | npx guruorm migrate:refresh | Reset & re-migrate | | npx guruorm migrate:status | Show migration status | | npx guruorm make:migration | Create migration | | npx guruorm db:seed | Run seeders | | npx guruorm make:seeder | Create seeder | | npx guruorm make:factory | Create factory | | npx guruorm model:prune | Prune models |

Examples

# Create a migration
npx guruorm make:migration create_users_table --create=users
npx guruorm make:migration add_status_to_users --table=users

# Run migrations
npx guruorm migrate
npx guruorm migrate --force  # Production
npx guruorm migrate --step=1  # Run one migration

# Rollback
npx guruorm migrate:rollback
npx guruorm migrate:rollback --step=2

# Fresh migration with seeding
npx guruorm migrate:fresh --seed

# Create seeder
npx guruorm make:seeder UserSeeder
npx guruorm make:seeder DatabaseSeeder

# Run seeder
npx guruorm db:seed
npx guruorm db:seed --class=UserSeeder
npx guruorm db:seed --force  # Production

# Create factory
npx guruorm make:factory UserFactory --model=User
npx guruorm make:factory PostFactory

# Prune models
npx guruorm model:prune
npx guruorm model:prune --model=OldLog

CLI Features

Powerful Commands - Intuitive syntax ✅ Flags Support - --force, --step, --class, etc. ✅ Auto-complete Ready - Tab completion support ✅ Helpful Output - Clear success/error messages ✅ File Generators - Create migrations, seeders, factories ✅ Production Guards - Prevents accidental production runs


🌟 Why guruORM?

  • Elegant API - Clean, expressive syntax
  • JavaScript & TypeScript - Works with both! No TypeScript required
  • Type Safety - Optional TypeScript support with intelligent autocompletion
  • Battle-Tested Patterns - Proven architecture
  • Production Ready - Comprehensive testing and error handling
  • Great DX - Clear error messages, helpful documentation, powerful CLI
  • Zero Config - Install and start coding immediately

Works with Plain JavaScript!

No TypeScript? No Problem!

// Pure JavaScript - No compilation needed
const { Model, DB } = require('guruorm');

class User extends Model {
  constructor() {
    super();
    this.table = 'users';
    this.fillable = ['name', 'email'];
  }
}

// Works perfectly!
const users = await User.where('active', true).get();
const john = await User.find(1);

Feature Coverage

| Component | Completion | Status | |-----------|-----------|---------| | Query Builder | 98% | ⭐⭐⭐⭐⭐ | | Eloquent ORM | 97% | ⭐⭐⭐⭐⭐ | | Relationships | 97% | ⭐⭐⭐⭐⭐ | | Schema Builder | 90% | ⭐⭐⭐⭐ | | Migrations | 90% | ⭐⭐⭐⭐ | | Seeding | 95% | ⭐⭐⭐⭐⭐ | | Events & Observers | 95% | ⭐⭐⭐⭐⭐ | | Testing Utilities | 70% | ⭐⭐⭐ | | Overall | ~94% | ⭐⭐⭐⭐⭐ |


⚡ Performance

Faster Than Sequelize in Key Areas

GuruORM uses Active Record pattern, which is lighter and more efficient than Sequelize's Data Mapper pattern.

Memory Efficiency:

// Process 100k records

// Other ORMs - Load all into memory
const users = await OtherORM.findAll({ limit: 100000 }); // 💥 ~450MB

// GuruORM - Stream with chunking
await User.chunk(1000, (users) => {
  // Process 1000 at a time
}); // ⚡ ~15MB

Cursor Pagination (Constant Speed):

// Offset pagination gets slower with pages
// Page 1: fast, Page 1000: SLOW

// GuruORM cursor pagination - always fast!
const { data, nextCursor } = await User.cursorPaginate(100);
// Same speed on page 1 or page 10,000! 🚀

Lazy Loading (Stream Processing):

// Memory-efficient streaming
for await (const user of User.lazy()) {
  // Process one at a time, minimal memory
}

Run the benchmark:

node examples/performance-benchmark.js

📊 View Complete Performance Comparison - Detailed benchmarks vs Sequelize, TypeORM, Prisma, Knex, Objection, MikroORM, Bookshelf


🤝 Contributing

We welcome contributions! Please see CONTRIBUTING.md for details.

⚠️ Important: All contributions must follow our Coding Standards. This ensures consistency and professional quality throughout the codebase.

📚 Documentation

📝 License

guruORM is open-sourced software licensed under the MIT license.

🔗 Links

💖 Special Thanks

Inspired by Laravel and Illuminate.


Made with ❤️ by the guruORM team