Objection.js is a relational query builder and ORM for Node.js, built on top of Knex. Current stable version is 3.1.5, released in 2023, with monthly releases. It provides full SQL power with an intuitive model-based API, supporting eager loading, graph operations, JSON schema validation, and transactions. Key differentiators: it stays close to SQL, does not hide the database behind abstractions, and offers official TypeScript support. All databases supported by Knex are supported (SQLite, PostgreSQL, MySQL). Requires Node >=14 and Knex >=1.0.1 as a peer dependency.
npm install objectionNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows basic setup: bind Knex to Model, define a model with JSON schema, create table, insert and query a user.
Replace `ModelClass<SomeModel>` with `typeof SomeModel`.
If using TypeScript, use `QueryBuilderType<Model>` as return type.
Use `modelInstance.relatedQuery('relationName')` instead of `modelInstance.$relatedQuery('relationName')`.Call `Model.knex(knex)` with your Knex instance at app startup.
Override `$beforeUpdate` to call `await this.$validate()` or use `allowInsert`/`allowUpdate` options.
Add `Model.knex(knex)` in your app initialization after creating the Knex instance.
Install knex as a peer dependency: `npm install knex`.
Check that the relation name in `eager()` matches exactly one of the keys in `static get relationMappings()`.
Use `typeof MyModel` instead of `ModelClass<MyModel>`.