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

smart-mysql

v0.9.19

Published

Interact with MySQL Using NoSQL Commands

Downloads

43

Readme

Smart MySQL smart-mysql made to build queries by hand waste your time.

So let's build it with JavaScript.

How to Install

$ npm install smart-mysql

How to connect

Let’s connect with smart_mysql class with calling class name. You can make a new object of smart_mysql class as we have done here .

host, user , password , charset , database is required .

var smart_mysql = require('smart-mysql');

var db = new smart_mysql({
    host: 'localhost',
    user: 'root',
    password: '',
    charset: 'utf8_unicode_ci',
    database: 'avl'
}, false);

Specify your table

It’s easy to define which table you wants to work with. You can specify your table name as we have done below.

db.collection('table_name');

Inserting Rows

We'll show you, That's simple to insert some records.

db.collection('user').insert({a: 1});
db.collection('user').insert({a:1, b:2});

Or you can insert many rows in a command.

db.collection('user').Insert({[{a:1}, {a:2}, {a:3}], b:1});

You can use callback () function.

db.collection('user').Insert({a:1}, function(count){
    console.log('Number of inserted rows : ' + count);
});

What does callback () function do ? You can retrieve results of your action with this class. We show you how to.

db.collection('user').insert({a:1}, function(done) {
    if (done) {
        console.log ("done!");
    };
});

Updating Rows

Update your table simply. This line update all of your rows without any condition. Use put new data in first parameter. Next line will update all of your culomns named a.

db.collection('user').Update({a: "your data"}, function(done){
    if (done) {
        console.log ("done!");
    };
});

This sql query happen for last command:

Update tbl set a: "your data"

And you can chose condition if you want to, Put it in second parameter.

db.collection('user').Update({a:"your data"}, {a:"my data"} , function(done){
    if (done) {
        console.log ("done!");
    };
});

In last line this query string will happen.

Update tbl set a : "your data" where a : "my data"

Delete a Row

It’s simple to delete a row from table with that condition you want or Without any condition as we have done below.

db.collection('user').delete({id:5}, function(done){
    if (done) {
        console.log ("done!");
    };
});

Last command return this query string:

Delete * from tablename where id = 5

Or in other way we can use an array in condition.

db.collection('user').delete({id:[5, 7, 10, 14, 17]}, function(done){
    if (done) {
        console.log ("done!");
    };
});

Selecting Rows

There is three way to use select function

  1. table
  2. record
  3. field
  1. In table function you will take all of rows that you want to be. You can use this parameters for table function.

db. Table ( field, filter, order, group, limit, page, callback ) Field can be a string or an array. db.table("id") OR db.table(["id", "name"]) OR db.table(false) FALSE will return * or all rows in select You can set condition in second parameter for select

db.collection('user').table(["id","username"], {id:1}, function(data){
    // Process the result data
});

OR use array condition

db.collection('user').table([{id:1}, {age:25}], function(data){
    // Process the result data
 });

In next parameter you can use ORDER in next parameter to condition; order can be an array or a string

db.collection('user').table(false, [{id : 1}, {age: 25}], "id desc", function(data){
    // Process the result data
});

Or use an array for order

db.collection('user').table(["id", "name"], [{id: 1}, {age: 25], ["id desc", "name asc"], function(data){
    // Process the result data
});

Record

  1. in record function you take only one row of table as we have done below. You can use this function like table function. But different is this function fetch first row.

record(field, filter, order, callback);

db.collection('user').record(["id", "name"], {id: 5}, (rec)=>{console.log(rec);});

  1. field function only return first field of that row we fetch db.field ( [ "name" ] , { id : 5 } );

Last command return this query, string. Select name from tablename where id=5, First parameter is that field we want get and second parameter Is our condition.