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

knex-transactional

v0.0.3

Published

Knex Transactional Decorator

Readme

Transaction Management with Node.js

Knex ORM with Transactional decorator

knex-transactional

A TypeScript decorator-based transaction management library for Knex.js that simplifies database transactions using the decorator pattern and AsyncLocalStorage.

Features

  • 🎯 Simple decorator-based transaction management
  • 🔄 Automatic transaction handling (commit/rollback)
  • 🔒 Transaction isolation level support
  • 🎭 Proxy-based query interception
  • 📦 Zero external dependencies (except Knex.js)
  • 💪 TypeScript support out of the box
  • Support for readonly transactions (requires Knex.js >= 2.5.0)

Installation

npm install knex-transactional

Options

  • isolationLevel: Transaction isolation level ('read uncommitted' | 'read committed' | 'repeatable read' | 'serializable')
  • readOnly
  • Other Knex.TransactionConfig options

Usage

const knex = require("knex")({
  client: "mysql",
  connection: {
    host: "127.0.0.1",
    port: 3306,
    user: "your_database_user",
    password: "your_database_password",
    database: "myapp_test",
  },
});

const db = initializeTransactions(knex);

export default db;

Performance Test Results

Test Environment

  • Testing Tool: Artillery
  • Load Configuration:
    • Warm-up: 10 requests per second for 5 seconds
    • Peak Load: 100 requests per second for 120 seconds

API Response Time Comparison

Decorator Approach (/decorator)

@Transactional()
async insertUserWithTransaction(userId: number) {
    const result = await db("user")
    .insert({
        userId
    })
    .returning("*");

    await db("user")
      .update({
        userId
      })
      .where("id", result[0].id);
}

| Metric | Response Time (ms) | | ------- | ------------------ | | Minimum | 2ms | | Median | 6ms | | Mean | 11.6ms | | p90 | 18ms | | p95 | 40.9ms | | p99 | 98.5ms | | Maximum | 355ms |

Manual Transaction Approach (/manual)

async insertUserManually(userId: number) {
    const trx = await db.transaction();
    try {
        const result = await trx("user")
            .insert({
                userId
            })
            .returning("*");

        await trx("user")
            .update({
                userId
            })
            .where("id", result[0].id);

        await trx.commit();
    } catch (error) {
        await trx.rollback();
        throw error;
    }
}

| Metric | Response Time (ms) | | ------- | ------------------ | | Minimum | 2ms | | Median | 7ms | | Mean | 11.8ms | | p90 | 18ms | | p95 | 40ms | | p99 | 115.6ms | | Maximum | 356ms |

Key Findings

  1. General Performance: Both approaches show similar performance in normal conditions (p50-p90), with differences of less than 1ms.
  2. High Load Stability: The decorator approach shows slightly better stability under high load (p95-p99).
  3. Production Readiness: Both methods demonstrate stable performance suitable for production environments.

Test Statistics

  • Total Requests: 12,050
  • Success Rate: 100% (No Errors)
  • Average RPS: 100
  • Average Session Duration: 18.2ms

Note: p95 indicates the response time for the 95th percentile of requests, meaning 95% of requests were processed within this time.

Detailed Comparison

| Metric | Decorator | Manual | Difference | | ------- | --------- | ------- | ---------- | | Minimum | 2ms | 2ms | 0ms | | Median | 6ms | 7ms | -1ms | | p90 | 18ms | 18ms | 0ms | | p95 | 40.9ms | 40ms | +0.9ms | | p99 | 98.5ms | 115.6ms | -17.1ms |