Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sidorares/nodejs-mysql-native
Native mysql async client for node.js
https://github.com/sidorares/nodejs-mysql-native
Last synced: 13 days ago
JSON representation
Native mysql async client for node.js
- Host: GitHub
- URL: https://github.com/sidorares/nodejs-mysql-native
- Owner: sidorares
- License: mit
- Created: 2010-02-15T14:44:45.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2018-05-17T09:55:33.000Z (over 6 years ago)
- Last Synced: 2024-10-19T18:16:35.563Z (24 days ago)
- Language: JavaScript
- Homepage:
- Size: 205 KB
- Stars: 244
- Watchers: 18
- Forks: 34
- Open Issues: 25
-
Metadata Files:
- Readme: README.md
- Changelog: Changelog
- License: LICENSE
Awesome Lists containing this project
README
# Deprecated . If you are using it, please consider migrating to [node-mysql2](https://github.com/sidorares/node-mysql2)
# About
Mysql client module for node.js, written in JavaScript. No other mysql runtime required.[![Build Status](https://secure.travis-ci.org/sidorares/nodejs-mysql-native.png)](http://travis-ci.org/sidorares/nodejs-mysql-native)
# Install
`npm install mysql-native`# Community
Check out the google group http://groups.google.com/group/node-mysql-native for questions/answers from users of the driver.# Example
var db = require("mysql-native").createTCPClient(); // localhost:3306 by default
db.auto_prepare = true;
function dump_rows(cmd)
{
cmd.addListener('row', function(r) { console.dir(r); } );
}db.auth("test", "testuser", "testpass");
dump_rows(db.query("select 1+1,2,3,'4',length('hello')"));
dump_rows(db.execute("select 1+1,2,3,'4',length(?)", ["hello"]));
db.close();output is:
row: [ 2, 2, 3, "4", 5]
row: [ 2, 2, 3, "4", 5]# Highlights
* commands are pipelined
* types are converted mysql<->javascript according to field type
* prepared statements are cached and auto-prepared
* row packet ( query ) and binary row packet ( execute ) handled transparently equal#API
## Module Functions
* createClient(socket) - create client from duplex stream (TODO: add default path to local server socket)
* createTCPClient(host, port) - create tcp client, default host 127.0.0.1, port 3306
* createUNIXClient(path) - connect to unix domain socket, default is /var/run/mysqld/mysqld.sock## Client Functions
All commands fire 'end'() event at the end of command executing.* `auth(db, user, pass)` - perform mysql connection handshake. Should be always a first command (TODO: add default user/pass if missing?).
Events:
'authorized'(serverStatus) event.* `query(sql)` - simple query.
Events:
'field'(field) - one for each field description
'fields_eof'() - after last field
'row'(rows) - array of field values, fired for each row in result set* `client.prepre(sql)` - prepare a statement and store result in client.pscache
Events:
'prepared'(preparedStatement)
'parameter'(field) - input parameter description* `execute(sql, parameters)` - parameters is an array of values. Known types are sent in appropriate mysql binary type (TODO: currently this is not true, type is always string and input converted using param.toString() )
Events:
same as with query()
* `client.close` - create and enqueue corresponding command
* `client.execute` also adds prepare command if there is no cached statement and client.auto_prepare set to true (TODO: add better api than client.auto_prepare flag)
* `client.terminate` - close conection immediately# TODO
* buffers
# LINKS
MySql protocol documentation:
*Other node.js mysql clients:
*
*
*[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/sidorares/nodejs-mysql-native/trend.png)](https://bitdeli.com/free "Bitdeli Badge")