Skip to content

Commit 966f17b

Browse files
committed
a few modifications
1 parent a9f5875 commit 966f17b

File tree

4 files changed

+29
-26
lines changed

4 files changed

+29
-26
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
2-
nbproject
2+
nbproject
3+
test.js

app.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var express = require('express'),
44
posts = require('./lib/controllers/posts'),
55
admin = require('./lib/controllers/admin'),
66
h5bp = require('./lib/externals/h5bp-node'),
7-
abstractModel = require('./lib/models/options');
7+
options = require('./lib/models/options');
88

99
// Webserver configuration https://github.com/h5bp/server-configs
1010
var app = module.exports = h5bp.server(express, {
@@ -21,7 +21,7 @@ app.configure(function() {
2121
app.use(express.static(__dirname + '/public'));
2222
});
2323
// set env
24-
app.settings.env = abstractModel.storageConfig.env;
24+
app.settings.env = options.storageConfig.env;
2525

2626
app.configure('dev', function() {
2727
app.use(express.errorHandler({dumpExceptions: true, showStack: true}));
@@ -49,5 +49,5 @@ app.get('/admin/login', admin.login);
4949
app.get('/admin/logout', admin.logout);
5050
app.post('/admin/login', admin.postLoginData);
5151

52-
app.listen(abstractModel.storageConfig.PORT);
53-
console.log('Listening on port: ' + abstractModel.storageConfig.PORT);
52+
app.listen(options.storageConfig.PORT);
53+
console.log('Listening on port: ' + options.storageConfig.PORT);

config.json

+2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
{
22
"user": "root",
33
"password": "1234",
4+
"database": "mysql",
45
"DB": "alboh_blog",
56
"TABLE_POST": "posts",
67
"TABLE_PUBLISH": "publish",
78
"TABLE_COMMENT": "comment",
9+
"HOST":"localhost",
810
"PORT": "3000",
911
"env": "dev",
1012
"postPerPage": 10,

lib/models/mysql.js

+21-21
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
1-
// mysql implementation
2-
var options = require('./options'),
3-
mysql = require('mysql'),
4-
DB = options.storageConfig.DB,
5-
TABLE_POST = options.storageConfig.TABLE_POST,
6-
TABLE_PUBLISH = options.storageConfig.TABLE_PUBLISH,
7-
TABLE_COMMENT = options.storageConfig.TABLE_COMMENT,
8-
loginData = {
9-
host: 'localhost',
1+
// ------------------------------------------------------- //
2+
// mysql driver implementation //
3+
// ------------------------------------------------------- //
4+
5+
// calling node modules
6+
var options = require('./options');
7+
var mysql = require('mysql');
8+
9+
// config
10+
var DB = options.storageConfig.DB;
11+
var TABLE_POST = options.storageConfig.TABLE_POST;
12+
var TABLE_PUBLISH = options.storageConfig.TABLE_PUBLISH;
13+
var TABLE_COMMENT = options.storageConfig.TABLE_COMMENT;
14+
15+
// connection to mysql
16+
var loginData = {
17+
host: options.storageConfig.HOST,
1018
user: options.storageConfig.user,
1119
password: options.storageConfig.password
12-
},
13-
client = mysql.createConnection(loginData);
20+
};
21+
var client = mysql.createConnection(loginData);
1422
client.connect();
1523

1624
// create the database and tables if they are not there
17-
client.query('CREATE DATABASE ' + DB, function(err) {
18-
if (err && err.number !== mysql.ERROR_DB_CREATE_EXIST) {
19-
return;
20-
}
21-
25+
client.query('CREATE DATABASE IF NOT EXISTS' + DB, function() {
2226
client.query(
2327
'CREATE TABLE IF NOT EXISTS ' + TABLE_POST +
2428
'(id INT(11) AUTO_INCREMENT, ' +
@@ -28,21 +32,17 @@ client.query('CREATE DATABASE ' + DB, function(err) {
2832
'content_markup TEXT, ' +
2933
'created VARCHAR(255), ' +
3034
'PRIMARY KEY (id))');
31-
3235
client.query(
3336
'CREATE TABLE IF NOT EXISTS ' + TABLE_PUBLISH +
3437
'(id INT(11) AUTO_INCREMENT, ' +
3538
'post_id INT(11), ' +
3639
'PRIMARY KEY (id))');
37-
3840
});
3941

4042
// set db
4143
client.query('USE ' + DB);
42-
4344
// constructor
44-
this.MySql = function() {
45-
};
45+
this.MySql = function() {};
4646

4747
// add a new item
4848
this.MySql.prototype.add = function(obj, next) {

0 commit comments

Comments
 (0)