Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: 3099f14081
Fetching contributors…

Cannot retrieve contributors at this time

92 lines (75 sloc) 4.539 kb

node-poormansmysql

node-poormansmysql is a MySQL driver for node.js that executes queries using the mysql command-line client.

Requirements

Documentation

MysqlConnection Methods:

  • (constructor) MysqlConnection(config)

    • Description: Performs initialization and sets the connection configuration. All properties supplied in config overwrite the defaults listed below.
    • Parameters:

      • config: (Object) An object containing the necessary connection information to connect to the MySQL server and perform queries. At least the user and password should be supplied. The default configuration is:

          user: null,
          password: null,
          db: null,
          host: 'localhost',
          port: 3306,
          connect_timeout: 0, // in seconds
          query_timeout: 0 // in seconds (TODO)
        
    • Return Value: (MysqlConnection) An instance of MysqlConnection.
  • setConfig(config)
    • Description: Sets the connection configuration. This is only needed if you are reusing the instance and need to change the connection information. As with the constructor, all properties supplied in config are merged with the defaults.
    • Parameters:
      • config: (Object) An object containing the necessary connection information to connect to the MySQL server and perform queries. At least the user and password should be supplied. See above for the default configuration.
    • Return Value: None
  • query(sql)
    • Description: Enqueues an SQL statement.
    • Parameters:
      • sql: (String) A valid SQL statement. Do not include a trailing semicolon at the end of the statement.
    • Return Value: None
  • execute()
    • Description: Begins executing the enqueued SQL statements all at once.
    • Parameters: None
    • Return Value: (Boolean) true if there were statements to be executed and the 'user' and 'password' connection details have been supplied, false otherwise.
  • (getter) affectedRows
    • Description: Returns the number of rows updated, inserted, or deleted by the last SQL statement.
    • Return Value: (Integer) The number of rows affected by the last SQL statement.
  • (getter) lastInsertId
    • Description: Returns the first automatically generated value that was set for an AUTO_INCREMENT column by the most recent INSERT statement. See here for more details.
    • Return Value: (Integer) The value of the AUTO_INCREMENT column for the last INSERTed row.

MysqlConnection Events:

  • error
    • Description: Fired when an error occurs. This can be either a MySQL error or a child process spawning error.
    • Parameters:
      • err: (String) The error details.
  • row
    • Description: Fired when a row has been generated for the given query.
    • Parameters:
      • rowdata: (Object) A hash containing a single row from the results of a query.
      • sql: (String) The original SQL (SELECT) statement that generated the row.
  • queryDone
    • Description: Fired when the given query has completed and any/all resulting rows for the given query have been emitted.
    • Parameters:
      • sql: (String) The original SQL (SELECT) statement that generated the row.
  • done
    • Description: Fired when all queries have completed and any/all resulting rows for each query have been emitted.
    • Parameters: None

Example

var pmm = require('./node-poormansmysql'), sys = require('sys');

var conn = new pmm.MysqlConnection({user: 'foo', password: 'bar', db: 'baz'});
conn.addListener('error', function(err) {
    sys.puts('Uh oh, ' + err);
});
conn.addListener('row', function(rowdata, sql) {
    sys.puts("'" + sql + "' generated a row: " + sys.inspect(rowdata));
});
conn.addListener('queryDone', function(sql) {
    sys.puts("Done with query: " + sql);
});
conn.addListener('done', function() {
    sys.puts('Done executing all SQL statements!');
});
conn.query("SELECT * FROM table");
conn.execute();

License

See LICENSE file.

Jump to Line
Something went wrong with that request. Please try again.