1 var util = require("util");
2 var config = require("./configure.js");
4 var profilelist,ipbanlist,rooms;
6 module.exports.GetProfileColletion = {};
7 module.exports.GetIpBanColletion = {};
8 module.exports.GetRoomInfomation = {};
9 module.exports = function(callback){
10 var async = require("async");
12 if("name_hash" in config.alias)
14 if(config.alias["name_hash"].type != "unsignednumber")
15 throw "name_hashの型はunsignednumberでなければなりません";
17 throw "name_hashが存在しません";
20 if("name" in config.alias)
22 if(config.alias["name"].type != "text")
23 throw "nameの型はtextでなければなりません";
28 if("password" in config.alias)
30 if(config.alias["password"].type != "password")
31 throw "nameの型はpasswordでなければなりません";
33 throw "passwordが存在しません";
36 if("lastmodified" in config.alias)
38 if(config.alias["lastmodified"].type != "datetime")
39 throw "lastmodifiedの型はtextでなければなりません";
41 throw "lastmodifiedが存在しません";
43 var fs = require("fs");
46 var Sequelize = require("sequelize");
47 var pool = new Sequelize(config.db_name, config.db_user, config.db_password,{
52 var query = GetCreateQuery(Sequelize,config.alias,"profilelist");
53 var profilelist = pool.define("profilelist",query);
54 module.exports.GetProfileColletion = profilelist;
68 var query = GetCreateQuery(Sequelize,def,"ipbanlist");
69 ipbanlist = pool.define("ipbanlist",query);
70 module.exports.GetIpBanColletion = ipbanlist;
75 type : "unsignednumber",
88 var query = GetCreateQuery(Sequelize,def,"rooms");
89 rooms = pool.define("rooms",query);
90 module.exports.GetRoomInfomation = rooms;
92 fs.exists("inited",function(exists){
96 function(exists,next){
100 fs.open("inited","a",function(err,fd){
103 module.exports.GetProfileColletion.drop();
104 module.exports.GetProfileColletion.sync();
106 module.exports.GetIpBanColletion.drop();
107 module.exports.GetIpBanColletion.sync();
109 module.exports.GetRoomInfomation.drop();
110 module.exports.GetRoomInfomation.sync();
120 function GetCreateQuery(Sequelize,def,tablename)
125 if(typeof(def[key].nodefinetable) != "undefined" && def[key].nodefinetable)
128 switch(def[key].type)
131 option["type"] = Sequelize.STRING(def[key].length);
134 option["type"] = Sequelize.INTEGER(def[key].length);
136 case "unsignednumber":
137 option["type"] = Sequelize.INTEGER(def[key].length).UNSIGNED;
140 option["type"] = Sequelize.STRING(def[key].length);
143 option["type"] = Sequelize.STRING(def[key].length);
146 option["type"] = Sequelize.TEXT;
149 option["type"] = Sequelize.BOOLEAN;
152 option["type"] = Sequelize.DATE;
155 throw util.format("invaild %s type:%s",key,def[key].type);
157 if(typeof(def[key].isnotempty) != "undefined" && def[key].isnotempty)
158 option["allowNull"] = true;
159 else if(typeof(def[key].primary) != "undefined" && def[key].primary)
160 option["primaryKey"] = true;
161 result[key] = option;