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)
Errors
Common errors & fixes
TypeError: Class constructor Model cannot be invoked without 'new'
Using require() instead of import in ESM package.
fixChange to ES module import: import { Model } from 'djorm' ReferenceError: Cannot access 'Author' before initialization
Circular dependency or forward reference in ForeignKey.
fixUse string references: ForeignKey('Author') or restructure modules. Error: Field must have a primaryKey defined
Missing primary key on model.
fixDefine AutoField({ primaryKey: true }) on the model. Upgrade
Version history
0.2.0-alpha.5latest on npm
Audit
Dependencies
No dependency data recorded yet.