-
Notifications
You must be signed in to change notification settings - Fork 20
/
db.js
46 lines (45 loc) · 1.61 KB
/
db.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
var jugglingdb = require('jugglingdb');
var Schema = jugglingdb.Schema;
var config = require('./config');
var get = config.get;
var prefix = get('prefix');
var schema = new Schema(
get('sqltype'),
{
port:get('port'),
host:get('host'),
username:get('username'),
password:get('password'),
database:get('database')
}
);
var BaiduCookie = exports.BaiduCookie = schema.define(
prefix + '_baiduCookies',
{
username : { type: String , index: true } ,
password : String ,
cookie : { type:Schema.JSON , limit: 1000},
express : Date
}
);
var SavedFile = exports.SavedFile = schema.define(
prefix + '_savedFiles',
{
identity : { type: String , index: true },
// hit : { type: Number , default: 1 },
// queryTimes : { type: Number , default: 1 },
// saveUser : { type: String , index: true },
joinTime : { type: Date , default: function(){ return Date.now();}},
lastHit : { type: Date , default: function(){ return Date.now();}},
size : Number,
fs_id : { type: Number , index:true , limit:64 },
}
);
SavedFile.validatesUniquenessOf('identity', {message: 'identity is not unique'});
SavedFile.validatesUniquenessOf('fs_id', {message: 'fs_id is not unique'});
BaiduCookie.validatesUniquenessOf('username', {message: 'username is not unique'});
BaiduCookie.hasMany(SavedFile , {as: 'files', foreignKey: 'fileid'});
SavedFile.belongsTo(BaiduCookie , {as: 'disk', foreignKey: 'fileid'});
exports.migrate = function(next){
return schema.automigrate(next);
}