pilmee-mysql

Library to manage mysql, using the mysql module, shortens the programming necessary to provide greater ease so the developer. Power by @pilmee

npm install pilmee-mysql
13 downloads in the last week
52 downloads in the last month

pilmee-mysql logo

Library to manage mysql, using the mysql module, shortens the programming necessary to provide greater ease so the developer. Power by @pilmee

Installation

$ npm install pilmee-mysql

Example 1 - Basic:

var db = require('pilmee-mysql');

db.configure(function(){
    db.set('host', 'localhost');
    db.set('user', 'root');
    db.set('database', 'ninjacode');
});

db.run('SELECT * FROM noticias ORDER BY id DESC', function(err, result){
     console.log('\n Records: ' + db.results());
});

Example 2 - Basic:

var db = require('pilmee-mysql');

db.configure(function(){
    db.set('host', 'localhost');
    db.set('user', 'root');
    db.set('database', 'ninjacode');
});

db.run('SELECT * FROM noticias ORDER BY id DESC', function(err, result){
     db.list(result, 'id', 'titulo', function(){
         console.log('\n Records: ' + db.results());
     });
});

Example 3 - Use ExpressJS:


/**
 * Module dependencies.
 */

var express = require('express')
  , routes = require('./routes')
  , user = require('./routes/user')
  , http = require('http')
  , path = require('path');

var db = require('pilmee-mysql');
db.configure(function(){
  db.set('host', 'localhost');
  db.set('user', 'root');
  db.set('database', 'ninjacode');
});

var app = express();

app.configure(function(){
  app.set('port', process.env.PORT || 3000);
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');
  app.use(express.favicon());
  app.use(express.logger('dev'));
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(express.cookieParser('your secret here'));
  app.use(express.session());
  app.use(app.router);
  app.use(express.static(path.join(__dirname, 'public')));
});

app.configure('development', function(){
  app.use(express.errorHandler());
});

/* DATA JSON */
app.get('/', function(req,  res){
  db.run('SELECT * FROM noticias', function(err, result, field){
    res.json(result);
  });
});

/* DATA XML */
app.get('/xml', function(req,  res){
  db.run('SELECT * FROM noticias', function(err, result, field){
    db.toXML(result, function(xml){
      res.send(xml);
    });
  });
});

http.createServer(app).listen(app.get('port'), function(){
  console.log("Express server listening on port " + app.get('port'));
});

Contact:

npm loves you