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が存在しません";
44 var Sequelize = require("sequelize");
45 var pool = new Sequelize(config.db_name, config.db_user, config.db_password,{
50 var fs = require("fs");
54 var query = GetCreateQuery(Sequelize,config.alias,"profilelist");
55 var profilelist = pool.define("profilelist",query);
56 module.exports.GetProfileColletion = profilelist;
69 var query = GetCreateQuery(Sequelize,def,"ipbanlist");
70 ipbanlist = pool.define("ipbanlist",query);
71 module.exports.GetIpBanColletion = ipbanlist;
76 type : "unsignednumber",
89 var query = GetCreateQuery(Sequelize,def,"rooms");
90 rooms = pool.define("rooms",query);
91 module.exports.GetRoomInfomation = rooms;
93 fs.exists("inited",function(exists){
97 function(exists,next){
101 fs.open("inited","a",function(err,fd){
107 module.exports.GetProfileColletion.sync({force:true}).done(next);
109 function(result,next){
110 pool.getQueryInterface().addIndex(
111 module.exports.GetProfileColletion.tableName,
115 function(result,next){
116 module.exports.GetIpBanColletion.sync({force:true}).done(next);
118 function(result,next){
119 module.exports.GetRoomInfomation.sync({force:true}).done(next);
129 function GetCreateQuery(Sequelize,def,tablename)
134 if(typeof(def[key].nodefinetable) != "undefined" && def[key].nodefinetable)
137 switch(def[key].type)
140 option["type"] = Sequelize.STRING(def[key].length);
143 option["type"] = Sequelize.INTEGER(def[key].length);
145 case "unsignednumber":
146 option["type"] = Sequelize.INTEGER(def[key].length).UNSIGNED;
149 option["type"] = Sequelize.STRING(def[key].length);
152 option["type"] = Sequelize.STRING(def[key].length);
155 option["type"] = Sequelize.TEXT;
158 option["type"] = Sequelize.BOOLEAN;
161 option["type"] = Sequelize.DATE;
164 throw util.format("invaild %s type:%s",key,def[key].type);
166 if(typeof(def[key].isnotempty) != "undefined" && def[key].isnotempty)
167 option["allowNull"] = true;
168 if(typeof(def[key].primary) != "undefined" && def[key].primary)
169 option["primaryKey"] = true;
170 result[key] = option;