Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

MySQL adapter for JugglingDB

NotificationsYou must be signed in to change notification settings

ineo4j/mysql-adapter

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MySQL adapter for JugglingDB.

Usage

To use it you needjugglingdb@0.2.x.

  1. Setup dependencies inpackage.json:

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

    varSchema=require('jugglingdb').Schema;varschema=newSchema('mysql',{database:'myapp_test',username:'root'});

    You can optionally pass a few additional parameters supported bynode-mysql, most particularlypassword andcollation.Collation currently defaults toutf8mb4_general_ci. Thecollation value will also be used to derive the connection charset.

Running tests

npm test

Using thedataType field/column option with MySQL

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

The following type-dataType combinations are supported:

  • Number

    *
    integer
    * tinyint * smallint * mediumint * int * bigint

    Use thelimit option to alter the display width.

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

    • floating point types
      * float * double

      Use theprecision andscale options to specify custom precision. Default is (16,8).

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

    • fixed-point exact value types
      * decimal * numeric

      Use theprecision andscale 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 }}

  • String / Schema.Text / Schema.JSON

    * varchar* char* text* mediumtext* tinytext* longtext

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

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

  • Date

    * datetime* timestamp

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

  • Enum

    Enums are special.Create an Enum using Enum factory:
    varMOOD=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 anor array object to the where clause to join the arguments in theor 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 theor 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 theattributes 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 setpool 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. Iftrue, the pool will queue the connection request and call it when one becomes available. Iffalse, 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 fromgetConnection. If set to0, 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 theindexes option in the 3rd argument todefine.

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 ChakkaevPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, 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 INTHE SOFTWARE.

About

MySQL adapter for JugglingDB

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript87.0%
  • CoffeeScript12.6%
  • Makefile0.4%

[8]ページ先頭

©2009-2025 Movatter.jp