1.3.0 • Published 9 years ago

mysql-active-record v1.3.0

Weekly downloads
1
License
MIT
Repository
github
Last release
9 years ago

mysql-active-record

NPM Version NPM = Version

Introduction

This is an abstraction framework that leverages the node-mysql module for node.js. It was inspired by CodeIgniter's ActiveRecord class for building SQL queries - former PHP developers will likely recognize this.

Completely written in JavaScript, does not require compiling, and is 100% MIT licensed.

Here is an example on how to use it:

Installation

$ npm install mysql-active-record

Usage

var MysqlActiveRecord = require('mysql-active-record');

var config = {
  host: 'localhost',
  user: 'user',
  password: 'password',
  database: 'database_name'
}

//confirm connection
var activeRecord = new MysqlActiveRecord(config);

//will produce SELECT * FROM table1;
activeRecord.get('table1', function(results) {
  if (!results.error) {
    if (results.numResults > 0) {
        console.log(results.rows); // actual records
        console.log(results.fields); //fields returned
        console.log(results.numResults); //number of results
        console.log(results.queryExecuted); //sql statement executed
    } else {
        console.log(results.queryExecuted);
    }
  } else {
        console.log(results.error); //any errors returned
        console.log(results.queryExecuted);
  }

});

Note:

  • config options are the same as the ones passed into the node-mysql module
  • connection is implicitly created when a query is run and ended immediately after.

CRUD Operations

SELECT Statements

  • FROM
  • WHERE
  • ORDER BY
  • GROUP BY
  • HAVING
  • JOIN
  • LIMIT

INSERT Statements

UPDATE Statements

DELETE Statements

Todo

  • Update this documentation
  • More testing + adding unit tests
  • Implement create functionality for database tables
  • Implement alter functionality for database tables

Thanks

Huge thanks goes out to Felix Geisendörfer - felixge for doing all of the heavy lifting of getting the node-mysql connector together.

Contributors

Fork this module on github and send a pull requests if you've got some great updates.

For any questions / issues with this module please open an issue.

1.3.0

9 years ago

1.2.5

10 years ago

1.2.3

10 years ago

1.2.2

10 years ago

1.2.1

10 years ago

1.2.0

10 years ago

1.1.0

11 years ago

1.0.1

12 years ago

1.0.0

12 years ago