Fastify MariaDB Pool plugin
Fastify MariaDB connection Pool plugin, with this you can share the same MariaDB connection pool in every part of your server.
Under the hood the official MariaDB Node.js connector is used, the options that you pass to register
will be passed to the MariaDB pool builder.
Note: start v2.x required Node.js 10+
Install
npm install fastify-mariadb --save
Usage
Add it to your project with register
and you are done!
This plugin will add the mariadb
namespace in your Fastify instance, with the following properties:
pool: the pool instance
query: an utility to perform a query without a transaction
getConnection: get a connection from the pool
Example:
const fastify = fastify fastify fastify fastify
As you can see there is no need to close the client, since is done internally.
Async await is supported, when register promise
option is true
:
const fastify = fastify fastify fastify
options
promise
-Boolean
(optional, if not present will usecallback
style pool)connectionString
-String
(optional, url string) For example:mariadb://user:pass@host/db?debug=true
Pool options
- Pool options includesconnection options
that will be used when creating new connections.
MariaDB connector/Node.js
most options are similar to mysql/mysql2
driver with more features and performant.
More usage, please see mariadb-connector-nodejs
Acknowledgements
- Most of codes are copied from fastify-mysql.
License
Licensed under MIT.