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

@asenajs/asena-drizzle

v1.1.2

Published

Type-safe database integration for AsenaJS with Drizzle ORM - Repository pattern, decorators, and multi-database support

Readme

@asenajs/asena-drizzle

Drizzle ORM utilities for AsenaJS - A powerful and type-safe database integration package that provides generic Database services and Repository patterns.

Features

  • 🚀 Generic Database Service - Support for multiple database types (PostgreSQL, MySQL, BunSQLite)
  • 🎯 Type-Safe Repository Pattern - Full TypeScript support with inferred types
  • 🏷️ Decorator-Based Configuration - Easy setup with @Database and @Repository decorators
  • 🔧 AsenaJS Integration - Seamless IoC container integration
  • 📦 Multiple Database Support - Connect to different databases simultaneously
  • Performance Optimized - Connection pooling and efficient query execution

Installation

bun add @asenajs/asena-drizzle drizzle-orm
# For PostgreSQL
bun add pg
# For MySQL
bun add mysql2

Quick Start

1. Database Service Setup

import { Database } from '@asenajs/asena-drizzle';

@Database({
  type: 'postgresql',
  config: {
    host: 'localhost',
    port: 5432,
    database: 'myapp',
    user: 'postgres',
    password: 'password',
  },
  name: 'MainDatabase' // Optional: for multiple databases but we recommend using it
})
export class MyDatabase extends AsenaDatabaseService {}

2. Repository Setup

import { BaseRepository, Repository } from '@asenajs/asena-drizzle';
import { pgTable, uuid, text } from 'drizzle-orm/pg-core';

const users = pgTable('users', {
  id: uuid('id').primaryKey().defaultRandom(),
  name: text('name').notNull(),
  email: text('email').notNull().unique(),
});

@Repository({
  table: users,
  databaseService: 'MainDatabase',
})
export class UserRepository extends BaseRepository<typeof users> {
  
  async findByEmail(email: string) {
    return this.findOne(eq(users.email, email));
  }
}

3. Service Usage

import { Service } from '@asenajs/asena/decorators';
import { Inject } from '@asenajs/asena/decorators/ioc';

@Service("UserService")
export class UserService {
  
  @Inject("UserRepository")
  private userRepository: UserRepository;

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

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

  async getUsersPaginated(page = 1, limit = 10) {
    return this.userRepository.paginate(page, limit);
  }
}

Supported Database Types

  • postgresql - PostgreSQL using pg (node-postgres) with connection pooling
  • mysql - MySQL using mysql2
  • bun-sql - BunSQL using Bun's SQL interface
  • sqlite - SQLite (coming soon)

Repository Methods

The BaseRepository provides the following built-in methods:

  • findById(id) - Find record by ID
  • findAll(where?) - Find all records with optional conditions
  • findOne(where) - Find single record
  • create(data) - Create new record
  • createMany(data[]) - Create multiple records
  • updateById(id, data) - Update record by ID
  • update(where, data) - Update records with conditions
  • deleteById(id) - Delete record by ID
  • delete(where) - Delete records with conditions
  • count() - Count all records
  • countBy(where) - Count records with conditions
  • paginate(page, limit, where?, orderBy?) - Paginated results
  • exists(where) - Check if record exists

Advanced Usage

Multiple Database Connections

@Database({
  type: 'postgresql',
  config: { /* primary db config */ },
  name: 'PrimaryDB'
})
export class PrimaryDatabase extends AsenaDatabaseService {}

@Database({
  type: 'mysql',
  config: { /* analytics db config */ },
  name: 'AnalyticsDB'
})
export class AnalyticsDatabase extends AsenaDatabaseService {}

@Repository({
  table: users,
  databaseService: 'PrimaryDB',
})
export class UserRepository extends BaseRepository<typeof users> {}

@Repository({
  table: events,
  databaseService: 'AnalyticsDB',
})
export class EventRepository extends BaseRepository<typeof events> {}

Connection String Usage

@Database({
  type: 'postgresql',
  config: {
    connectionString: process.env.DATABASE_URL,
    host: '', port: 0, database: '', user: '', password: ''
  }
})
export class DatabaseFromURL extends AsenaDatabaseService {}

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.