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

jugglingdb-mysql

v0.2.3

Published

MySQL adapter for JugglingDB

Downloads

56

Readme

JugglingDB-MySQL Build Status

MySQL adapter for JugglingDB.

Usage

To use it you need [email protected].

  1. Setup dependencies in package.json:

    {
      ...
      "dependencies": {
        "jugglingdb": "0.2.x",
        "jugglingdb-mysql": "latest"
      },
      ...
    }
  2. Use:

    var Schema = require('jugglingdb').Schema;
    var schema = new Schema('mysql', {
        database: 'myapp_test',
        username: 'root'
    });

    You can optionally pass a few additional parameters supported by node-mysql, most particularly password and collation. Collation currently defaults to utf8mb4_general_ci. The collation value will also be used to derive the connection charset.

Running tests

npm test

Using the dataType field/column option with MySQL

The jugglingdb MySQL adapter now supports using the dataType column/property attribute to specify what MySQL column type is used for many jugglingdb types.

The following type-dataType combinations are supported:

  • Use the limit option to alter the display width.

    Example: { count : { type: Number, dataType: 'smallInt' }}

    • Use the precision and scale options to specify custom precision. Default is (16,8).

      Example: { average : { type: Number, dataType: 'float', precision: 20, scale: 4 }}

    • Use the precision and scale options to specify custom precision. Default is (9,2).

      These aren't likely to function as true fixed-point.

      Example: { stdDev : { type: Number, dataType: 'decimal', precision: 12, scale: 8 }}

  • Example: { userName : { type: String, dataType: 'char', limit: 24 }}

    Example: { biography : { type: String, dataType: 'longtext' }}

  • Example: { startTime : { type: Date, dataType: 'timestamp' }}

  • var MOOD = schema.EnumFactory('glad', 'sad', 'mad');
    MOOD.SAD;    // 'sad'
    MOOD(2);     // 'sad'
    MOOD('SAD'); // 'sad'
    MOOD('sad'); // 'sad'
    • { mood: { type: MOOD }}
    • { choice: { type: schema.EnumFactory('yes', 'no', 'maybe'), null: false }}

Using OR and IN operator

OR

Mysql adapter now supports the or functionality. You can add an or array object to the where clause to join the arguments in the or array with an OR.

Example: This example selects all the animals whose name are Penny AND type is either cat OR size is medium

where : {
    name : 'Penny',
    or : [ { type : 'cat'},
           { size : 'medium'}
    ]
}

It's important to note that each object in the or array is treat as if it was in the "where" clause, thus you can create complex queries like this;

Example: The example below selects all large white dogs OR all cats who are either small or black color

where : {
    or : [ { type : 'dog', color : 'white', size : 'large'},
           { type : 'cat', or : [ { size : 'small'},
                                  { color : 'black'}
                                ]
           }
    ]
}

SQL translation for the above would be:

WHERE (type = 'dog' AND color = 'white' AND size = 'large')
   OR (type = 'cat' AND (size = 'small' OR color = 'black'))

IN

IN operator is pretty straight forward. If you give any columns in the where clause an array, they will be interpreted to be an IN object

Example: The example below will look for items that have id 1, 4 or 6

where : {
    id : [1,4,6]
}

Select specific columns

In some cases, you may wish to select specific columns from the table, to do so simply use the attributes param.

###Examples:

returns array of column data(ex. ['1','2','3']

Model.all({where: {name: 'Bill'}, attributes: 'id'},cb)

returns array of object literals(ex. [{id:'1'}, {id:'2'}, {id:'3'}]

Model.all({where: {name: 'Bill'}, attributes: ['id']},cb)

returns array of object literals(ex. [{id:'1', age:'25'}, {id:'2', age:'56'}, {id:'3', age: '44'}]

Model.all({where: {name: 'Bill'}, attributes: ['id', 'age']},cb)

Connection Pooling

Mysql adapter uses the pooling provided by the node-mysql module. Simply set pool option to true in the connection settings.

Pool Options

Taken from node-mysql module

  • waitForConnections: Determines the pool's action when no connections are available and the limit has been reached. If true, the pool will queue the connection request and call it when one becomes available. If false, the pool will immediately call back with an error. (Default: true)
  • connectionLimit: The maximum number of connections to create at once.(Default: 10)
  • queueLimit: The maximum number of connection requests the pool will queue before returning an error from getConnection. If set to 0, there is no limit to the number of queued connection requests. (Default: 0)

Creating Multi-Column Indexes

The mysql adapter supports the declaration of multi-column indexes on models via the the indexes option in the 3rd argument to define.

UserData = db.define('UserData', {
        email: { type: String, null: false, index: true },
        name: String,
        bio: Schema.Text,
        birthDate: Date,
        pendingPeriod: Number,
        createdByAdmin: Boolean,
    } , { indexes: {
            index0: {
                columns: 'email, createdByAdmin'
            }
        }
    });

MIT License

Copyright (C) 2012 by Anatoliy Chakkaev

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.