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

@hazeljs/typeorm

v1.0.6

Published

TypeORM integration for HazelJS framework

Readme

@hazeljs/typeorm

TypeORM + HazelJS. Repository pattern, DI, lifecycle.

DataSource as an injectable service, BaseRepository and @Repository / @InjectRepository decorators. Full CRUD and transactions via TypeORM.

npm version npm downloads License: Apache-2.0

Features

  • DataSource integration – TypeORM DataSource as injectable TypeOrmService
  • Repository patternBaseRepository<T> with find / findOne / create / save / update / delete / count
  • Decorators@Repository({ model: 'User' }) and @InjectRepository() for DI
  • Lifecycle – connect in onModuleInit, disconnect in onModuleDestroy
  • forRoot – optional TypeOrmModule.forRoot(options) for custom DataSource options

Installation

npm install @hazeljs/typeorm typeorm

Quick Start

1. Set DATABASE_URL

# .env
DATABASE_URL="postgresql://user:pass@localhost:5432/mydb"

2. Register the module

import { HazelModule } from '@hazeljs/core';
import { TypeOrmModule } from '@hazeljs/typeorm';

@HazelModule({
  imports: [TypeOrmModule],
})
export class AppModule {}

With custom options:

import { TypeOrmModule } from '@hazeljs/typeorm';

@HazelModule({
  imports: [
    TypeOrmModule.forRoot({
      type: 'postgres',
      host: 'localhost',
      port: 5432,
      username: 'user',
      password: 'pass',
      database: 'mydb',
      entities: [__dirname + '/**/*.entity{.ts,.js}'],
      synchronize: false,
    }),
  ],
})
export class AppModule {}

3. Define an entity

import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm';

@Entity('users')
export class UserEntity {
  @PrimaryGeneratedColumn('uuid')
  id!: string;

  @Column({ unique: true })
  email!: string;

  @Column()
  name!: string;
}

4. Create a repository

@Repository implies @Injectable() — no need to add both decorators.

import { BaseRepository, Repository, TypeOrmService } from '@hazeljs/typeorm';
import { UserEntity } from './user.entity';

@Repository({ model: 'User' })
export class UserRepository extends BaseRepository<UserEntity> {
  constructor(typeOrm: TypeOrmService) {
    super(typeOrm, UserEntity);
  }

  async findByEmail(email: string): Promise<UserEntity | null> {
    return this.findOne({ where: { email } });
  }
}

5. Use in a service

Use @Service for service classes — it is the correct decorator for business-logic classes in HazelJS (not @Injectable).

import { Service } from '@hazeljs/core';
import { InjectRepository } from '@hazeljs/typeorm';
import { UserRepository } from './user.repository';

@Service()
export class UserService {
  constructor(
    @InjectRepository()
    private readonly userRepository: UserRepository
  ) {}

  async findAll() {
    return this.userRepository.find();
  }

  async create(data: { email: string; name: string }) {
    return this.userRepository.create(data);
  }
}

Transactions

Use TypeOrmService.dataSource for transactions:

import { Service } from '@hazeljs/core';
import { TypeOrmService } from '@hazeljs/typeorm';

@Service()
export class TransferService {
  constructor(private readonly typeOrm: TypeOrmService) {}

  async transfer(fromId: string, toId: string, amount: number) {
    await this.typeOrm.dataSource.transaction(async (manager) => {
      await manager.decrement(Account, { id: fromId }, 'balance', amount);
      await manager.increment(Account, { id: toId }, 'balance', amount);
    });
  }
}

Links

License

Apache 2.0 © HazelJS