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

mysql-dbo

v3.0.0

Published

Simple MySQL DBO for node

Downloads

4

Readme

mysql-dbo

Simple MySQL Database Object for node

Installation

npm install --save mysql-dbo

Description

99% of the time we just need to Insert/Update something easily or select the first row of a set.

This package provides exactly that and no more.

Reference

connect(callback?:Function)

close()

query(query:String, callback?:Function)

select(query:String, key?:String, firstOnly?:Boolean, callback?:Function)

insert(table:String, data:Object|Array.<Object>, columns?:Array<String>, ignore:Boolean, callback?:Function)

update(table:String, data:Object|Array.<Object>, columns?:Array<String>, where:String|Object, callback?:Function)

delete(table:String, where:String|Object, callback?:Function)

getById(table:String, id:Number, callback?:Function)

escape(string:String)

getInsertId(result:Object)

getAffectedRows(result:Object)

Usage

'use strict';

const MySQL = require('mysql-dbo');


let dbo = new MySQL({
    host: 'localhost',
    port: 3306,
    database: 'test',
    user: 'root',
    password: ''
});


// Misc query
dbo.query('SHOW CREATE TABLE users', (error, result) => {
    console.log('Test 1:', error, result);
});


// Normal select
dbo.select('SELECT * FROM users LIMIT 10', (error, users) => {
    console.log('Test 2:', error, users);
});

// Return an object with the id column as key
dbo.select('SELECT * FROM users LIMIT 10', 'id', (error, users) => {
    console.log('Test 3:', error, users);
});

// Select first row of the result
dbo.select('SELECT * FROM users LIMIT 1', true, (error, user) => {
    console.log('Test 4:', error, user);
});


// Insert one row
dbo.insert('users', {name: 'test1', email: '[email protected]'}, (error, insertId) => {
    console.log('Test 5:', error, insertId);
});

// Insert many
dbo.insert('users', [
    {name: 'test2', email: '[email protected]'},
    {name: 'test3', email: '[email protected]'}
], (error, insertId) => {
    console.log('Test 6:', error, insertId);
});

// Insert one row with explicit columns
dbo.insert('users', {skip: Math.random(), name: 'test4', email: '[email protected]'}, ['name', 'email'], (error, insertId) => {
    console.log('Test 7:', error, insertId);
});

// Insert many with explicit columns
dbo.insert('users', [
    {skip: Math.random(), name: 'test5', email: '[email protected]'},
    {skip: Math.random(), name: 'test6', email: '[email protected]'}
], ['name', 'email'], (error, insertId) => {
    console.log('Test 8:', error, insertId);
});

// Full insert
dbo.insert(
    'users', 
    [
        {random: Math.random(), name: 'test7', email: '[email protected]'},
        {random: Math.random(), name: 'test8', email: '[email protected]'}
    ],
    ['name', 'email'],
    false,
    (error, insertId) => {
        console.log('Test 9:', error, insertId);
    }
);

// Full insert IGNORE with explicit columns
dbo.insert(
    'users', 
    [
        {random: Math.random(), name: 'test9', email: '[email protected]'},
        {random: Math.random(), name: 'test10', email: '[email protected]'}
    ],
    ['name', 'email'],
    true,
    (error, insertId) => {
        console.log('Test 10:', error, insertId);
    }
);


// Update row
dbo.update('users', {name: 'test1111', email: '[email protected]'}, 'id = 1', (error, affectedRows) => {
    console.log('Test 11:', error, affectedRows);
});

// Update row with explicit columns
dbo.update('users', {skip: Math.random(), name: 'test5555', email: '[email protected]'}, ['name', 'email'], 'id = 5', (error, affectedRows) => {
    console.log('Test 13:', error, affectedRows);
});

// Update with object where (checked with = and joined with AND)
dbo.update(
    'users', 
    {random: Math.random(), name: 'test999', email: '[email protected]'},
    ['name', 'email'],
    {id: 9},
    (error, affectedRows) => {
        console.log('Test 16:', error, affectedRows);
    }
);


// Normal delete
dbo.delete('users', 'id = 10', (error, deletedRows) => {
    console.log('Test 17:', error, deletedRows);
});

// Delete with object where (checked with = and joined with AND)
dbo.delete('users', {id: 9}, (error, deletedRows) => {
    console.log('Test 18:', error, deletedRows);
});