Registry / database / sworm
library3.8.1jsnpmunverified

A lightweight write-only Node.js ORM supporting MSSQL, PostgreSQL, MySQL, Oracle, SQLite, and Web SQL. Version 3.8.1 is current. Sworm focuses on writing graphs of related entities while querying is done with raw SQL to avoid performance pitfalls like opaque query generation, N+1 queries, and complex relationship management. It provides a simple model API for defining tables and relationships, connects lazily, and supports both callback and promise patterns. It is a niche alternative to full-featured ORMs like Sequelize or TypeORM, emphasizing simplicity and database-agnostic write operations.

npm install sworm
INSTALL
IMPORT
SIG · SWORM
S
sworm
databasejavascriptv3.8.1
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.

db
const sworm = require('sworm'); const db = sworm.db();
import { db } from 'sworm';
sworm uses CommonJS and requires a factory call to create a db instance; there is no default export or named import for 'db'.
model
const person = db.model({table: 'people'});
const person = sworm.model({table: 'people'});
model() is a method on a db instance, not on the sworm module directly.
connect
db.connect({ driver: 'pg', config: { ... } });
sworm.connect({ ... });
connect() is called on a db instance, not the sworm module.

Demonstrates creating a sworm db instance, defining a model for the 'people' table, connecting to PostgreSQL, saving a record, and disconnecting.

const sworm = require('sworm'); const db = sworm.db({ driver: 'pg', config: { user: process.env.PGUSER ?? 'postgres', password: process.env.PGPASSWORD ?? '', host: process.env.PGHOST ?? 'localhost', database: process.env.PGDATABASE ?? 'test' } }); const person = db.model({ table: 'people' }); async function main() { await db.connect(); const bob = person({ name: 'Bob' }); await bob.save(); console.log('Saved Bob'); await db.disconnect(); } main().catch(console.error);
Debug
Known issues
gotchasworm uses lazy connection: the first database interaction triggers the connection. Ensure all configuration is set before any operation.
fix
Call db.connect() explicitly before performing any database operations to avoid unexpected connection timing.
affects: >=1.0.0
gotchasworm is write-only; querying is done with raw SQL via db.query() or similar methods. Do not expect ORM-style query builders for reads.
fix
Use raw SQL for queries: const rows = await db.query('SELECT * FROM people WHERE name = $1', ['Bob']);
affects: >=1.0.0
gotchaThe model() function does not auto-create tables; it assumes the table already exists in the database.
fix
Ensure the table is created before attempting to insert records, or use migrations/schema scripts.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'pg'
The required database driver (pg) is not installed.
fix
Run: npm install pg
Error: connect ECONNREFUSED 127.0.0.1:5432
PostgreSQL is not running or connection details are incorrect.
fix
Start PostgreSQL service or check host/port in config.
TypeError: db.model is not a function
db was created incorrectly, likely by calling sworm() instead of sworm.db().
fix
Use const db = sworm.db(); then db.model(...) or check if sworm is properly imported.
Upgrade
Version history
3.8.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
16 hits · last 30 days
node
12
Meta
2
OpenAI (training)
1
Resources
packagesworm
sworm — npm install sworm · libregistry