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

eznodemysql

v1.0.17

Published

async, easy and fast mysql requests

Downloads

20

Readme

Easy MySQL requests

Promise based, easy and fast methods for MySQL requests.

npm install --save eznodemysql

Usage

const SQL = new (require('eznodemysql'));

// Wait for connecting
await SQL.connect(host, port, user, password, database_name);

// Fast syntax
let all_rows = await SQL.get('table_name');
let one_row = await SQL.get('table_name', "name=? AND id>?", ['unesca"pe%d param', 5]);

// Raw requests
let custom_one_row = await SQL.one("SELECT * FROM users WHERE name=?", ['unesca"ped param']);
let custom_all_rows = await SQL.all("SELECT * FROM users WHERE id>?", [5]);

Bulk insert and update

All rows insert or update in one query, thats extremly fast. Method accepts array of rows to insert or update. Main feature: you can set unique\primary column like a id and row will be updated instead of insert. Also, you can write update condition in last parameter

let rows = [
    {
        name: 'Bob',
        sex: 1
    },
    {
        name: 'Kate',
        sex: 2,
        // That field will be serialized
        categories: [
            'cats lover',
            'hello kitty'
        ]
    },
    // That will be updated, instead of insert, if id=177 exists, cause 'id' is unique field
    // Missed field 'categories' will be filled by default mysql value
    {
        id: 177,
        name: 'Potter',
        sex: 1
    },
];

// Insert all non-unique rows, and update other only if column sex=1
await SQL.BulkUpdate('table_name', rows, ['not_update_these_field'], 'sex=1']);

// or just
await SQL.BulkUpdate('table_name', rows);

That is very convenient, if you get columns add or update some in array and save again:

let rows = await SQL.selectAll('users');

rows[177].name = 'Harry Potter';
rows.push({name: 'Adam', sex: 1});

await SQL.BulkUpdate('users', rows);

One row will be inserted and one will be updated. Missed columns fill with default (mysql) values.

Good practice is use unique fields in mysql

BULK REQUEST

BulkUpdate generate the request:

INSERT IGNORE INTO table(columns...) VALUES (row1col1,row1col2, ...), (row2col1,row2col2,...) ON DUPLICATE KEY UPDATE updated_field=IF(update_condition, value, old_value), ...
  • with default values for missed columns
  • with serialization for objects

License

MIT