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

dbexecutors

v1.7.3

Published

Simplify database operations

Readme

Introduction

What is this?

Database manipulations can be very boring, you need to create a connection, do CRUD by sending commands to database server, close connection, re-establish the broken connection... And with Node.js, you also need to listen to those network events and deal with a lot of callbacks.

A connection pool could make it easier, but most Node.js connection pool packages didn't give us the async/await interface, and you still need to release the connection after you use it. Sometimes I just want a function that helps me execute a sql string, or a redis command. I don't want to care about the network connection stuffs, or listen to any network events.

With this package, you don't need to do those boring things anymore, dbexecutors give you a simple Promise-based interface, and do all those necessary things underground.

Basic Usage

For example, with MysqlExecutor, you just need to create a executor first(tell it which server to connect):

const executor = dbexecutors.getMysqlExecutor({
  host: "localhost",
  port: 3306,
  password: "asdf",
  //...
})

Then you can use it like this:

(async function() {

//...
await executor.insert("t1", { name: "x", age: 6, gender: 1 })
// You can also write:
await executor.execute('INSERT INTO t1(name, age) VALUES("x", 6)')

//...
const r = await executor.select("t1", { name: "x" })
//...


})().catch(console.error)

RedisExecutor works the same way.

const executor = dbexecutors.getRedisExecutor({
  host: "localhost",
  port: 6379,
  password: "asdf",
})
(async function() {

//...
await executor.execute([ "set", "test_string", "hello, redisexecutor" ])
//...
const r = await executor.execute([ "get", "test_string" ])
//...


})().catch(console.error)

Transaction

For redis, you don't need transaction, you can and should use redis script instead. These are some contents you can find in https://redis.io/topics/transactions

A Redis script is transactional by definition, so everything you can do with a Redis transaction, you can also do with a script, and usually the script will be both simpler and faster.

Actually Redis may remove transaction in the future and use redis script only.

However it is not impossible that in a non immediate future we'll see that the whole user base is just using scripts. If this happens we may deprecate and finally remove transactions.

For mysql, you do need transaction. In this case, you need to get connection from the connection pool and release it after you finishing your query.

(async function() {

const conn = await executor.getConnection()

await conn.transactionStart()

try {
  await conn.execute(`update t1 set age=26 where name="A"`)
  await conn.execute(`update t1 set age=27 where name="B"`)
  await conn.transactionCommit()
} catch (e) {
  await conn.transactionRollback()
}

conn.release()

})().catch(console.error)