Socket
Book a DemoInstallSign in
Socket

db-client-smacondi

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

db-client-smacondi

A Node client for managing database connections and account-based cluster routing, designed for MongoDB

latest
npmnpm
Version
1.1.0
Version published
Maintainers
1
Created
Source

db-client-smacondi

A Node.js client for managing database connections and account-based cluster routing, designed for MongoDB.

Installation

npm install db-client-smacondi

Usage

ES Modules (ESM)


// import named exports
import { getDbClientSmacondi, closeAllDbClients } from 'db-client-smacondi';

// Using the singleton pattern (recommended)
const dbClientSmacondi = getDbClientSmacondi(connectionStringMap, apiURL, readTimeout, writeTimeout);
// load dbClient for an account (async):
const { dbClient, dbName, _id } = await dbClientSmacondi.getDbClientByAccountId('someAccountId')
// or load a dbClient by providing a clusterId (sync)
const clusterDbClient = dbClientSmacondi.getDbClientByClusterId('someClusterId')

// Close all database connections when needed
await closeAllDbClients();

CommonJS


// import named exports
const { getDbClientSmacondi, closeAllDbClients } = require('db-client-smacondi');

// Using the singleton pattern (recommended)
const dbClientSmacondi = getDbClientSmacondi(connectionStringMap, apiURL, readTimeout, writeTimeout);
// load dbClient for an account (async):
const { dbClient, dbName, _id } = await dbClientSmacondi.getDbClientByAccountId('someAccountId')
// or load a dbClient by providing a clusterId (sync)
const clusterDbClient = dbClientSmacondi.getDbClientByClusterId('someClusterId')

// Close all database connections when needed
await closeAllDbClients();

API Reference

getDbClientSmacondi(connectionStringMap, apiURL, readTimeout, writeTimeout)

function that returns a singleton instance of the DbClientSmacondi class.

  • connectionStringMap {Object<string, string>}: Object where key is the clusterId and value is the connection string for the cluster.
  • apiURL {string} (optional): URL of the account API to get account details. Default: 'localhost:5000'.
  • readTimeout {number} (optional): Read timeout in milliseconds. Default: 30000.
  • writeTimeout {number} (optional): Write timeout in milliseconds. Default: 30000.

Returns: {DbClientSmacondi} - The DbClientSmacondi singleton instance.

closeAllDbClients()

Closes all active database client connections.

Returns: {Promise<void>}

DbClient

Low-level class for direct MongoDB client management.

Constructor: new DbClient(connectionString, readTimeout, writeTimeout)

  • connectionString {string}: MongoDB connection string.
  • readTimeout {number} (optional): Read timeout in milliseconds. Default: 30000.
  • writeTimeout {number} (optional): Write timeout in milliseconds. Default: 30000.

Features

  • Singleton pattern for efficient database connection management
  • Account-based routing for MongoDB connections
  • Connection string mapping for different database clusters
  • Automatic connection pooling and management
  • Configurable read and write timeouts
  • Built-in logging with Winston
  • Support for both ESM and CommonJS import patterns

Example

import { getDbClientSmacondi } from 'db-client-smacondi';

// Configure your cluster connection strings
const connectionStringMap = {
  'cluster1': 'mongodb://user:pass@host1:port/db',
  'cluster2': 'mongodb://user:pass@host2:port/db',
};

// Initialize the client
const dbClientSmacondi = getDbClientSmacondi(connectionStringMap, 'https://api.example.com/accountInfo', 30000, 30000);

// Use the client in your application
async function main() {
  try {
    // Get a database client for a specific account
    const { dbClient, dbName, _id } = await dbClientSmacondi.getDbClientForAccount('demo_account');
    
    // Perform database operations
    const collection = await dbClient.find(dbName, 'collection_a', {});
    
    console.log(result);
  } catch (error) {
    console.error('Error:', error);
  } finally {
    // Close all connections when your app is shutting down
    await closeAllDbClients();
  }
}

License

This package is licensed under the AGPL-3.0-or-later license.

FAQs

Package last updated on 09 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.