{"id":20248817,"url":"https://github.com/webeetle/fastify-waterline","last_synced_at":"2025-04-10T22:24:57.244Z","repository":{"id":34890787,"uuid":"186598468","full_name":"webeetle/fastify-waterline","owner":"webeetle","description":"Attaches a Waterline ORM to a Fastify server instance.","archived":false,"fork":false,"pushed_at":"2022-12-20T17:26:49.000Z","size":968,"stargazers_count":4,"open_issues_count":4,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T19:22:08.474Z","etag":null,"topics":["fastify","fastify-plugin","nodejs","nodejs-modules","waterline"],"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/webeetle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-14T10:18:52.000Z","updated_at":"2021-06-23T15:58:26.000Z","dependencies_parsed_at":"2023-01-15T09:58:49.909Z","dependency_job_id":null,"html_url":"https://github.com/webeetle/fastify-waterline","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webeetle%2Ffastify-waterline","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webeetle%2Ffastify-waterline/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webeetle%2Ffastify-waterline/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webeetle%2Ffastify-waterline/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webeetle","download_url":"https://codeload.github.com/webeetle/fastify-waterline/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247999840,"owners_count":21031044,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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-plugin","nodejs","nodejs-modules","waterline"],"created_at":"2024-11-14T09:49:44.719Z","updated_at":"2025-04-10T22:24:57.219Z","avatar_url":"https://github.com/webeetle.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fastify-waterline\n\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/) ![Build Status](https://travis-ci.com/webeetle/fastify-waterline.svg?branch=master) [![Greenkeeper badge](https://badges.greenkeeper.io/webeetle/fastify-waterline.svg)](https://greenkeeper.io/) ![npm-version](https://img.shields.io/npm/v/fastify-waterline.svg)\n\n`fastify-waterline` add a [Waterline](https://waterlinejs.org/) ORM instance to your [Fastify](https://github.com/fastify/fastify) project.\n\n## What is Waterline?\n\nWaterline is a datastore-agnostic tool that dramatically simplifies interaction with one or more databases. It provides an abstraction layer on top of the underlying database, allowing you to easily query and manipulate your data without writing vendor-specific integration code.\n\n## Install\n\n```\nnpm i fastify-waterline --save\n```\n\n## Usage\n\nFirst of all you need to define a model. A model represents a set of structured data, called records. Models usually correspond to a table/collection in a database, attributes correspond to columns/fields, and records correspond to rows/documents. Here is an example:\n\n```\n// file models/user.js\n'use strict'\n\nmodule.exports = {\n  attributes: {\n    id: {\n      type: 'number',\n      autoMigrations: { autoIncrement: true }\n    },\n    firstName: {\n      type: 'string',\n      required: true\n    },\n    lastName: {\n      type: 'string',\n      required: true\n    },\n    username: {\n      type: 'string',\n      required: true\n    }\n  },\n  primaryKey: 'id',\n  tableName: 'users'\n}\n```\n\nNow let's imagine that this model represent a table in a MySQL database called `test`. Now we can add the `fastify-waterline` plugin at our fastify instance in this way:\n\n```\nconst fastify = Fastify()\nfastify.register(require('fastify-waterline'), [{\n  name: 'mysql',\n  adapter: 'mysql',\n  host: 'localhost',\n  port: 3306,\n  user: 'root',\n  database: 'test',\n  entitiesFolder: './models'\n}])\n\nfastify.ready(async err =\u003e {\n  if (err) {\n    fastify.log.error(err)\n  }\n\n  const UserModel = await fastify.fw.getModel('user')\n  let newUser = await UserModel.create({\n    firstName: 'Davide',\n    lastName: 'D\\'Antonio',\n    username: 'ddantonio'\n  }).meta({ fetch: true })\n})\n```\n\nThe Fastify instance expose two methods `getModel` and `getInstance`\n\n## Options\n\n|  Option | Description |\n| ------------- | ------------- |\n| `name` | The name of the connection |\n| `adapter` | The adapter that must be used. One of `mysql`, `mongo`, `postgresql`, `disk`|\n| `host` | The database host |\n| `port` | The database port |\n| `user` | The database user |\n| `password` | The database password |\n| `entitiesFolder` | The folder path of our `.js` entities files |\n| `entities` | An array of entities for example `[ require('./models/user'), require('./models/post') ]` |\n\nOther available options can be found on [here](https://github.com/balderdashy/waterline)\n\n## Contributing\n\nIf you feel you can help in any way, be it with examples, extra testing, or new features please open a pull request or open an issue.\n\nThe code follows the Standard code style.\n\n[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)\n\n## Acknowledgements\n\nThis project is kindly sponsored by [Webeetle](http://webeetle.com)\n\n## License\n\nLicensed under [MIT](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebeetle%2Ffastify-waterline","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebeetle%2Ffastify-waterline","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebeetle%2Ffastify-waterline/lists"}