npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

meadow-connection-mysql

v1.0.14

Published

Meadow MySQL Plugin

Downloads

1,612

Readme

Meadow Connection MySQL

A MySQL connection pool provider for the Meadow ORM. Wraps mysql2 as a Fable service, providing connection pooling with named placeholders, auto-connect support, and DDL generation from Meadow table schemas.

Build Status npm version License: MIT


Features

  • MySQL2 Connection Pooling -- High-performance pooled connections via mysql2
  • Fable Service Provider -- Registers with a Fable instance for dependency injection, logging, and configuration
  • Named Placeholders -- Automatically enables named placeholders for parameterized queries
  • Auto-Connect -- Optional automatic connection on instantiation via the MeadowConnectionMySQLAutoConnect flag
  • Schema-Driven DDL -- Generates CREATE TABLE IF NOT EXISTS statements from Meadow table schemas with primary keys, UTF-8 charset, and proper column types
  • Connection Safety -- Guards against creating duplicate connection pools with descriptive logging (passwords are never leaked)
  • Settings Coercion -- Accepts both Meadow-style (Server, Port, User) and mysql2-native (host, port, user) configuration formats

Installation

npm install meadow-connection-mysql

Quick Start

const libFable = require('fable');
const MeadowConnectionMySQL = require('meadow-connection-mysql');

let fable = new libFable(
{
	MySQL:
	{
		Server: '127.0.0.1',
		Port: 3306,
		User: 'root',
		Password: 'PASSWORD',
		Database: 'my_app',
		ConnectionPoolLimit: 20
	},
	MeadowConnectionMySQLAutoConnect: true
});

fable.serviceManager.addAndInstantiateServiceType('MeadowMySQLProvider',
	MeadowConnectionMySQL);

// Query using the connection pool
fable.MeadowMySQLProvider.pool.query('SELECT * FROM Book LIMIT 10',
	(pError, pRows, pFields) =>
	{
		console.log(`Found ${pRows.length} books.`);
	});

Configuration

The MySQL connection settings can be provided through Fable settings or the service provider options.

Via Fable Settings

let fable = new libFable(
{
	MySQL:
	{
		Server: '127.0.0.1',
		Port: 3306,
		User: 'root',
		Password: 'PASSWORD',
		Database: 'my_app',
		ConnectionPoolLimit: 20
	}
});

Via Provider Options

let connection = fable.instantiateServiceProvider('MeadowConnectionMySQL',
{
	MySQL:
	{
		host: '127.0.0.1',
		port: 3306,
		user: 'root',
		password: 'PASSWORD',
		database: 'my_app',
		connectionLimit: 20
	}
}, MeadowConnectionMySQL);

Both Meadow-style property names (Server, Port, User, Password, Database, ConnectionPoolLimit) and mysql2-native names (host, port, user, password, database, connectionLimit) are supported. The provider automatically coerces the Meadow format to the mysql2 format.

Auto-Connect

Set MeadowConnectionMySQLAutoConnect to true in either Fable settings or provider options to connect automatically on instantiation:

let fable = new libFable(
{
	MySQL: { /* ... */ },
	MeadowConnectionMySQLAutoConnect: true
});

API

connect()

Create the MySQL connection pool synchronously. Guards against double-connect — calling connect() on an already-connected instance logs an error and skips pool creation.

connectAsync(fCallback)

Async wrapper around connect() for consistency with other Meadow connection providers.

| Parameter | Type | Description | |-----------|------|-------------| | fCallback | Function | Callback receiving (error, connectionPool) |

pool (getter)

Returns the underlying mysql2 connection pool for direct query access.

connected (property)

Boolean indicating whether the connection pool has been created.

generateCreateTableStatement(pMeadowTableSchema)

Generate a CREATE TABLE IF NOT EXISTS SQL statement from a Meadow table schema object. Tables are created with utf8mb4 charset and utf8mb4_unicode_ci collation.

| Parameter | Type | Description | |-----------|------|-------------| | pMeadowTableSchema | Object | Meadow table schema with TableName and Columns array |

createTable(pMeadowTableSchema, fCallback)

Execute a CREATE TABLE statement against the connected database.

createTables(pMeadowSchema, fCallback)

Create all tables defined in a Meadow schema object (iterates pMeadowSchema.Tables sequentially).

generateDropTableStatement(pTableName)

Generate a DROP TABLE IF EXISTS SQL statement for the given table name.

Column Type Mapping

| Meadow Type | MySQL Column | |-------------|--------------| | ID | INT UNSIGNED NOT NULL AUTO_INCREMENT (with PRIMARY KEY) | | GUID | CHAR(size) with default GUID (size defaults to 36) | | ForeignKey | INT UNSIGNED NOT NULL DEFAULT '0' | | Numeric | INT NOT NULL DEFAULT '0' | | Decimal | DECIMAL(size) | | String | CHAR(size) NOT NULL DEFAULT '' | | Text | TEXT | | DateTime | DATETIME | | Boolean | TINYINT NOT NULL DEFAULT '0' |

Part of the Retold Framework

Meadow Connection MySQL is a database connector for the Meadow data access layer:

Testing

Run the test suite:

npm test

Run with coverage:

npm run coverage

Related Packages

License

MIT

Contributing

Pull requests are welcome. For details on our code of conduct, contribution process, and testing requirements, see the Retold Contributing Guide.