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

myjql

v1.0.3

Published

MyJQL =============

Downloads

10

Readme

MyJQL

A library to simplify the usage of mysql module by chainning differents methods to construct a query and then execute it.

We provide the CRUD utils functions: SELECT, INSERT, UPDATE and DELETE.

Installation

To use with node:

$ npm install --save myjql

Usage

...
const myjql = require('myjql');
...

Connecting to MySQL Database

...
myjql.connect({    // Return object same as `createConnection` 
                    // of the module `mysql`
                    // You can work with as you are working `mysql`
                    // Same as `createConnection`
        "host"      :   "localhost", 
        "user"      :   "root", 
        "password"  :   "root", 
        "database"  :   "randomDB"
    });
...

SELECT Query

...
let selectFromQuery = myjql.Query
    .select('colA, colB')       // String of cols with `,` between each col
 // .select(['colA', 'colB'])   // Or an Array that contains different cols
    .from('tableA')             // Table as string (Only string is supported)
    .where()
        .attr('age')
            .gte(25)
//  .where()
//      .attr('age')
//          .gt(25)
//  .where()
//      .attr('age')
//          .lte(25)
//  .where()
//      .attr('age')
//          .lt(25)
//  .where()
//      .attr('age')
//          .equals(25)
    .and()
        .attr('name')
            .like('%somename')
    .and()
        .attr("something")
            .eq()               // If nothing given, it replace it by '?'
    .exec(["18"]);              // Data given in order to replace the '?' value
                                // in the same order of the 'attr'
...

INSERT Query

...
let insertIntoQuery = myjql.Query
    .insert('tableA')                   // Table as string (Only string is supported)
        .cols('colA, colB, colC')       // String of cols with `,` between each col
//      .cols(['colA', 'colB', 'colC']) // Or an Array that contains different cols
        .values([                       // Array of string
            '\'Value1\', \'Something\', 25', 
            '\'Value2\', \'Something\', 25', 
            '\'Value3\', \'Something\', 25', 
        ])
        .exec();
...

UPDATE Query

...
let updateQuery = myjql.Query
    .update('tableA')                           // Table as string (Only string is supported)
        .set('onlyOneColName', 'theNewValue')   // Set the col and its value
                                                // If a string given in 1st arg, 
                                                // then the second arg its value is '?'
//      .set([                                  // If a lot values must be changed,
//          { column: 'colA', value: 'NewValue' }
//          { column: 'colB', value: 25 }
//          { column: 'colC', value: true }
//      ])                                      // you can give like this
        .where()                                // You can also chain it with where
            .attr('colId')
                .equal(25)
        .exec();
...

DELETE Query

...
let deleteFromQuery = myjql.Query
    .delete('tableName')                        // Table as string (Only string is supported)
    .where()
        .attr('idColumn')
            .equal(20);
    .exec();
// Or
deleteFromQuery = myjql.Query
    .delete()
        .from('tableName')
    .where()
        .attr('idColumn')
            .equal(20);
    .exec();
...

From Query To String

...
// If you want to get the query string
let query = myjql.Query
    .select("*")
        .from("tableName");
query.toString();   // 'SELECT * FROM tableName'
...

Create an Query Object from my own query String

...
// If you have your own query string
let ownQuery = myjql.Query.of("...");

Security issues

Security issues should be reported through GitHub by opening a GitHub issue simply asking or by emailing the module's author/contributors.

An ideal report would include a clear indication of what the security issue is and how it would be exploited.

Contributing

This project welcomes contributions from the community. Contributions are accepted using GitHub pull requests. If you're not familiar with making GitHub pull requests, please refer to the GitHub documentation "Creating a pull request".