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

sql-easy

v1.0.8

Published

Promise syntax sugar for mysql.js. Simple grammar rules and await async are also available.

Downloads

3

Readme

sql-easy

Promise syntax sugar for mysql.js. Simple grammar rules and await async are also available.

Table of Contents

  • Install
  • Introduction
  • Document
  • Contributors
  • Todo

Install

This is a npm module available through npm registry. Before installing, make sure you have installed Node.js 8.0 or higher. You can install it by npm install command:

npm install sql-easy

Introduction

The module provide a more easy way for JavaScript developers to operate the mysql database. Here is an example on how to query all data from a table of mysql database:

const Sql = require('sql-easy');

let sl = new Sql({
  host     : 'localhost',
  user     : 'username',
  password : 'password',
  database : 'demo',
  table    : 'info'
})

const OperateObject = {};

sl.query(OperateObject).then(res => {
  //get the query result here
  console.log(res);
}).catch(err => {
  //catch the error here
  console.log(err);
})

Document

Connection

It is easy to connect your mysql Database. Just create a sql-easy instance and pass a object as a configuation option. The option is as same as mysql.js's configuation option.

let sl = new Sql({
  host     : 'localhost',
  user     : 'username',
  password : 'password',
  database : 'demo',
  table    : 'info'
})
  • host*: The hostname of the database you are connecting to.
  • user*: The username of the database.
  • password*: Password of the database.
  • database*: The name of the database.
  • table: The table you want to operate, you can also change it in OperateObject.

Methods

Query

Query all data ot the table

  sl.query().then(res => {
    let result = res.data;
    let status = res.status. 
  }).catch(err => {})

Query data with conditions in some fields

  sl.query({
    fields: ['id', 'title', 'date'],
    conditions: `id>10 && name='kitty' || title='订阅号'`
  }).then(res => {
    cosole.log(res.data);
  }).catch(err => {})

Query data of other tables

  sl.query({
    table: 'othertable'
  }).then(res = {}).catch(err => {});

Insert

Insert data into database

  sl.insert({
    fields: ['id', 'title', 'name'],
    data: [
      [2, '标题', 'kitty'],
      [52, '任务', 'peter'],
      [10, '测试', 'marry']
    ]
  }).then(res => {}).catch(err => {})

Update

Update data with conditions in some fields

  sl.update({
    fields: ['id', 'title', 'name'],
    data: ['2', '标题', 'kitty'],
    conditions: `id>10 && name='kitty' || title='订阅号'`
  }).then(res => {}).catch(err => {})

Delete

Delete some lines with conditions

  sl.delete({
    conditions: `id>10 && name='kitty' || title='订阅号'`
  }).then(res => {}).catch(err => {})

OperateObject

Core of the sql-easy is the OperateObject. Here are all attributes of the Object.

fields (Array)

Fields of the database you want to operate. It must be provided in Insert and Update operation. Follow is an example:

  {
    fields: ['name', 'id', 'title', 'date']
  }

data (Array)

The data you want to Insert or Update.

Update one line data

  {
    data: ['kitty', '12', '问题研究所', '20180521']
  }

Insert more line data

  {
    data: [
      ['kitty', '52', '网红爆款', '20140212'],
      ['kathy', '21', '命名空间', '20140212'],
      ['peter', '12', '暂时有空', '20140212'],
    ]
  }

conditions (String)

The conditions in WHERE case, it is not necessary in all operations. You can use it very easily because it is similar to javascript syntax.

  {
    conditions: `id>5 && name='kathy' || title='暂时有空'`
  }

table (String)

Tablename of the database you want to operate. It can cover you configuation option.

Contributors

Most of work has been done by mysql.js. Thanks goes to the people who have contributed code to this module.

Todo

  • Add more database statement support.
  • ...