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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@stackra/ts-eloquent

v1.2.1

Published

Laravel Eloquent-style TypeScript ORM built on RxDB — reactive, offline-first, with Supabase replication

Readme




@stackra/ts-eloquent

Laravel Eloquent-style ORM built on RxDB for client-side TypeScript applications.

Installation

pnpm add @stackra/ts-eloquent

Features

  • 🏗️ EloquentModule.forRoot() / forFeature() with DI integration
  • 📦 Model base class with Eloquent-style API (find, create, update, delete)
  • 🔍 QueryBuilder with where, orderBy, limit, fluent chaining
  • 🗂️ Schema layer: Blueprint, SchemaBuilder, SchemaResolver
  • 🔗 Relations: @HasOne, @HasMany, @BelongsTo, @BelongsToMany
  • 🎭 Decorators: @Collection, @Column, @PrimaryKey, @Fillable, @Guarded, @Hidden, @Cast, @Index, @Timestamps, @SoftDeletes
  • 🔄 Lifecycle hooks: @BeforeCreate, @AfterCreate, @BeforeUpdate, @AfterUpdate, @BeforeDelete, @AfterDelete
  • 👁️ Observer pattern with @ObservedBy decorator
  • 🌱 Factory for test data generation
  • 🌾 Seeder for database seeding
  • 📋 Repository and Service patterns
  • 🔀 Migration and MigrationRunner with auto-migrate support
  • 🔌 ConnectionManager for multiple named database connections
  • 📡 Supabase replication helpers
  • ⚛️ React hook: useFind(Model, id, { live }) with reactive updates
  • 🏷️ DI tokens: ELOQUENT_CONFIG, CONNECTION_MANAGER, MODEL_REGISTRY, SCHEMA_RESOLVER, MIGRATION_RUNNER, SEEDER_RUNNER

Usage

Module Registration

/**
 * |-------------------------------------------------------------------
 * | Register EloquentModule in your root AppModule.
 * |-------------------------------------------------------------------
 */
import { Module } from '@stackra/ts-container';
import { EloquentModule } from '@stackra/ts-eloquent';

@Module({
  imports: [
    EloquentModule.forRoot({
      default: 'local',
      connections: {
        local: { driver: 'memory', name: 'app' },
      },
      autoMigrate: true,
    }),
  ],
})
export class AppModule {}

Feature Module

/**
 * |-------------------------------------------------------------------
 * | Register models, migrations, seeders, and observers per feature.
 * |-------------------------------------------------------------------
 */
@Module({
  imports: [
    EloquentModule.forFeature({
      models: [User, Post],
      migrations: [CreateUsersTable],
      seeders: [UserSeeder],
      observers: [{ model: User, observer: UserObserver }],
    }),
  ],
})
export class UserModule {}

Defining a Model

/**
 * |-------------------------------------------------------------------
 * | Use decorators to define schema, relations, and behavior.
 * |-------------------------------------------------------------------
 */
import {
  Model,
  Collection,
  Column,
  PrimaryKey,
  Fillable,
  HasMany,
  Timestamps,
} from '@stackra/ts-eloquent';

@Collection('users')
@Timestamps()
export class User extends Model {
  @PrimaryKey()
  @Column({ type: 'string' })
  id!: string;

  @Fillable()
  @Column({ type: 'string' })
  name!: string;

  @HasMany(() => Post, 'userId')
  posts!: Post[];
}

Querying

/**
 * |-------------------------------------------------------------------
 * | Eloquent-style query builder with fluent chaining.
 * |-------------------------------------------------------------------
 */
const user = await User.find('123');
const admins = await User.query()
  .where('role', '=', 'admin')
  .orderBy('name')
  .get();
const first = await User.query()
  .where('email', '=', '[email protected]')
  .first();

React Hook

/**
 * |-------------------------------------------------------------------
 * | useFind with live mode subscribes to document changes.
 * |-------------------------------------------------------------------
 */
import { useFind } from '@stackra/ts-eloquent';

function UserProfile({ userId }: { userId: string }) {
  const { data: user, loading, error } = useFind(User, userId, { live: true });

  if (loading) return <p>Loading...</p>;
  if (!user) return <p>Not found</p>;
  return <p>{user.getAttribute('name')}</p>;
}

API Reference

| Export | Type | Description | | ----------------------------- | -------- | --------------------------------------------- | | EloquentModule | Module | DI module with forRoot() and forFeature() | | Model | Class | Base model with Eloquent-style API | | QueryBuilder | Class | Fluent query builder | | Blueprint / SchemaBuilder | Class | Schema definition | | ConnectionManager | Service | Multi-connection management | | ModelRegistry | Registry | Registered model tracking | | MigrationRegistry | Registry | Migration tracking with auto-migrate | | SeederRegistry | Registry | Seeder tracking | | ObserverRegistry | Registry | Observer binding tracking | | Repository | Class | Repository pattern base class | | Service | Class | Service pattern base class | | Factory | Class | Test data factory | | Migration | Class | Migration base class | | Seeder | Class | Seeder base class | | Observer | Class | Model observer base class | | useFind(model, id, opts?) | Hook | Find model by PK with optional live mode |

License

MIT