Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sequelize-pool

Package Overview
Dependencies
Maintainers
3
Versions
16
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.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
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

FAQs

Package last updated on 25 Jul 2022

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc