Registry / database / ts-db-helper

ts-db-helper

JSON →
library0.0.15jsnpmunverified

ts-db-helper is an experimental TypeScript ORM for relational databases, currently at version 0.0.15. It provides a lightweight, model-based abstraction over SQL databases with TypeScript-first design, offering simple CRUD operations and type-safe queries. The package has minimal dependencies and is suitable for small projects or quick prototypes. However, it is in early development (pre-1.0), with no stable release cadence, limited features compared to mature ORMs like TypeORM or Prisma, and lacks comprehensive documentation. Key differentiators include its simplicity and focus on TypeScript type inference, but it may lack production readiness and community support.

npm install ts-db-helper
INSTALL
IMPORT
SIG · TS-DB-HELPER
T
ts-db-helper
databasejavascriptv0.0.15
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

default
✓ import DB from 'ts-db-helper'
✗ const DB = require('ts-db-helper').default
ESM default import; CJS require requires .default
Model
✓ import { Model } from 'ts-db-helper'
✗ const { Model } = require('ts-db-helper')
Named export; works in both ESM and CJS
DB
✓ import DB from 'ts-db-helper'
✗ import { DB } from 'ts-db-helper'
DB is the default export, not a named export
QueryBuilder
✓ import { QueryBuilder } from 'ts-db-helper'
✗ import QueryBuilder from 'ts-db-helper'
QueryBuilder is a named export

Shows basic setup of DB connection, defining a Model, and performing CRUD operations (create, find, update, delete).

import DB, { Model } from 'ts-db-helper'; const db = new DB({ host: process.env.DB_HOST ?? 'localhost', port: parseInt(process.env.DB_PORT ?? '3306'), user: process.env.DB_USER ?? 'root', password: process.env.DB_PASS ?? '', database: process.env.DB_NAME ?? 'test' }); class User extends Model { static tableName = 'users'; id!: number; name!: string; email!: string; } async function main() { await db.connect(); // Create user const user = await User.create({ name: 'John', email: 'john@example.com' }); console.log('User created:', user); // Find by id const foundUser = await User.find(user.id); console.log('Found:', foundUser); // Update user.name = 'Jane'; await user.save(); // Delete await user.delete(); await db.close(); } main().catch(console.error);
Debug
Known issues
gotchaThe library is in early stage (v0.0.x). APIs may change without notice. Do not use in production without thorough testing.
fix
Consider using mature ORMs like TypeORM, Prisma, or Sequelize for production.
affects: >=0.0.0
deprecatedNo deprecation notices documented; but pre-1.0 versions may have breaking changes.
fix
Pin exact version and review changelog before updating.
affects: >=0.0.0
gotchaDefault export (DB) is used to create a connection instance. Some users mistakenly import { DB } as named export.
fix
Use `import DB from 'ts-db-helper'` (no curly braces).
affects: >=0.0.0
gotchaModel class requires a static `tableName` property. Forgetting this will cause runtime errors.
fix
Always define static tableName in model subclasses.
affects: >=0.0.0
gotchaDatabase connections must be opened and closed explicitly. No connection pooling built-in.
fix
Call db.connect() before queries and db.close() after done.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'ts-db-helper'
Package not installed or import path incorrect.
fix
Run `npm install ts-db-helper` and ensure import path is correct.
TypeError: db.connect is not a function
DB used as a named import instead of default import.
fix
Use `import DB from 'ts-db-helper'` (default import).
Property 'tableName' is missing in class User
Static tableName not defined in Model subclass.
fix
Add `static tableName = 'users'` to the class.
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost'
Invalid database credentials.
fix
Check DB_HOST, DB_USER, DB_PASS environment variables or config.
Upgrade
Version history
0.0.15latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
19 hits · last 30 days
node
18
OpenAI (training)
1
Resources
ts-db-helper — npm install ts-db-helper · libregistry