-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
93 additions
and
3 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
var mysql = require('mysql'); | ||
var connection = mysql.createConnection({ | ||
host : 'localhost', | ||
user : 'root', | ||
password : '', | ||
database : 'nodecrud' | ||
}); | ||
|
||
connection.connect(); | ||
|
||
module.exports = connection; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
var UsersModel = require('../model/UsersModel'); | ||
var Promise = require('bluebird'); | ||
|
||
|
||
function UsersController(Model) { | ||
this.Model = Promise.promisifyAll(Model); | ||
} | ||
|
||
UsersController.prototype.create = function(req, res) { | ||
|
||
}; | ||
|
||
UsersController.prototype.findOne = function(req, res) { | ||
var _id = req.params._id; | ||
|
||
this.Model.findOneAsync(_id) | ||
.then(function(result) { | ||
res.json(result[0] || []); | ||
}) | ||
.catch(function(err) { | ||
console.log(err) | ||
}); | ||
}; | ||
|
||
UsersController.prototype.findAll = function(req, res) { | ||
this.Model.findAllAsync() | ||
.then(function(result) { | ||
res.json(result || []); | ||
}) | ||
.catch(function(err) { | ||
console.log(err) | ||
}); | ||
}; | ||
|
||
UsersController.prototype.update = function(req, res) { | ||
|
||
}; | ||
|
||
|
||
UsersController.prototype.delete = function(req, res) { | ||
|
||
}; | ||
|
||
module.exports = new UsersController(UsersModel); |
Empty file.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
var mysql = require('../Db/mysql'); | ||
|
||
function UsersModel() { | ||
|
||
} | ||
|
||
UsersModel.prototype.create = function(data, callback) { | ||
|
||
}; | ||
|
||
UsersModel.prototype.findOne = function(_id, callback) { | ||
mysql.query('SELECT id, name, age FROM users WHERE id = ' + _id, function(err, rows, fields) { | ||
callback(err, rows); | ||
}); | ||
}; | ||
|
||
UsersModel.prototype.findAll = function(callback) { | ||
mysql.query('SELECT id, name, age FROM users', function(err, rows, fields) { | ||
callback(err, rows); | ||
}); | ||
}; | ||
|
||
UsersModel.prototype.update = function(data, _id, callback) { | ||
|
||
}; | ||
|
||
UsersModel.prototype.delete = function(_id, callback) { | ||
|
||
}; | ||
|
||
module.exports = new UsersModel(); |
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
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