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 🙏

© 2024 – Pkg Stats / Ryan Hefner

sqlexecutor

v0.0.7

Published

sqlexecutor is a lightweight and flexible Node-js library for executing MYSql queries with ease and handle results asynchronously. The library provides a simple and intuitive interface for interacting with your database, allowing you to focus on building

Downloads

11

Readme

SQL Executor

SQL Executor is a lightweight library for executing mySQL queries in Node.js applications, it focuses on optimizing queries and prevent overhead issues, sqlExecutor also provides out of the box configuration yet giving you the opportunity to customize your own options.

Installation

You can install SQL Executor via npm:

npm install sqlexecutor

or

yarn add sqlexecutor

Usage

To use SQL Executor in your Node.js application, first require it in your file:

const Executor = require("sqlexecutor");

Then, create an instance of Executor with your database configuration:

const executor = new Executor({
  host: "localhost",
  user: "root",
  password: "",
  database: "my_database",
});

Note: There are default parameters set for you, see - Table ,You only need to set the ones you need to change.

Then create an executor by calling the worker

const executor = worker.call;

You can then execute SQL queries using the executor instance:

executor("SELECT * FROM table_name")
  .then((results) => {
    console.log(results);
  })
  .catch((error) => {
    console.error(error);
  });

Or

You can instantiate it directly by adding .call to the Executor()

const Executor = require("sqlexecutor");

const executor = new Executor({
  host: "localhost",
  user: "root",
  password: "",
  database: "my_database",
}).call;

executor("SELECT * FROM table_name")
  .then((results) => {
    console.log(results);
  })
  .catch((error) => {
    console.error(error);
  });

Alternatively, you can use the executeQuery method directly:

const Executor = require("sqlexecutor");

const worker = new Executor({
  host: "localhost",
  user: "root",
  password: "",
  database: "my_database",
});

worker
  .executeQuery("SELECT * FROM table_name")
  .then((results) => {
    console.log(results);
  })
  .catch((error) => {
    console.error(error);
  });

There is no difference between executor and worker.executeQuery , it totally depends on preference.

API for bundle pooling

sqlexecutor ideally use a single connection pooling lifecycle to handle queries but you can choose to override that by calling

const bundle = worker.bundle;

then

bundle("SELECT * FROM table_name")
  .then((results) => {
    console.log(results);
  })
  .catch((error) => {
    console.error(error);
  });

executor(query, params)

Executes a SQL query with optional parameters.

  • query: String - SQL query string.
  • params: Array (optional) - Query parameters.

Returns a Promise that resolves with the query results.

SQL injection security

SQLExecutor enhances security by safeguarding against SQL injection attacks through the use of placeholders (?).


executor('SELECT * FROM table_name where email = ?',[[email protected]])
    .then(results => {
        console.log(results);
    })
    .catch(error => {
        console.error(error);
    });

Table

This is the default parameters table, You only need to add parameters that differs from the dafault that you might want to use.

| Parameters | Default | | ------------------ | ------------ | | host | "localhost" | | user | "root" | | password | empty string | | database | "my_database | | waitForConnections | true | | connectionLimit | 20 | | queueLimit | 0 | | timezone | "local" | | charset | "utf8mb4" | | port | 3306 |

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

For donations and collaboration , you can get to me through email