{"id":42745,"library":"fastify-objectionjs","title":"fastify-objectionjs","description":"A Fastify plugin integrating objection.js ORM. Current version 2.0.1 requires Node.js ^14.x || >=16.x || >=18.x, Fastify ^4.0.0, and has a peer dependency on better-sqlite3. Provides automatic knex setup, model registration, and exposes models via fastify.objection. Uses ESM with CJS fallback. Differentiates by offering a declarative plugin interface for objection.js within Fastify, with default SQLite configuration.","status":"active","version":"2.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/jarcodallo/fastify-objectionjs","tags":["javascript","fastify","objectionjs","orm","typescript"],"install":[{"cmd":"npm install fastify-objectionjs","lang":"bash","label":"npm"},{"cmd":"yarn add fastify-objectionjs","lang":"bash","label":"yarn"},{"cmd":"pnpm add fastify-objectionjs","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency, plugin is designed for Fastify v4","package":"fastify","optional":false},{"reason":"peer dependency, default knex client","package":"better-sqlite3","optional":true}],"imports":[{"note":"Default export is the plugin function. Use ESM import or CJS require without destructuring.","wrong":"const { default } = require('fastify-objectionjs')","symbol":"default","correct":"import fastifyObjectionjs from 'fastify-objectionjs'"},{"note":"CJS require returns the plugin function directly, not an object with a 'plugin' property.","wrong":"const { plugin } = require('fastify-objectionjs')","symbol":"plugin","correct":"const plugin = require('fastify-objectionjs')"},{"note":"Model is exported by objection.js, not by this plugin. Plugin only provides knex setup and model registration.","wrong":"import { Model } from 'fastify-objectionjs'","symbol":"Model","correct":"import { Model } from 'objection'"}],"quickstart":{"code":"import fastify from 'fastify';\nimport fastifyObjectionjs from 'fastify-objectionjs';\nimport { Model } from 'objection';\n\nclass User extends Model {\n  static get tableName() { return 'users'; }\n  static get jsonSchema() {\n    return {\n      type: 'object',\n      required: ['username', 'password'],\n      properties: {\n        id: { type: 'integer' },\n        username: { type: 'string', minLength: 1, maxLength: 255 },\n        password: { type: 'string', minLength: 1, maxLength: 255 }\n      }\n    };\n  }\n}\n\nconst app = fastify();\nawait app.register(fastifyObjectionjs, {\n  knexConfig: {\n    client: 'better-sqlite3',\n    connection: { filename: './test.sqlite' }\n  },\n  models: [User]\n});\n\nconst user = await app.objection.models.user.query().findOne({ username: 'test' });\nconsole.log(user);","lang":"typescript","description":"Registers the plugin with a User model and SQLite config, then queries a user from fastify.objection."},"warnings":[{"fix":"Avoid mutating fastify.objection.knex; create separate knex instances for custom work.","message":"Knex instance mutation: the plugin creates a knex instance and assigns it to fastify.objection.knex; modifying it can affect global state.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Define models directly or clone them before registration if reused.","message":"Model registration mutation: models are mutated with knex instance; reusing models across plugins can cause issues.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use dynamic import or ensure bundler handles CommonJS modules.","message":"Plugin uses CommonJS internally; ESM usage may require specific bundler configuration.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Explicitly pass knexConfig to avoid unintended file creation.","message":"Default knex config uses better-sqlite3; if not provided, a SQLite file is created in the current directory.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Monitor vulnerability databases for better-sqlite3 and objection.js.","message":"No security incidents reported yet, but supply chain risks exist due to peer dependencies (better-sqlite3).","severity":"deprecated","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'14':15 '16':17 '18':19 '2.0.1':12 '4.0.0':22 'automat':33 'better':30 'better-sqlite3':29 'cjs':46 'configur':62 'current':10 'declar':52 'default':60 'depend':27 'differenti':48 'esm':44 'expos':39 'fallback':47 'fastifi':2,5,21,58,64 'fastify-objectionj':1 'fastify.objection':42 'integr':7 'interfac':54 'javascript':63 'knex':34 'model':36,40 'node.js':14 'objection.js':8,56 'objectionj':3,65 'offer':50 'orm':9,66 'peer':26 'plugin':6,53 'provid':32 'registr':37 'requir':13 'setup':35 'sqlite':61 'sqlite3':31 'typescript':67 'use':43 'version':11 'via':41 'within':57 'x':16,18,20","created_at":"2026-06-05T16:56:27.753038+00:00","updated_at":"2026-06-05T16:56:27.753038+00:00","problems":[{"fix":"Ensure fastify.register(fastifyObjectionjs, ...) is called before any route or hook that uses fastify.objection.","cause":"Plugin not registered before accessing fastify.objection.","error":"TypeError: Cannot read properties of undefined (reading 'models')"},{"fix":"Run 'npm install better-sqlite3' to install the required database driver.","cause":"Missing peer dependency better-sqlite3.","error":"Error: knex: require of 'better-sqlite3' failed"},{"fix":"Use 'import fastifyObjectionjs from 'fastify-objectionjs'' or 'const plugin = require('fastify-objectionjs')'.","cause":"Importing the default export incorrectly (e.g., destructuring named export).","error":"Error: Plugin must be a function or a promise"},{"fix":"Run 'npm install objection' to install the ORM dependency.","cause":"objection.js not installed.","error":"UnhandledPromiseRejection: Error: Cannot find module 'objection'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/jarcodallo/fastify-objectionjs#readme","github":"https://github.com/jarcodallo/fastify-objectionjs","docs":null,"changelog":null,"pypi":null,"npm":"fastify-objectionjs","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}