Simple ORM for leveldb/levelup providing getters, setters, and streaming for models backed by sublevels. Current stable version is 2.0.0. Allows defining models with a primary key, supports compound keys via bytewise encoding, and auto-incrementing keys via a keyfn callback. Designed for use with level-sublevel for shared database state across multiple models. Uses an inheritable base class pattern. Lightweight and minimal compared to full ODM solutions like mongoose.
npm install level-ormNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a leveldb-backed ORM model for 'users', saves a user, retrieves it, and deletes it.
Use bytewise as keyEncoding when opening the database: level(path, { keyEncoding: bytewise, valueEncoding: 'json' })Ensure you pass an object like { db: levelInstance } (or a sublevel) as the first argument.Replace with 'class Users extends Model { constructor(container) { super(container, 'users', 'handle'); } }'Implement keyfn as a function that generates a unique value, e.g., using monotonic-timestamp.
Ver 1.x: new Model(db, sublevelName, key). In 2.x: new Model({ db: db }, sublevelName, key).Ensure you pass an object with a 'db' property: new Model({ db: yourLevelInstance }, 'users', 'handle'); instead of new Model(yourLevelInstance, ...).Use bytewise encoding for keys: require('bytewise/hex') and set keyEncoding: bytewise in level options.Define a constructor that calls super with the container, sublevel name, and key, then export the class.