Last active
January 4, 2016 11:59
-
-
Save sbstp/8618208 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mysql = require('mysql'); | |
var connection = mysql.createConnection({ | |
host : 'localhost', | |
user : 'node-test', | |
password : '', | |
database : 'node_test' | |
}); | |
exports.open = function (callback){ | |
connection.connect(function(err){ | |
callback(err, connection); | |
}); | |
} | |
// USAGE | |
var db = require('./database.js'); | |
db.open(function (err, con) { | |
if (err) return; | |
// ... | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var user = require('./user.js'); | |
var results = user.all(); | |
console.log(results); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var db = require('./database'); | |
var connection = db.open(); | |
exports.all = function(){ | |
connection.query('select * from user', function(err, rows){ | |
if(err){ | |
console.log(err); | |
} else { | |
console.log('Query successfull'); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment