Registry / database / knight-orm

knight-orm

JSON →
library1.0.0-rc.1jsnpmunverified

A lightweight, non-invasive ORM for TypeScript/JavaScript that stores object trees into relational databases. Current version is 1.0.0-rc.1 (release candidate). Uses knight-criteria for query definitions and knight-sql for SQL generation. Designed to be minimal and flexible, supporting PostgreSQL, MySQL, and SQLite. Unlike heavier ORMs, it keeps domain objects free from framework annotations, using a separate schema definition for mapping. Supports CRUD operations, transactions via companion packages, and optional type safety with TypeScript.

npm install knight-orm
INSTALL
IMPORT
SIG · KNIGHT-ORM
K
knight-orm
databasejavascriptv1.0.0-rc.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.

Schema
import { Schema } from 'knight-orm'
const Schema = require('knight-orm').Schema
ESM default. CommonJS require may work but ESM is preferred.
Orm
import { Orm } from 'knight-orm'
import Orm from 'knight-orm'
Named export, not default.
MysqlFactory
import { MysqlFactory } from 'knight-orm'
Factory for MySQL dialect. Use with Orm constructor.

Shows schema definition, ORM instantiation with PostgreSQL, and basic store operation.

import { Schema, Orm } from 'knight-orm' import { Pool } from 'pg' class Knight { id: number name: string constructor(name: string) { this.name = name } } const schema = new Schema() schema.addTable('knight', { columns: { 'id': { property: 'id', primaryKey: true, generated: true }, 'name': 'name' }, newInstance: () => new Knight('') }) const pool = new Pool({ /* connection config */ }) const queryFn = (sql: string, values?: any[]) => pool.query(sql, values) const orm = new Orm(schema, 'postgres') const knight = new Knight('Lancelot') async function main() { await orm.store(queryFn, knight) console.log('Stored:', knight.id) } main().catch(console.error)
Debug
Known issues
breakingRelease candidate may have API changes before stable 1.0.0
fix
Pin exact version and test after each RC update.
affects: =1.0.0-rc.1
gotchaSchema requires newInstance function; default constructor not automatically detected
fix
Always provide newInstance in schema options.
affects: >=0
gotchaPrimary key must be explicitly defined in schema columns
fix
Set primaryKey: true on column mapping.
affects: >=0
gotchaGenerated primary keys (auto-increment) require generated: true in column definition
fix
Add generated: true to primary key column.
affects: >=0
deprecatedOrm constructor uses string dialect name; future versions may use factory pattern
fix
Use dedicated dialect factories like MysqlFactory, PostgresFactory when available.
affects: =1.0.0-rc.1
Errors
Common errors & fixes
TypeError: schema.addTable is not a function
Schema not imported correctly or instantiated without new
fix
Correct import: import { Schema } from 'knight-orm' then const schema = new Schema()
Error: No primary key defined for table 'knight'
Missing primaryKey: true in column mapping
fix
Add primaryKey: true to the id column definition in schema.addTable
Error: Column 'name' is not mapped in schema
Schema column mapping missing for property
fix
Ensure table column mapping includes a 'name' entry with property 'name'
Upgrade
Version history
1.0.0-rc.1latest on npm
Audit
Dependencies
knight-changerequiredObject diffing for updates
knight-criteriarequiredQuery criteria definition
knight-logrequiredLogging
knight-sqlrequiredSQL string generation
Agent activity
7 hits · last 30 days
node
6
Resources
knight-orm — npm install knight-orm · libregistry