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

Ivan-Baranov/fastify-simple-mysql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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})

Releases

No releases published

Packages

No packages published