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

node-mariadb

v0.1.1

Published

A pure javascript client for mariadb

Downloads

16

Readme

node-mariadb

Node-mariadb is a pure javascript client for mariadb.
Some Drivers have compatibility with mysql.
Our goal is supporting almost functions and protocols of mariadb.

The latest version of node-mariadb supported only HandlerSocket Driver(ver 0.1.1).

Build Status NPM version

Supported protocols and functions.

  • HandlerSocket

Future (Not implemented yet)

  • Regular mysql protocol
  • Galera cluster
  • Non-blocking api client

Installation

Basic Sample of HandlerSocket Driver (Read).

var nodeMaria = require('node-mariadb');

//hs readable configuration.
var connection = nodeMaria.createConnection({
  driverType: nodeMaria.DRIVER_TYPE_HANDLER_SOCKET,
  host:'localhost',
  port:9998
});

connection.on('erorr', function(err){
  console.log(err);
  process.exit(1);
});

connection.on('connect', function(){
  
  ### Basic find.
  connection.openIndex('CTU', 'employee', nodeMaria.HandlerSocket.PRIMARY, ['id', 'name', 'age']
  , function(err, hs){
    hs.find([1], {limit:1},function(err, data){
      console.log(data);   =>  [{id: '1', name: 'jack', age: '40'}]
    });
  });


  ### Find with in clause
  connection.openIndex('CTU', 'employee', nodeMaria.HandlerSocket.PRIMARY, ['id', 'name', 'age'], ['id']
  , function(err, hs){
    hs.find({in: [1, 2, 3]}, {limit: 3}, function(err, data){
      console.log(data);   =>  [{id: '2', name: 'Tonny', age: '38'}, .... ]
    });
  });


  ### Find with filter
  connection.openIndex('CTU', 'employee', 'age', ['id', 'name', 'age'], ['age']
  , function(err, hs){
    hs.find([26], {operator: '>', limit:5, filter:['age', '<=', 28]}, function(err, data){
      console.log(data);   =>  [{id: '2', name: 'Chloe', age: '35'}, ..... ]
    });
  });
  
});

Basic Sample of HandlerSocket Driver (Write).

var nodeMaria = require('node-mariadb');

//hs writeable configuration.
var connection = nodeMaria.createConnection({
  driverType: nodeMaria.DRIVER_TYPE_HANDLER_SOCKET,
  host:'localhost',
  port:9999
});

connection.on('erorr', function(err){
  console.log(err);
  process.exit(1);
});

connection.on('connect', function(){
  
  ### Insert
  connection.openIndex('CTU', 'employee', nodeMaria.HandlerSocket.PRIMARY, ['id', 'name', 'age']
  , function(err, hs){
    hs.insert([10, 'Edgar', 35],function(err, data){
      console.log(data);   => true
    });
  });


  ### Update
  connection.openIndex('CTU', 'employee', nodeMaria.HandlerSocket.PRIMARY, ['id', 'name', 'age'], ['id']
  , function(err, hs){
    hs.update([12], {set:[12, 'Bill', 50]}, function(err, affectedNum){
      console.log(affectedNum);   =>  1
    });
  });
  
  ### Delete
  connection.openIndex('CTU', 'employee', nodeMaria.HandlerSocket.PRIMARY, ['id']
  , function(err, hs){
    hs.delete([1], function(err, affectedNum){
      console.log(affectedNum);   =>  1
    });
  });

});

Api Reference

createConnection

nodeMaria.createConnection(Object settings, [Object options])

Arguments

  • settings:
  • driverType: A driver type name. Currently suppoerted only HandlerSocket.
  • host: A host name or address for mariadb server.
  • port: A port number for mariadb server.
  • auth: {key: 'Your authnetication key'}
  • options: Options(debug, logging, etc...). (Not implemented yet.)

Constants

nodeMaria.DRIVER_TYPE_MYSQL_REGULAR_PROTOCOL
nodeMaria.DRIVER_TYPE_HANDLER_SOCKET

Events

connect

Emitted when a connection is established.

error

Emitted when an error is occured.

####close Emitted when a connection is closed.


HandlerSocket

openIndex

con.openIndex(Array config, Function callback<Object error, Object Index>)

open index to prepare to handle records.

Arguments

  • config
  1. A database name
  2. A table name
  3. An index name. If you would like to use 'Primary', you can use constant of Handlersocket.PRIMARY.
  4. An array of column names.
  5. optional [An array of column names use for filter or while filter.]
  • callback: Callback function

Find

hs.find(Any values, [Object options], Function callback<Object error, Array data>)

Find records by values and options.

Arguments

  • values : [value1, value2, ... ] or {in: [value1, value2, ... ]}
  • options:
  • limit: num (default 1)
  • offset: num (default 0)
  • operator: =,>,>=,<and<=
  • filter: ['indexname', 'operator', 'value']
  • while: ['indexname', 'operator', 'value']
  • callback: callback function.

Insert

hs.insert(Array values, [Object options], Function callback<Object error, Bool isSuccess>)

Insert record.

Arguments

  • values : [value1, value2, ... ]
  • callback: callback function.

Update

hs.update(Any values, [Object options], Function callback<Object error, Number affectedNum>)

Update rows by values and options.
It arguments are similar to find. A only different is 'set' option which is used to set updating values like as 'update' clause of sql.

Arguments

  • values : [value1, value2, ... ] or {in: [value1, value2, ... ]}
  • options:
  • set(required): [value1, value2, .... ]
  • limit: num (default 1)
  • offset: num (default 0)
  • operator: =,>,>=,<and<=
  • filter: ['indexname', 'operator', 'value']
  • while: ['indexname', 'operator', 'value']
  • callback: callback function.

Delete

hs.delete(Any values, [Object options], Function callback<Object error, Number affectedNum>)

Delete records by values and options. It arguments are same as find.

Arguments

  • values : [value1, value2, ... ] or {in: [value1, value2, ... ]}
  • options:
  • limit: num (default 1)
  • offset: num (default 0)
  • operator: =,>,>=,<and<=
  • filter: ['indexname', 'operator', 'value']
  • while: ['indexname', 'operator', 'value']
  • callback: callback function.

Increment

hs.increment(Any values, [Object options], Function callback<Object error, Number affectedNum>)

Increment records '+' options num.

Arguments

  • values : [value1, value2, ... ] or {in: [value1, value2, ... ]}
  • options:
  • '+': num
  • limit: num (default 1)
  • offset: num (default 0)
  • operator: =,>,>=,<and<=
  • filter: ['indexname', 'operator', 'value']
  • while: ['indexname', 'operator', 'value']
  • callback: callback function.

Decrement

hs.delete(Any values, [Object options], Function callback<Object error, Number affectedNum>)

Decrement records '-' options num.

Arguments

  • values : [value1, value2, ... ] or {in: [value1, value2, ... ]}
  • options:
  • '-': num
  • limit: num (default 1)
  • offset: num (default 0)
  • operator: =,>,>=,<and<=
  • filter: ['indexname', 'operator', 'value']
  • while: ['indexname', 'operator', 'value']
  • callback: callback function.

[Modifier]Get

[Modifier]Get behavior is same as normal modifier(Such as update, delete, increment and decrement).
But, their return values are not affected num but records which are contents of the records before modification.

hs.updateGet(Any values, [Object options], Function callback<Object error, Array beforeModRecords>)
hs.deleteGet(Any values, [Object options], Function callback<Object error, Array beforeModRecords>)
hs.incrementGet(Any values, [Object options], Function callback<Object error, Array beforeModRecords>)
hs.decrementGet(Any values, [Object options], Function callback<Object error, Array beforeModRecords>)

Run Test

License

(The MIT License)

Copyright (c) 2013 Yuki Takei(Noppoman) [email protected]

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.