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-mssql

v1.0.16

Published

Meadow MSSQL Plugin

Readme

Meadow Connection MSSQL

A Microsoft SQL Server connection provider for the Meadow ORM. Wraps mssql (Tedious) as a Fable service, providing connection pooling with configurable timeouts, prepared statements, and DDL generation from Meadow table schemas.

Build Status npm version License: MIT


Features

  • MSSQL Connection Pooling -- Managed connection pool via mssql (Tedious driver)
  • Fable Service Provider -- Registers with a Fable instance for dependency injection, logging, and configuration
  • Async Connection -- Truly asynchronous connection flow with promise-based pool creation and callback interface
  • Prepared Statements -- Built-in preparedStatement getter for creating parameterized queries against the pool
  • Direct Driver Access -- MSSQL getter exposes the raw mssql package for type constants (Int, VarChar, Decimal, etc.)
  • Schema-Driven DDL -- Generates CREATE TABLE statements with [dbo] schema prefix, IDENTITY primary keys, and proper MSSQL column types
  • Connection Safety -- Guards against duplicate connection pools with descriptive logging (passwords are never leaked)
  • Configurable Timeouts -- Request timeout (80s) and connection timeout (80s) with pool idle timeout (30s) defaults

Installation

npm install meadow-connection-mssql

Quick Start

const libFable = require('fable');
const MeadowConnectionMSSQL = require('meadow-connection-mssql');

let fable = new libFable(
{
	MSSQL:
	{
		server: 'localhost',
		port: 1433,
		user: 'sa',
		password: 'PASSWORD',
		database: 'my_app'
	}
});

let connection = fable.instantiateServiceProvider('MeadowConnectionMSSQL',
	{}, MeadowConnectionMSSQL);

connection.connectAsync((pError, pPool) =>
{
	if (pError)
	{
		console.error('Connection failed:', pError);
		return;
	}

	// Query using the connection pool
	connection.pool.query('SELECT TOP 10 * FROM Book')
		.then((pResult) =>
		{
			console.log(`Found ${pResult.recordset.length} books.`);
		});
});

Configuration

The MSSQL connection settings are provided through the Fable settings MSSQL object:

let fable = new libFable(
{
	MSSQL:
	{
		server: 'localhost',
		port: 1433,
		user: 'sa',
		password: 'PASSWORD',
		database: 'my_app'
	}
});

Configuration Options

| Setting | Type | Default | Description | |---------|------|---------|-------------| | server | String | — | SQL Server hostname or IP address | | port | Number | 1433 | TCP port | | user | String | — | Login user | | password | String | — | Login password | | database | String | — | Database name | | MeadowConnectionMSSQLAutoConnect | Boolean | false | Auto-connect on instantiation (calls connect()) |

Connection Pool Defaults

The provider configures sensible pool defaults:

  • Pool max: 10 connections
  • Pool min: 0 connections
  • Idle timeout: 30,000 ms
  • Request timeout: 80,000 ms
  • Connection timeout: 80,000 ms
  • Trust server certificate: true (for local dev and self-signed certs)
  • UTC mode: disabled (useUTC: false)

API

connectAsync(fCallback)

Open the MSSQL connection pool asynchronously. This is the recommended connection method — MSSQL connections are inherently asynchronous.

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

connect()

Synchronous convenience wrapper that calls connectAsync without a callback. Logs a warning because this can cause race conditions with the async MSSQL driver.

pool (getter)

Returns the underlying mssql connection pool for direct query access.

MSSQL (getter)

Returns the mssql library module for direct access to types, prepared statements, and other driver features.

preparedStatement (getter)

Creates and returns a new mssql.PreparedStatement bound to the active connection pool. Throws an error if the pool is not connected.

connected (property)

Boolean indicating whether the connection pool is open.

generateCreateTableStatement(pMeadowTableSchema)

Generate a CREATE TABLE SQL statement from a Meadow table schema object. Tables are created in the [dbo] schema with bracketed column names.

| 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. Silently succeeds if the table already exists.

createTables(pMeadowSchema, fCallback)

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

generateDropTableStatement(pTableName)

Generate a safe DROP TABLE statement using IF OBJECT_ID to check existence before dropping.

Column Type Mapping

| Meadow Type | MSSQL Column | |-------------|--------------| | ID | INT NOT NULL IDENTITY PRIMARY KEY | | GUID | VARCHAR(254) with default GUID | | ForeignKey | INT UNSIGNED NOT NULL DEFAULT 0 | | Numeric | INT NOT NULL DEFAULT 0 | | Decimal | DECIMAL(size) | | String | VARCHAR(size) DEFAULT '' | | Text | TEXT | | DateTime | DATETIME | | Boolean | TINYINT DEFAULT 0 |

Part of the Retold Framework

Meadow Connection MSSQL 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.