{"id":42743,"library":"fastify-at-mysql","title":"fastify-at-mysql","description":"Fastify MySQL plugin using @databases/mysql to prevent SQL injection attacks. Version 0.4.0 provides a wrapper that exposes mysql property on Fastify instance, supporting queries, transactions, and tasks with built-in SQL injection protection via tagged template literals. It offers result types: raw (default), iterator, and stream. The plugin is actively maintained, ships TypeScript types, and requires Fastify v4+ and @databases/mysql as peer dependencies.","status":"active","version":"0.4.0","language":"javascript","source_language":"en","source_url":"https://github.com/mateonunez/fastify-at-mysql","tags":["javascript","fastify","mysql","@databases","typescript"],"install":[{"cmd":"npm install fastify-at-mysql","lang":"bash","label":"npm"},{"cmd":"yarn add fastify-at-mysql","lang":"bash","label":"yarn"},{"cmd":"pnpm add fastify-at-mysql","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency: plugin registers on Fastify instance","package":"fastify","optional":false},{"reason":"Underlying MySQL client for safe queries","package":"@databases/mysql","optional":false}],"imports":[{"note":"Package ships TypeScript types and supports both ESM and CJS.","wrong":"const fastifyMysql = require('fastify-at-mysql').default","symbol":"default","correct":"import fastifyMysql from 'fastify-at-mysql'"},{"note":"In CommonJS, require returns the default export directly.","wrong":"const { default: fastifyMysql } = require('fastify-at-mysql')","symbol":"fastifyMysql (CommonJS)","correct":"const fastifyMysql = require('fastify-at-mysql')"}],"quickstart":{"code":"import Fastify from 'fastify';\nimport fastifyMysql from 'fastify-at-mysql';\n\nconst app = Fastify();\n\napp.register(fastifyMysql, {\n  host: process.env.DB_HOST ?? 'localhost',\n  port: parseInt(process.env.DB_PORT ?? '3306'),\n  user: process.env.DB_USER ?? 'root',\n  password: process.env.DB_PASS ?? '',\n  database: process.env.DB_NAME ?? 'test',\n});\n\napp.get('/users', async (request, reply) => {\n  const { rows } = await app.mysql.query(app.mysql.sql`SELECT * FROM users`);\n  return rows;\n});\n\nawait app.listen({ port: 3000 });","lang":"typescript","description":"Registers the MySQL plugin, then uses tagged template literals to safely query users."},"warnings":[{"fix":"Use `fastify.mysql.sql` for all queries.","message":"Ensure you use the `sql` tagged template from `fastify.mysql.sql` to prevent SQL injection, not raw strings.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Upgrade Fastify to v4+ or use an older version of the plugin if needed.","message":"The plugin expects Fastify v4+; using with Fastify v3 may cause register issues.","severity":"breaking","affected_versions":">=0.4.0"},{"fix":"Remove `{ type: 'raw' }` option; raw is now default.","message":"The `query` method with `{ type: 'raw' }` is deprecated in favor of default behavior (raw).","severity":"deprecated","affected_versions":">=0.3.0"},{"fix":"Ensure transaction callbacks are async or return a promise.","message":"When using `transaction`, each callback must be an async function or return a promise.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Access MySQL through the Fastify instance: `fastify.mysql`.","message":"Do not import `mysql` directly from `@databases/mysql`; always use `fastify.mysql` from the plugin.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"search_vec":"'0.4.0':16 'activ':55 'attack':14 'built':34 'built-in':33 'databas':72 'databases/mysql':9,65 'default':48 'depend':68 'expos':21 'fastifi':2,5,25,62,70 'fastify-at-mysql':1 'inject':13,37 'instanc':26 'iter':49 'javascript':69 'liter':42 'maintain':56 'mysql':4,6,22,71 'offer':44 'peer':67 'plugin':7,53 'prevent':11 'properti':23 'protect':38 'provid':17 'queri':28 'raw':47 'requir':61 'result':45 'ship':57 'sql':12,36 'stream':51 'support':27 'tag':40 'task':31 'templat':41 'transact':29 'type':46,59 'typescript':58,73 'use':8 'v4':63 'version':15 'via':39 'wrapper':19","created_at":"2026-06-05T16:56:27.695258+00:00","updated_at":"2026-06-05T16:56:27.695258+00:00","problems":[{"fix":"Call `app.register(fastifyMysql, options)` before using `fastify.mysql`.","cause":"Plugin not registered or registration order wrong.","error":"TypeError: fastify.mysql is not a function"},{"fix":"Ensure MySQL is running and accessible; check environment variables for DB_HOST and DB_PORT.","cause":"MySQL not running or host/port incorrect.","error":"Error: connect ECONNREFUSED ::1:3306"},{"fix":"Run `npm install @databases/mysql`.","cause":"Missing peer dependency @databases/mysql.","error":"Cannot find module '@databases/mysql'"},{"fix":"Always use `fastify.mysql.sql` tagged template: `fastify.mysql.sql`SELECT * FROM contributors``.","cause":"Using `sql` without importing or misusing as a regular function.","error":"SyntaxError: Unexpected token using 'sql' tag"}],"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/mateonunez/fastify-at-mysql#readme","github":"https://github.com/mateonunez/fastify-at-mysql","docs":null,"changelog":null,"pypi":null,"npm":"fastify-at-mysql","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}}