Registry / database / djorm
library0.2.0-alpha.5jsnpmunverified

A Django-like ORM framework for Node.js (v0.2.0-alpha.5), still in early alpha. It provides a familiar API for developers coming from Django, with model definitions, querying, and migrations. The project is experimental and not yet stable, with major changes expected. It targets Node >=16 and uses ESM.

npm install djorm
INSTALL
IMPORT
SIG · DJORM
D
djorm
databasejavascriptv0.2.0-alpha.5
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.

Model
import { Model } from 'djorm'
const { Model } = require('djorm')
ESM-only, no CommonJS support.
Field types
import { CharField, IntegerField } from 'djorm'
import CharField from 'djorm'
Named exports per field type.
QuerySet
import { QuerySet } from 'djorm'
Used for building queries; not exposed in older alpha versions.

Define models with fields, create instances, and perform queries with filtering and relations.

import { Model, CharField, IntegerField, AutoField, ForeignKey, ManyToManyField, OneToOneField } from 'djorm' class Author extends Model { static fields = { id: AutoField({ primaryKey: true }), name: CharField({ maxLength: 100 }), age: IntegerField() } } class Book extends Model { static fields = { id: AutoField({ primaryKey: true }), title: CharField({ maxLength: 200 }), author: ForeignKey(Author), tags: ManyToManyField(Tag) } } class Tag extends Model { static fields = { id: AutoField({ primaryKey: true }), name: CharField({ maxLength: 50 }) } } async function main() { const author = await Author.objects.create({ name: 'Jane Doe', age: 30 }) const book = await Book.objects.create({ title: 'My Book', author }) const books = await Book.objects.filter({ author__name: 'Jane Doe' }).all() const tag = await Tag.objects.get({ name: 'fiction' }) await book.tags.add(tag) console.log(books) } main().catch(console.error)
Debug
Known issues
breakingAlpha stage: API is unstable; expect breaking changes in minors.
fix
Pin to exact version and update carefully.
affects: =0.2.0-alpha.5
deprecatedModelMeta class deprecated in favor of static fields and Meta class.
fix
Use static fields property and optional static Meta class.
affects: >0.1.0
gotchaESM-only package; require() will fail.
fix
Use import syntax or dynamic import().
affects: >=0.2.0
gotchaAutoField must be explicitly defined for primary keys; not automatic.
fix
Add AutoField({ primaryKey: true }) to your model.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: Class constructor Model cannot be invoked without 'new'
Using require() instead of import in ESM package.
fix
Change to ES module import: import { Model } from 'djorm'
ReferenceError: Cannot access 'Author' before initialization
Circular dependency or forward reference in ForeignKey.
fix
Use string references: ForeignKey('Author') or restructure modules.
Error: Field must have a primaryKey defined
Missing primary key on model.
fix
Define AutoField({ primaryKey: true }) on the model.
Upgrade
Version history
0.2.0-alpha.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
6
Resources
packagedjorm
djorm — npm install djorm · libregistry