Registry / web-framework / najm-database

najm-database

JSON →
library1.1.8jsnpmunverified

Community-maintained database plugin for the Najm API framework (v1.1.8). Provides decorator-based transaction management, automatic rollback, Drizzle ORM integration, and Zod schema validation. Requires najm-core, reflect-metadata, drizzle-orm >=0.36.0, and zod. Updated monthly. Differentiator: declarative @Transactional decorator with automatic commit/rollback tied to request lifecycle, reducing boilerplate for Najm-based APIs.

npm install najm-database
INSTALL
IMPORT
SIG · NAJM-DATABASE
N
najm-database
web-frameworkjavascriptv1.1.8
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

DatabasePlugin
import { DatabasePlugin } from 'najm-database'
const DatabasePlugin = require('najm-database').DatabasePlugin
ESM-only since v1.0.0. Named export.
Transactional
import { Transactional } from 'najm-database'
import Transactional from 'najm-database'
Named export, not default. Used as @Transactional decorator.
DatabaseConfig
import type { DatabaseConfig } from 'najm-database'
import { DatabaseConfig } from 'najm-database'
Type export. Should use `import type` in TypeScript to avoid runtime overhead.
default
import NajmDatabase from 'najm-database'
import { NajmDatabase } from 'najm-database'
Default export is the main plugin class. Named export NajmDatabase does not exist.

Shows how to initialize the DatabasePlugin with a Drizzle ORM instance and use the @Transactional decorator on a method to wrap it in a database transaction.

import { DatabasePlugin, Transactional } from 'najm-database'; import { drizzle } from 'drizzle-orm/node-postgres'; import { Pool } from 'pg'; const pool = new Pool({ connectionString: process.env.DB_URL ?? '' }); const db = drizzle(pool); // Register plugin with Najm framework import { Najm } from 'najm-core'; const app = new Najm(); app.use(DatabasePlugin, { db }); // Use @Transactional decorator in a service class UserService { @Transactional() async createUser(data: { name: string }) { // This method runs inside a database transaction // Automatically commits on success, rolls back on error return await db.insert(users).values(data).returning(); } }
Debug
Known issues
breakingVersion 1.0.0 removed CommonJS support. All imports must use ESM syntax.
fix
Replace require() with import statements. Use dynamic import if necessary.
affects: >=1.0.0 <2.0.0
deprecatedThe `DatabasePlugin` constructor now requires an options object with `db` property. Passing a direct Drizzle instance is deprecated.
fix
Use `new DatabasePlugin({ db: drizzleInstance })` instead of `new DatabasePlugin(drizzleInstance)`.
affects: >=1.1.0
gotchaThe @Transactional decorator only works on methods inside classes that are instantiated by the Najm framework container. Manually instantiated classes will not have transaction support.
fix
Ensure the class is registered as a service or component in Najm.
affects: >=1.0.0
gotchareflect-metadata must be imported at the application entry point before any decorator usage, otherwise @Transactional will throw 'Reflect.getMetadata is not a function'.
fix
Add `import 'reflect-metadata'` at the top of your main file.
affects: >=1.0.0
Errors
Common errors & fixes
Reflect.getMetadata is not a function
reflect-metadata polyfill not imported before decorator usage.
fix
Add `import 'reflect-metadata'` to the top of the entry file.
Cannot find module 'najm-database' or its corresponding type declarations
Missing peer dependency najm-core or incorrect Node.js version (requires ESM).
fix
Run `npm install —legacy-peer-deps` and ensure package.json has `"type": "module"`.
SyntaxError: Unexpected token 'export'
CommonJS context (require) cannot handle ESM-only package.
fix
Convert project to ESM or use dynamic import: `const { DatabasePlugin } = await import('najm-database')`.
TypeError: Class constructor DatabasePlugin cannot be invoked without 'new'
Using `DatabasePlugin()` instead of `new DatabasePlugin()`.
fix
Instantiate with `new DatabasePlugin({ db })`.
Upgrade
Version history
1.1.8latest on npm
Audit
Dependencies
najm-coreoptionalcore framework dependency
reflect-metadatarequiredrequired for decorator functionality
drizzle-ormoptionalpeer dependency for database operations
zodoptionalpeer dependency for schema validation
Agent activity
6 hits · last 30 days
node
6
Resources
najm-database — npm install najm-database · libregistry