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 ,
10
18
user : options . storageConfig . user ,
11
19
password : options . storageConfig . password
12
- } ,
13
- client = mysql . createConnection ( loginData ) ;
20
+ } ;
21
+ var client = mysql . createConnection ( loginData ) ;
14
22
client . connect ( ) ;
15
23
16
24
// 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 ( ) {
22
26
client . query (
23
27
'CREATE TABLE IF NOT EXISTS ' + TABLE_POST +
24
28
'(id INT(11) AUTO_INCREMENT, ' +
@@ -28,21 +32,17 @@ client.query('CREATE DATABASE ' + DB, function(err) {
28
32
'content_markup TEXT, ' +
29
33
'created VARCHAR(255), ' +
30
34
'PRIMARY KEY (id))' ) ;
31
-
32
35
client . query (
33
36
'CREATE TABLE IF NOT EXISTS ' + TABLE_PUBLISH +
34
37
'(id INT(11) AUTO_INCREMENT, ' +
35
38
'post_id INT(11), ' +
36
39
'PRIMARY KEY (id))' ) ;
37
-
38
40
} ) ;
39
41
40
42
// set db
41
43
client . query ( 'USE ' + DB ) ;
42
-
43
44
// constructor
44
- this . MySql = function ( ) {
45
- } ;
45
+ this . MySql = function ( ) { } ;
46
46
47
47
// add a new item
48
48
this . MySql . prototype . add = function ( obj , next ) {
0 commit comments