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

msql

v1.0.3

Published

This is a tool for making build sql easier.

Downloads

822

Readme

Msql

This is a tool for building sql without any stress.
With this tool, you can build a sql only by some paramters.
If you love this tool, I hope you can star me at my github ManitoYu.
I am a chinese college student, and I want to try my best to contribute my code to the code world. So I hope you can support me.

Select

There is a demo referring to select some records.

var Msql = require('msql');
var where = {
    id: 1,
    path: 'images/3.jpg',  
    $or: ['id|path']
};
var sql = Msql('img').where(where).select();
console.log(sql); // select * from img where id = 1 OR path = "images/3.jpg"

Find

If you want to find only one record by primary key, you can config as follows.

var Msql = Msql('img').config({
    pk: 'id' // assign the primary key
});
var sql = Msql.find(1); // Then you can query according to pk
console.log(sql); // SELECT * FROM img where id = 1

Certainly, you can query without any config.

var sql = Msql('img').find({ id: 1 });
console.log(sql); // SELECT * FROM img where id = 1

Create

Then you can see the demo referring to create a new record as follow.

var Msql = require('msql');
var data = {
    path: 'path1',
    con: 'This is content'
};
var sql = Msql('img').create(data);
console.log(sql); // INSERT INTO img(path, con) VALUES ("path1", "This is a new record")

Update

Once you set assign the primay key of table, you can update a record as follow.
Assumed that you will update a record which id is equal to 1, you can do it like this.

var Img = Msql('img').config({
    pk: 'id'
});
var sql = Img.update({ id: 1, path: 'path1' }); // specify the value of id, will update the record which id is 1
console.log(sql); // UPDATE img SET path = "path1" where id = 1

Delete

if you specify the primary key, you can delete a record only by giving the value of pk.

var Img = Msql('img').config({
    pk: 'id'
});
var sql = Img.delete(1); // id = 1
console.log(sql); // DELETE FROM img where id = 1

And you can also delete it without any config.

var sql = Img.delete({ id: 1 }); 
console.log(sql); // DELETE FROM img where id = 1

Where

  • eq
  • neq
  • neq
  • gt
  • egt
  • lt
  • elt
Img.where({ id: { $lt: 2 } }).select(); // SELECT * FROM img where (id < 2)
Img.where({ id: [{ $gt: 1 }, { elt: 4 }] }).select(); // SELECT * FROM img where ((id > 1) OR (id <= 4))
  • like
  • in
Img.where({ path: { $like: 'con1' }, id: 3 }).select(); // SELECT * FROM img where (path like "con1") AND (id = 3)
Img.where({ id: { $in: [1, 2, 3, 4] } }).select(); // SELECT * FROM img where (id in (1, 2, 3, 4))

Field

If you don't want to query all of fields, you can assign the several fields by yourself.

var sql = Msql.field(['path']).find({ id: 1 }); // a list of fields
console.log(sql); // SELECT path FROM img where id = 1