{"id":20046175,"url":"https://github.com/spa5k/fastify-slonik","last_synced_at":"2026-03-09T19:13:36.229Z","repository":{"id":37078832,"uuid":"391133550","full_name":"spa5k/fastify-slonik","owner":"spa5k","description":"Fastify Slonik Plugin to help access slonik from anywhere in a fastify app.","archived":false,"fork":false,"pushed_at":"2026-02-24T01:41:55.000Z","size":556,"stargazers_count":7,"open_issues_count":11,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-02-24T08:15:07.251Z","etag":null,"topics":["fastify","fastify-plugin","hacktoberfest","postgres","postgresql","slonik","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/spa5k.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-07-30T16:47:06.000Z","updated_at":"2023-04-08T12:20:24.000Z","dependencies_parsed_at":"2023-02-15T14:31:05.426Z","dependency_job_id":"f58151d4-380a-4b90-bc30-ef1867225404","html_url":"https://github.com/spa5k/fastify-slonik","commit_stats":{"total_commits":97,"total_committers":6,"mean_commits":"16.166666666666668","dds":0.5257731958762887,"last_synced_commit":"105bc2aa88c8b308e5acf3b66923b5e8965b140c"},"previous_names":["unbuttun/fastify-slonik"],"tags_count":26,"template":false,"template_full_name":null,"purl":"pkg:github/spa5k/fastify-slonik","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spa5k%2Ffastify-slonik","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spa5k%2Ffastify-slonik/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spa5k%2Ffastify-slonik/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spa5k%2Ffastify-slonik/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spa5k","download_url":"https://codeload.github.com/spa5k/fastify-slonik/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spa5k%2Ffastify-slonik/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30308907,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-09T17:35:44.120Z","status":"ssl_error","status_checked_at":"2026-03-09T17:35:43.707Z","response_time":61,"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-plugin","hacktoberfest","postgres","postgresql","slonik","typescript"],"created_at":"2024-11-13T11:21:40.796Z","updated_at":"2026-03-09T19:13:36.215Z","avatar_url":"https://github.com/spa5k.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fastify Slonik\n\nA [Fastify](https://www.fastify.io/) plugin that uses the PostgreSQL client, [Slonik](https://www.npmjs.com/package/slonik). Slonik abstracts repeating code patterns, protects against unsafe connection handling and value interpolation, and provides a rich debugging experience.\n\nFor fastify v4, use latest version, for fastify v3, use v1.4x.\n\n[![NPM downloads](https://img.shields.io/npm/dm/fastify-slonik.svg?style=for-the-badge)](https://www.npmjs.com/package/fastify-slonik)\n[![npm](https://img.shields.io/npm/v/fastify-slonik?logo=npm\u0026style=for-the-badge)](https://www.npmjs.com/package/fastify-slonik)\n![node-current](https://img.shields.io/badge/Node-%3E=14-success?style=for-the-badge\u0026logo=node)\n\n## Usage\n\nYarn\n\n```sh\nyarn add fastify-slonik\n```\n\nNPM\n\n```sh\nnpm i fastify-slonik\n```\n\nPNPM\n\n```sh\npnpm i fastify-slonik\n```\n\n## Example:\n\n### Import the Plugin\n\nBoth default export and named export option is available.\n\n```js\n// index.js\nconst { fastifySlonik } = require(\"fastify-slonik\");\n\n// Or\nconst fastifySlonik = require(\"fastify-slonik\");\n```\n\nor\n\n```js\nimport { fastifySlonik } from \"fastify-slonik\";\n\n// or\n\nimport fastifySlonik from \"fastify-slonik\";\n```\n\n### Register the Plugin\n\n```ts\n// register fastify-slonik\ntry {\n  await app.register(fastifySlonik, {\n    connectionString: process.env.DATABASE_URL,\n  });\n} catch (err) {\n  console.log(\"🔴 Failed to connect, check your Connection string\");\n  throw new Error(err);\n}\n```\n\n### Using the plugin through decorators\n\nFastifyInstance (this) and FastifyRequest (request) have been decorated with slonik and sql.\nUse it the way you want.\n\n```ts\n// setup test route\n// The decorated Fastify server is bound to this in route route handlers:\nfastify.get('/users', async function (this, request, reply) {\n  const { sql, slonik } = this;\n  const queryText = sql`SELECT * FROM users WHERE user_id = 1`\n  const user = await slonik.query(queryText)\n\n  reply.send(user)\n}\n```\n\n### Another way to access the Slonik and SQL decorator is through the request object-\n\n```ts\nfastify.get('/users', async function (request, reply) {\n  const { sql, slonik } = request\n  const queryText = sql`SELECT * FROM users WHERE user_id = 1`\n\n  const user = await slonik.query(queryText)\n  reply.send(user)\n}\n```\n\n[Docs for This](https://www.fastify.io/docs/latest/Reference/Decorators/#decoratename-value-dependencies)\n\nView [Slonik API](https://github.com/gajus/slonik#slonik-usage-api) for details.\n\n## Development and Testing\n\n[Tap](https://node-tap.org/) is used for testing. Use `pnpm test` command to run tests.\n\n### Docker approach\n\n```\n$ docker-compose up\n```\n\nTo run the tests:\n\n- Create .env `cp .env.example .env`\n\n```\n$ yarn test\n```\n\n### Custom Postgres approach\n\n1. Set up a database of your choice in a postgres server of your choice\n2. Create the required table using\n   ```sql\n   CREATE TABLE users(id serial PRIMARY KEY, username VARCHAR (50) NOT NULL);\n   ```\n3. Create .env `cp .env.example .env` and update environment variables accordingly\n\n## License\n\nLicensed under [MIT](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspa5k%2Ffastify-slonik","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspa5k%2Ffastify-slonik","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspa5k%2Ffastify-slonik/lists"}