refactor database

This commit is contained in:
jysperm
2014-09-06 11:58:36 +08:00
parent 67f476feb1
commit 4ad15c7ded
7 changed files with 9 additions and 21 deletions

View File

@@ -3,7 +3,6 @@ path = require 'path'
harp = require 'harp'
fs = require 'fs'
moment = require 'moment'
mongomin = require 'mongo-min'
redis = require 'redis'
global.app = express()
@@ -30,20 +29,16 @@ bindRouters = ->
app.get '/', (req, res) ->
res.redirect '/panel/'
exports.connectDatabase = (callback) ->
exports.run = ->
{user, password, host, name} = config.mongodb
mongomin "mongodb://#{user}:#{password}@#{host}/#{name}", (err, db) ->
MongoClient.connect "mongodb://#{user}:#{password}@#{host}/#{name}", (err, db) ->
throw err if err
app.db = db
app.redis = redis.createClient 6379, '127.0.0.1',
auth_pass: config.redis_password
callback err
exports.run = ->
exports.connectDatabase (err) ->
throw err if err
app.package = require './package.json'
app.use connect.json()
@@ -51,8 +46,6 @@ exports.run = ->
app.use connect.cookieParser()
app.use connect.logger('dev')
moment.locale 'zh_CN'
app.use (req, res, next) ->
res.locals.app = app
res.locals.t = i18n.getTranslator req.cookies.language

View File

@@ -6,11 +6,7 @@ bitcoin = require '../bitcoin'
mBalance = require './balance'
module.exports = exports = app.db.buildModel 'accounts'
exports.byUsername = exports.buildByXXOO 'username'
exports.byEmail = exports.buildByXXOO 'email'
exports.byDepositAddress = exports.buildByXXOO 'attribute.bitcoin_deposit_address'
module.exports = exports = app.db.collection 'accounts'
sample =
username: 'jysperm'

View File

@@ -1,4 +1,4 @@
module.exports = exports = app.db.buildModel 'balance_log'
module.exports = exports = app.db.collection 'balance_log'
sample =
account_id: new ObjectID()

View File

@@ -1,6 +1,6 @@
mAccount = require './account'
module.exports = exports = app.db.buildModel 'coupon_code'
module.exports = exports = app.db.collection 'coupon_code'
sample =
code: 'PmlFH2hpziDmyqPX'

View File

@@ -1,4 +1,4 @@
module.exports = exports = app.db.buildModel 'security_log'
module.exports = exports = app.db.collection 'security_log'
sample =
account_id: new ObjectID()

View File

@@ -2,7 +2,7 @@ markdown = require('markdown').markdown
mAccount = require './account'
module.exports = exports = app.db.buildModel 'tickets'
module.exports = exports = app.db.collection 'tickets'
sample =
account_id: ObjectID()

View File

@@ -40,7 +40,6 @@
"mysql": "~2.4.2",
"moment-timezone": "~0.2.2",
"request": "~2.40.0",
"mongo-min": "~0.2.2",
"redis": "~0.12.1",
"nodemailer": "~0.7.1"
}