node-mysql is a pure Javascript MySQL network driver for node.js
node-mysql is currently only really suitable for testing. It has a long way to go until it's a stable MySQL adapter, and your help would be greatly appreciated!
Tests are currently in the process of being rewritten to use vows.js
Originally written by Yuichiro MASUI, the library is currently lacking in documentation, although this is being worked on.
The API was originally modelled on mysql.rb. The following might be a useful reference: tmtm's mysql library reference.
Currently, this driver supports single connection only. In order to implement multiple connections, a pool manager needs to be written, which in turn requires MySQL transactions to be implemented.
var sys = require('sys');
var mysql = require('./lib/mysql');
/*
> mysql -u root
CREATE DATABASE nodejs_mysql;
GRANT ALL ON nodejs_mysql.* TO nodejs_mysql@localhost IDENTIFIED BY "nodejs_mysql";
*/
var conn = new mysql.Connection('localhost','nodejs_mysql', 'nodejs_mysql', 'nodejs_mysql');
conn.connect();
conn.query("CREATE TEMPORARY TABLE test1(intval INTEGER, strval TEXT, timestampval TIMESTAMP, boolval BOOLEAN);");
conn.query("INSERT INTO test1 VALUES(1,'a',now(),true);");
conn.query("SELECT * FROM test1;",
function(result) {
for(var i=0; i<result.records.length; ++i) {
sys.puts("Result: "+sys.inspect(result.toHash(result.records[i])));
};
},
function(error) {
sys.puts("Error: "+sys.inspect(error));
});
See also the examples folder.
- node.js >= 0.1.92
MIT License. See LICENSE file.
Original code by Yuichiro MASUI and contributors. For an up-to-date list see AUTHORS
MySQL protocol encode/decode from tmtm's ruby-mysql.
- http://github.com/tmtm/ruby-mysql
- Copyright: Copyright (c) 2009-2010 TOMITA Masahiro
- License: Ruby's
Promise library
- http://nodejs.org/
- Copyright 2009, 2010 Ryan Lienhart Dahl. All rights reserved.
- License: MIT
pack/unpack from php.js
- http://phpjs.org/functions/pack:880
- Author: Tim de Koning (http://www.kingsquare.nl)
- License: BSD