Registry / database / typescript-nedb-orm

typescript-nedb-orm

JSON →
library1.7.0jsnpmunverified

typescript-nedb-orm v1.7.0 is a lightweight ORM/ODM for @seald-io/nedb, a portable, file-based database for Node.js. Written entirely in TypeScript, it provides a decorator-free class-based approach to define models that extend a generic ORM class. Key features include automatic ID generation (via IID interface), CRUD operations (save, find, update, delete, remove, findOne, findById, count), and static methods for queries. Released under MIT, it targets Node.js environments. Maintained by a single developer, it is a simple alternative to heavier ORMs like Sequelize or Mongoose, leveraging NEDB's embedded nature but without support for relationships or migrations.

npm install typescript-nedb-orm
INSTALL
IMPORT
SIG · TYPESCRIPT-NEDB-OR
T
typescript-nedb-orm
databasejavascriptv1.7.0
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.

ORM
✓ import { ORM } from 'typescript-nedb-orm'
✗ const ORM = require('typescript-nedb-orm').ORM
ESM import is the standard. CommonJS require works but is not typical.
IID
✓ import { IID } from 'typescript-nedb-orm'
✗ const { IID } = require('typescript-nedb-orm')
IID is an interface used for extending model interfaces. Import alongside ORM.
default
✓ import typescriptNedbOrm from 'typescript-nedb-orm'
✗ import * as typescriptNedbOrm from 'typescript-nedb-orm'
There is no default export; the above will result in undefined. Always use named imports.

Defines a Person model extending ORM, saves, queries, and deletes documents.

import { IID, ORM } from 'typescript-nedb-orm' interface IPerson extends IID { name: string email: string } class Person extends ORM<IPerson> implements IPerson { name: string email: string constructor(person: IPerson) { super(person) this.name = person.name this.email = person.email } } async function run() { const person = new Person({ name: 'Luc', email: 'luc@luc.fr' }) const saved: IPerson = await person.save() const found: IPerson | null = await Person.findOne<IPerson>({ name: 'Luc' }) console.log(found?.email) // luc@luc.fr await person.delete() } run().catch(console.error)
Debug
Known issues
gotchaModel classes must implement the field interface and call super() with the same data; failing to do so results in undefined fields.
fix
Ensure constructor copies all fields from the argument to this before calling super, or delegate to super(person) and assign after.
affects: >=1.0.0
gotchaStatic methods like find, findOne, findById, update, remove, count are asynchronous and must be awaited.
fix
Always await static method calls, or use .then().
affects: >=1.0.0
deprecatedThe ORM class constructor expects an object with IID (id field); omitting id will cause type errors.
fix
Include id: string in your interface or use a default UUID-like string.
affects: >=1.0.0
gotchaThe package depends on @seald-io/nedb, which is a fork of the original NeDB. Some query operators may differ.
fix
Refer to @seald-io/nedb documentation for supported query operators.
affects: >=1.0.0
Errors
Common errors & fixes
Property 'save' does not exist on type 'Person'.
Forgetting to extend ORM<IPerson> or calling save on instance without await inside async context.
fix
Ensure the class extends ORM<IPerson> and that save() is called inside an async function with await.
Cannot find name 'IID'
Missing import of IID from typescript-nedb-orm.
fix
Add import { IID, ORM } from 'typescript-nedb-orm' at the top of the file.
The 'this' context of type 'Person' is not assignable to method's 'this' of type 'ORM<IPerson>'
Calling a method like save() directly without an instance or using class instead of instance.
fix
Ensure methods are called on instances of Person, not on the class itself (except static methods).
Upgrade
Version history
1.7.0latest on npm
Audit
Dependencies
@seald-io/nedbrequiredRuntime dependency; provides the underlying NeDB database engine.
Agent activity
20 hits · last 30 days
node
18
OpenAI (training)
1
Resources
typescript-nedb-orm — npm install typescript-nedb-orm · libregistry