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 🙏

© 2025 – Pkg Stats / Ryan Hefner

multi-db-connector

v1.0.20

Published

A robust npm module for managing multiple database connections (Snowflake, Neo4j, PostgreSQL, MySQL) and executing queries in parallel

Readme

Multi-Database Connector (TypeScript)

A robust TypeScript npm module for managing multiple database connections (Snowflake, Neo4j, PostgreSQL, MySQL) and executing queries in parallel.

Features

  • TypeScript Support: Fully typed with comprehensive type definitions
  • 🔄 Multiple Database Support: Snowflake, Neo4j, PostgreSQL, MySQL
  • Parallel Query Execution: Execute queries across multiple databases simultaneously
  • 🔌 Connection Pooling: Efficient connection management for each database type
  • 🔁 Automatic Retry: Built-in retry mechanism for failed queries
  • 🛡️ Type Safety: Full TypeScript support with interfaces and type checking
  • 📦 Easy to Use: Simple, intuitive API

Installation

npm install multi-db-connector

TypeScript Development Workflow

  • For hot-reloading during development, use:

    npm run dev

    This uses nodemon and ts-node to watch and reload .ts files automatically.

  • To build the project:

    npm run build
  • To run the compiled server:

    npm run start

Troubleshooting

  • Unknown file extension ".ts": Make sure you are using ts-node for development, not node directly on .ts files.
  • ReferenceError: Cannot access 'dotenv' before initialization: Ensure all import statements are at the top of your .ts files before any code execution.
  • TypeError: MultiDatabaseQueryManager is not a constructor: Use the correct import syntax:
    import { MultiDatabaseQueryManager } from 'multi-db-connector';

TypeScript Usage

Basic Example

import { MultiDatabaseQueryManager } from 'multi-db-connector';

const manager = new MultiDatabaseQueryManager();

// Add connections
await manager.addConnection('snowflake', 'snowflake', {
  account: 'your-account',
  username: 'your-username',
  password: 'your-password',
  warehouse: 'COMPUTE_WH',
  database: 'ANALYTICS',
  schema: 'PUBLIC'
});

await manager.addConnection('graph', 'neo4j', {
  uri: 'neo4j://localhost:7687',
  username: 'neo4j',
  password: 'password'
});

// Execute queries
const results = await manager.executeQuery('snowflake', 
  'SELECT * FROM customers LIMIT 10'
);

console.log(results);

// Close connections
await manager.closeAllConnections();

Type Definitions

The package includes comprehensive TypeScript type definitions:

import { 
  MultiDatabaseQueryManager,
  DatabaseType,
  DatabaseCredentials,
  QueryRequest,
  QueryResult,
  SnowflakeCredentials,
  Neo4jCredentials,
  PostgreSQLCredentials,
  MySQLCredentials
} from 'multi-db-connector';

Supported Databases

Snowflake

import { SnowflakeCredentials } from 'multi-db-connector';

const credentials: SnowflakeCredentials = {
  account: 'your-account',
  username: 'your-username',
  password: 'your-password',
  warehouse: 'COMPUTE_WH',
  database: 'ANALYTICS',
  schema: 'PUBLIC',
  role: 'ANALYST' // optional
};

await manager.addConnection('snowflake', 'snowflake', credentials);

Neo4j

import { Neo4jCredentials } from 'multi-db-connector';

const credentials: Neo4jCredentials = {
  uri: 'neo4j://localhost:7687',
  username: 'neo4j',
  password: 'password',
  database: 'neo4j', // optional
  maxPoolSize: 50, // optional
  connectionTimeout: 30000 // optional
};

await manager.addConnection('graph', 'neo4j', credentials);

PostgreSQL

import { PostgreSQLCredentials } from 'multi-db-connector';

const credentials: PostgreSQLCredentials = {
  host: 'localhost',
  port: 5432, // optional, defaults to 5432
  database: 'mydb',
  user: 'postgres',
  password: 'password',
  maxConnections: 20, // optional
  idleTimeout: 30000, // optional
  connectionTimeout: 10000 // optional
};

await manager.addConnection('postgres', 'postgresql', credentials);

MySQL

import { MySQLCredentials } from 'multi-db-connector';

const credentials: MySQLCredentials = {
  host: 'localhost',
  port: 3306, // optional, defaults to 3306
  database: 'mydb',
  user: 'root',
  password: 'password',
  maxConnections: 10 // optional
};

await manager.addConnection('mysql', 'mysql', credentials);

API Reference

MultiDatabaseQueryManager

Methods

addConnection(connectionId: string, type: DatabaseType, credentials: DatabaseCredentials): Promise<void>

Add a new database connection.

executeQuery(connectionId: string, query: string, params?: any[]): Promise<any[]>

Execute a single query on a specific connection.

executeQueriesParallel(connectionId: string, queries: (string | QueryObject)[]): Promise<QueryResult[]>

Execute multiple queries in parallel on the same connection.

executeMultiConnectionQueries(queryRequests: QueryRequest[]): Promise<QueryResult[]>

Execute queries across multiple connections in parallel.

executeQueryWithRetry(connectionId: string, query: string, params?: any[], maxRetries?: number): Promise<any[]>

Execute a query with automatic retry on failure.

getConnectionInfo(connectionId: string): ConnectionInfo | null

Get information about a specific connection.

listConnections(): string[]

List all active connection IDs.

closeConnection(connectionId: string): Promise<void>

Close a specific connection.

closeAllConnections(): Promise<void>

Close all connections.

getActiveQueryCount(): number

Get count of active queries.

getSupportedDatabases(): string[]

Get list of supported database types.

Development

Building from Source

# Install dependencies
npm install

# Build TypeScript
npm run build

# Watch mode
npm run build:watch

# Run tests
npm test

# Clean build artifacts
npm run clean

Project Structure

multi-db-connector/
├── adapters/
│   ├── BaseAdapter.ts          # Abstract base adapter class
│   ├── SnowflakeAdapter.ts     # Snowflake implementation
│   ├── Neo4jAdapter.ts         # Neo4j implementation
│   ├── PostgreSQLAdapter.ts    # PostgreSQL implementation
│   └── MySQLAdapter.ts         # MySQL implementation
├── index.ts                     # Main entry point
├── examples.ts                  # Usage examples
├── test.ts                      # Test suite
├── tsconfig.json               # TypeScript configuration
└── package.json                # Package configuration

Examples

See the examples.ts file for comprehensive usage examples including:

  1. Basic usage with multiple database types
  2. Cross-database analytics
  3. Neo4j graph queries
  4. Multi-region Snowflake queries
  5. PostgreSQL + MySQL integration
  6. Error handling and retry mechanisms

TypeScript Configuration

The project uses strict TypeScript settings:

  • Strict null checks
  • No implicit any
  • Strict function types
  • No unused locals/parameters
  • Full type inference

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Changelog

v1.0.3 (TypeScript Conversion)

  • ✅ Converted entire codebase to TypeScript
  • ✅ Added comprehensive type definitions
  • ✅ Added type-safe interfaces for all database credentials
  • ✅ Improved IDE autocomplete and type checking
  • ✅ Added source maps for debugging
  • ✅ Added declaration files for npm package consumers

Publishing a New Version

To publish a new version of the package to npm:

# Clean previous build artifacts
npm run clean ; npm run build ; npm version patch ;npm publish