Description
A node.js binding to MariaDB's non-blocking (MySQL) client
library.
This binding is different from other vanilla libmysqlclient bindings in that it
uses the non-blocking functions available in MariaDB's client library.
Therefore, this binding does not use multiple threads to achieve non-blocking
behavior.
This binding is currently tested on Windows and Linux.
Requirements
Install
npm install mariasql
Examples
- Simple query to retrieve a list of all databases:
var inspect = require('util').inspect;
var Client = require('mariasql');
var c = new Client();
c.on('connect', function() {
console.log('Connected!');
var q = c.query("SHOW DATABASES");
q.on('result', function(result) {
console.log('Query result: ' + inspect(result));
});
q.on('error', function(err) {
console.log('Query error: ' + err);
});
q.on('end', function() {
console.log('Query finished');
c.close();
});
});
c.on('error', function(err) {
console.log('Client error: ' + err);
});
c.on('close', function(had_err) {
console.log('Closed');
});
c.connect({
host: '127.0.0.1',
user: 'foo',
password: 'bar'
});
API
require('mariasql') returns a Client object
Client events
-
connect() - A connection to the server was successful.
-
error(<Error>err) - An error occurred at the connection level.
-
close(<boolean>hadError) - The connection was closed. hadError
is set to true if this was due to a connection-level error.
Client methods
-
(constructor)() - Creates and returns a new Client instance.
-
connect(<object>config) - (void) - Attempts a connection to a server using the information given in config
:
-
user - <string> - Username for authentication. Default: (*nix: current login name, Windows: ???)
-
password - <string> - Password for authentication. Default: (blank password)
-
host - <string> - Hostname or IP address of the MySQL/MariaDB server. Default: "localhost"
-
port - <integer> - Port number of the MySQL/MariaDB server. Default: 3306
-
db - <string> - A database to automatically select after authentication Default: (no db)
-
query(<string>query) - <EventEmitter> - Enqueues the given query
and returns an EventEmitter that emits the following when the query is executed:
-
result(<object>res) - res
is an object of fieldName=>value pairs, where value is a string.
-
end() - No more results for this query.
-
error(<Error>err) - An error occurred while executing this query.
-
escape(<string>value) - Escapes value
for use in queries. This method requires a live connection.
-
close(<boolean>immediately) - If immediately
is true, the connection is severed even if other queries are still in the queue.
TODO
-
Multiple statement (e.g. "SELECT * FROM foo; SELECT * FROM bar" vs. "SELECT * FROM foo") support
-
Compression
-
SSL encrypted connections
-
Misc. query info (e.g. affected_rows, insert_id, etc)
-
Auto-reconnect algorithm(s)
-
Array-based query results option instead of being forced into a fieldName=>value object
-
Possibly some other stuff I'm not aware of at the moment