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

sl-mysql-query-builder

v1.0.2

Published

simple mysql query maker

Downloads

6

Readme

sl-mysql-query-builder

simple javascirpt query maker for mysql.

support for complex condition of query.

Installation

npm install sl-mysql-query-builder

Quick Example

const MySQLQueryBuilder = require('sl-mysql-query-builder');

const builder = new MySQLQueryBuilder();

const condition = {
  'user_id': '123'	
}
let build = builder.table('MyTable').read().where(condition).order('meeting_date', 'DESC').paginate(3, 4).build();
console.log(build);
/*
 Equal to
 SELECT * FROM MyTable WHERE user_id = '123' ORDER BY meeting_date DESC LIMIT 3, 4;
*/

Available Query

  1. INSERT
  2. SELECT
  3. DELETE
  4. UPDATE
  5. WHERE
  6. JOIN
  7. ORDER
  8. PROCEDURE
  9. BULK INSERT
  10. GROUP BY

and will update more...

USAGE EXAMPLE

1. Expression Replace

const condition = {
  'meeting_date': {
    expression: '(:from_date <= meeting_date AND meeting_date <= :to_date)',
    value: {
      ":from_date": 8,
      ":to_date": 9
    } 
  }
};

2. Raw Condition Input

const obj = {
  'creation_date': new Date().getTime(),
  'user_id': '1234'
};
let history = {
  expression: `\`history\` = JSON_ARRAY_APPEND(history, "$", '${JSON.stringify(obj)}')`,
  value: {}
}

obj.history = history;
let build = builder9.table('SalesLogs').update(obj).where({'log_id': '6dc314af38c9be471f98a6044d6dc073'}).build();

3. UPDATE Object with condition

let obj = {
  'show_count': {
    'expression': 'show_count = show_count + 1',
    'value': {}
  }
};
let build = builder11.table('Board').update(obj).where({}).build();

4. Call Procedure

let build = builder10.procedure('UpdateLogHistory', '123').build();
console.log(build);

5. Bulk Insert

const dateTime = new Date().getTime();

let obj = {
  'log_id': ['a', 'b'],
  'user_id': ['1', '2'],
  'creation_date': [dateTime, dateTime]
};

let build = builder13.table('SalesLogs').insert(obj, true).build();

6. JOIN, LEFT JOIN, RIHGT JOIN ...

    let userId ='123';

    let build = builder7.table('UsersTree').read().where({'UsersTree.user_id': userId}).join('Users', {'Users.user_id': userId}).build();

7. Complex condition

In this case, user_id condition converts to user_id = '123' OR user_id = '456' (OR is default, you can change it to AND)

const condition = {
  'user_id': ['123', '456'],
  'meeting_date': {
    expression: '(:from_date <= meeting_date AND meeting_date <= :to_date)',
    value: {
      ":from_date": 8,
      ":to_date": 9
    } 
  }
};

let build = builder4.table('SalesLogs').read().where(condition).order('meeting_date', 'DESC').paginate(3, 4).build();

Test

run test with mocha

mocha test/query_builder.test.js