Skip to content
This repository was archived by the owner on Apr 17, 2024. It is now read-only.

Latest commit

 

History

History
30 lines (24 loc) · 837 Bytes

README.md

File metadata and controls

30 lines (24 loc) · 837 Bytes

Fastify Simple MySQL

Based on mysql2 library

Features

  • named placeholders
  • async methods
  • config via ENV

Prepare

Set env MYSQL_URL (see: example.env).

Recommend use with fastify-graceful-shutdown plugin for close connection on shutdown.

Methods

  • query - query
  • rows - all rows as array of objects
  • row - single row as object (first row)
  • column - single column as array of values (first column)
  • value - single value (first field from first row)
  • insert - insert and return insertId
  • total - return value of SELECT CALC_FOUND_ROWS() query

Use

// in app
fastify.register(require("fastify-simple-mysql"))

// in route
const r = await this.db.value(`SELECT :a + :b`, {a: 1, b: 2})