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 = ;var where = id: 1 path: 'images/3.jpg' $or: 'id|path';var sql = ;console; // 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 = ;var sql = Msql; // Then you can query according to pkconsole; // SELECT * FROM img where id = 1
Certainly, you can query without any config.
var sql = ;console; // SELECT * FROM img where id = 1
Create
Then you can see the demo referring to create a new record as follow.
var Msql = ;var data = path: 'path1' con: 'This is content';var sql = ;console; // 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 = ;var sql = Img; // specify the value of id, will update the record which id is 1console; // 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 = ;var sql = Img; // id = 1console; // DELETE FROM img where id = 1
And you can also delete it without any config.
var sql = Img; console; // DELETE FROM img where id = 1
Where
- eq
- neq
- neq
- gt
- egt
- lt
- elt
Img; // SELECT * FROM img where (id < 2)Img; // SELECT * FROM img where ((id > 1) OR (id <= 4))
- like
- in
Img; // SELECT * FROM img where (path like "con1") AND (id = 3)Img; // 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; // a list of fieldsconsole; // SELECT path FROM img where id = 1