{"id":19225793,"url":"https://github.com/0xslipk/fastify-objectionjs","last_synced_at":"2026-04-02T13:33:16.048Z","repository":{"id":42233643,"uuid":"185506008","full_name":"0xslipk/fastify-objectionjs","owner":"0xslipk","description":"fastify-objectionjs is a plugin for the Fastify.","archived":false,"fork":false,"pushed_at":"2023-07-18T20:34:50.000Z","size":828,"stargazers_count":19,"open_issues_count":1,"forks_count":6,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-30T14:19:09.863Z","etag":null,"topics":["fastify","fastify-objectionjs","knex","objectionjs-models"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/0xslipk.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-08T01:39:59.000Z","updated_at":"2025-09-11T00:48:43.000Z","dependencies_parsed_at":"2024-06-18T18:43:07.570Z","dependency_job_id":"b71c91c0-8aaa-4d83-8a57-efa263e21e1e","html_url":"https://github.com/0xslipk/fastify-objectionjs","commit_stats":null,"previous_names":["jarcodallo/fastify-objectionjs"],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/0xslipk/fastify-objectionjs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xslipk%2Ffastify-objectionjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xslipk%2Ffastify-objectionjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xslipk%2Ffastify-objectionjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xslipk%2Ffastify-objectionjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/0xslipk","download_url":"https://codeload.github.com/0xslipk/fastify-objectionjs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xslipk%2Ffastify-objectionjs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31307143,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-02T12:59:32.332Z","status":"ssl_error","status_checked_at":"2026-04-02T12:54:48.875Z","response_time":89,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fastify","fastify-objectionjs","knex","objectionjs-models"],"created_at":"2024-11-09T15:16:19.509Z","updated_at":"2026-04-02T13:33:16.031Z","avatar_url":"https://github.com/0xslipk.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Fastify Objectionjs Plugin\n==========================\n\n[![CircleCI](https://dl.circleci.com/status-badge/img/gh/0xslipk/fastify-objectionjs/tree/main.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/0xslipk/fastify-objectionjs/tree/main)\n[![Coverage Status](https://coveralls.io/repos/github/jarcodallo/fastify-objectionjs/badge.svg?branch=main)](https://coveralls.io/github/jarcodallo/fastify-objectionjs?branch=main)\n[![npm](https://img.shields.io/npm/v/fastify-objectionjs?label=version\u0026logo=npm)](https://www.npmjs.com/package/fastify-objectionjs)\n[![npm](https://img.shields.io/npm/dw/fastify-objectionjs?logo=npm)](https://www.npmjs.com/package/fastify-objectionjs?activeTab=versions)\n[![vulnerabilities](https://img.shields.io/snyk/vulnerabilities/npm/fastify-objectionjs)](https://snyk.io/test/github/jarcodallo/fastify-objectionjs)\n[![License](https://img.shields.io/badge/license-MIT%20License-brightgreen.svg)](https://opensource.org/licenses/MIT)\n\n*fastify-objectionjs* is a plugin for the [Fastify](http://fastify.io/) framework that provides integration with [objectionjs ORM](https://vincit.github.io/objection.js/).\n\nSupports Fastify versions ^4.0.0.\n\nIf you don't provide the `knexConfig.client` by yourself (see below), the plugin use the default configuration:\n\n```js\nconst defaultKnexConfig = {\n  client: 'better-sqlite3',\n  connection: {\n    filename: './default.sqlite'\n  }\n}\n```\n\n### Requirements\n\nNode.js v14 LTS or later.\n\n## Install\n\n```\nnpm i fastify-objectionjs --save\n```\n\n## Usage\nDefine the objectionjs model\n\n```js\n// user.model.js\n'use strict'\n\nconst { Model } = require('objection')\nconst schema = require('./schema')\n\nclass User extends Model {\n  static get tableName () {\n    return 'users'\n  }\n\n  static get jsonSchema () {\n    return Base.generateJsonSchema({\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        salt: { type: 'string', minLength: 1, maxLength: 255 },\n        created_at: { type: 'string' },\n        updated_at: { type: 'string' }\n      }\n    })\n  }\n}\n\nmodule.exports = User\n```\n\nAdd the knex config and objectionjs models to the project with `register`\n\n```js\nconst fastify = require('fastify')()\nconst User = require('./user.model.js')\n\nfastify.register(require('fastify-objectionjs'), {\n  knexConfig: {\n    client: 'better-sqlite3',\n    connection: {\n      filename: './default.sqlite'\n    }\n  },\n  models: [User]\n})\n\nconst schema = {\n  response: {\n    200: {\n      type: 'object',\n      properties: {\n        id: { type: 'integer' },\n        token: { type: 'string' }\n      }\n    },\n    401: {\n      type: 'object',\n      properties: {\n        message: { type: 'string' }\n      }\n    }\n  },\n  body: {\n    type: 'object',\n    properties: {\n      username: { type: 'string', minLength: 1, maxLength: 255 },\n      password: { type: 'string', minLength: 1, maxLength: 255 }\n    },\n    required: ['username', 'password']\n  }\n}\n\nfastify.post('/login', { schema }, async function (request, reply) {\n  const { username, password } = request.body\n\n  const user = await fastify.objection.models.user\n    .query()\n    .findOne({ username })\n\n  if (user \u0026\u0026 fastify.password.validate(user.password, user.salt, password)) {\n    const token = fastify.jwt.sign(\n      { sub: user.username },\n      { expiresIn: '6h' }\n    )\n\n    reply.send({ id: user.id, token })\n  } else {\n    reply.status(401).send({ message: 'Invalid username or password' })\n  }\n})\n\nfastify.listen(3000, err =\u003e {\n  if (err) throw err\n})\n```\n\nYou can also use the plugin only to do the setup and call the model files directly.\n\n```js\nconst fastify = require('fastify')()\nconst User = require('./user.model.js')\n\nfastify.register(require('fastify-objectionjs'), {\n  knexConfig: {\n    client: 'better-sqlite3',\n    connection: {\n      filename: './default.sqlite'\n    }\n  }\n})\n\nconst schema = {\n  response: {\n    200: {\n      type: 'object',\n      properties: {\n        id: { type: 'integer' },\n        token: { type: 'string' }\n      }\n    },\n    401: {\n      type: 'object',\n      properties: {\n        message: { type: 'string' }\n      }\n    }\n  },\n  body: {\n    type: 'object',\n    properties: {\n      username: { type: 'string', minLength: 1, maxLength: 255 },\n      password: { type: 'string', minLength: 1, maxLength: 255 }\n    },\n    required: ['username', 'password']\n  }\n}\n\nfastify.post('/login', { schema }, async function (request, reply) {\n  const { username, password } = request.body\n\n  const user = await User.query().findOne({ username })\n\n  if (user \u0026\u0026 fastify.password.validate(user.password, user.salt, password)) {\n    const token = fastify.jwt.sign(\n      { sub: user.username },\n      { expiresIn: '6h' }\n    )\n\n    reply.send({ id: user.id, token })\n  } else {\n    reply.status(401).send({ message: 'Invalid username or password' })\n  }\n})\n\nfastify.listen(3000, err =\u003e {\n  if (err) throw err\n})\n```\n\n## API\n\n### Options\n\n*fastify-objectionjs* accepts the options object:\n\n```js\n{\n  knexConfig: {\n    client: 'better-sqlite3',\n    connection: {\n      filename: './default.sqlite'\n    }\n  },\n  models: [User],\n  upperCase: false,\n  underscoreBeforeDigits: false,\n  underscoreBetweenUppercaseLetters: false\n}\n```\n\n+ `knexConfig` (Default: `better-sqlite3 connection`): can be set any knex valid configuration.\n+ `models` (Default: `undefined`): a collection of objectionjs models.\n+ `upperCase` (Default: `false`): Set to `true` if your columns are UPPER_SNAKE_CASED.\n+ `underscoreBeforeDigits` (Default: `false`): When `true`, will place an underscore before digits (`foo1Bar2` becomes `foo_1_bar_2`). When `false`, `foo1Bar2` becomes `foo1_bar2`.\n+ `underscoreBetweenUppercaseLetters` (Default: `false`): When `true`, will place underscores between consecutive uppercase letters (`fooBAR` becomes `foo_b_a_r`). When `false`, `fooBAR` will become `foo_bar`.\n\n## Change Log\n\nSee [Changelog](CHANGELOG.md) for more information.\n\n## Contributing\n\nContributions welcome! See [Contributing](CONTRIBUTING.md).\n\n## Collaborators\n\n* [__Jose Ramirez__](https://github.com/0xslipk)\n\n## License\n\nLicensed under the MIT - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0xslipk%2Ffastify-objectionjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F0xslipk%2Ffastify-objectionjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0xslipk%2Ffastify-objectionjs/lists"}