OSDN Git Service

sequelizeに移行した
[webchat/WebChat.git] / room.js
diff --git a/room.js b/room.js
index a5ff81c..950fa36 100644 (file)
--- a/room.js
+++ b/room.js
@@ -3,14 +3,7 @@ module.exports = function()
 {
        var _this = this;
        var config = require("./configure.js");
-       var MySQLPool = new require("./mysql_pool.js");
-       var pool = new MySQLPool({
-                               host     : config.db_host,
-                               user     : config.db_user,
-                               password : config.db_password,
-                               port     : config.db_port,
-                               database : config.db_name,
-                       });
+       var RoomInfomationModel = require("./init").GetRoomInfomation;
        var collection = {};
        this.Get = function(rno){
                return collection[rno];
@@ -45,7 +38,7 @@ module.exports = function()
                var async = require("async");
                async.waterfall([
                        function(next){
-                               pool.query("TRUNCATE TABLE rooms",null,next);
+                               RoomInfomationModel.drop().done(next);
                        },
                        function(result,next){
                                var util = require("util");
@@ -72,7 +65,8 @@ module.exports = function()
                                        Add(rno,password,romonly);
                                        items.push(new Array(rno,password,romonly));
                                }
-                               pool.query("INSERT INTO rooms VALUES ?",[items],callfunc);
+                               newRoom = RoomInfomationModel.build(items);
+                               newRoom.save().done(next);
                        }
                ],callfunc);
        }
@@ -81,13 +75,12 @@ module.exports = function()
                var async = require("async");
                async.waterfall([
                        function(next){
-                               pool.query("SELECT * FROM rooms",null,next);
+                               RoomInfomationModel.findAll().done(next);
                        },
                        function(result,next){
                                for(var i = 0; i < result.length; i++)
                                {
-                                       //MySQL\82Å\82ÍTINYINT\82ª\8eg\82í\82ê\82Ä\82¢\82é
-                                       Add(result[i].number,result[i].password,result[i].hiddenlog != 0);
+                                       Add(result[i].number,result[i].password,result[i].hiddenlog);
                                }
                                next(null,null);
                        }