🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

sequelize-pool

Package Overview
Dependencies
Maintainers
3
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sequelize-pool

Resource pooling for Node.JS

8.0.1
latest
Source
npm
Version published
Weekly downloads
2M
-2.14%
Maintainers
3
Weekly downloads
 
Created

What is sequelize-pool?

The sequelize-pool npm package is a standalone library for managing resource pools, such as database connections. It is designed to be used with Sequelize, a popular ORM for Node.js, but can also be used independently. The package provides a robust and efficient way to manage and reuse resources, ensuring optimal performance and resource utilization.

What are sequelize-pool's main functionalities?

Creating a Pool

This code demonstrates how to create a new resource pool using sequelize-pool. The pool is configured with a name, create and destroy functions for managing resources, and parameters for maximum and minimum resources, as well as idle timeout.

const Pool = require('sequelize-pool').Pool;
const pool = new Pool({
  name: 'my-pool',
  create: function() {
    return new Promise((resolve) => {
      resolve({}); // Simulate resource creation
    });
  },
  destroy: function(resource) {
    return new Promise((resolve) => {
      resolve(); // Simulate resource destruction
    });
  },
  max: 10,
  min: 2,
  idle: 10000
});

Acquiring a Resource

This code demonstrates how to acquire a resource from the pool. Once the resource is acquired, it can be used for various operations. After usage, the resource is released back to the pool.

pool.acquire().then((resource) => {
  console.log('Resource acquired:', resource);
  // Use the resource
  pool.release(resource);
});

Releasing a Resource

This code demonstrates how to release a resource back to the pool after it has been used. Releasing resources ensures they can be reused, optimizing resource management.

pool.acquire().then((resource) => {
  console.log('Resource acquired:', resource);
  // Use the resource
  pool.release(resource).then(() => {
    console.log('Resource released');
  });
});

Draining the Pool

This code demonstrates how to drain the pool, which means no new resources will be created. After draining, all existing resources are destroyed. This is useful for gracefully shutting down applications.

pool.drain().then(() => {
  console.log('Pool drained');
  return pool.destroyAllNow();
}).then(() => {
  console.log('All resources destroyed');
});

Other packages similar to sequelize-pool

Keywords

pool

FAQs

Package last updated on 28 Mar 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