X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=profile.js;h=9734638b60c2c17899442edf4b68007eead88f37;hb=f1b33cf06fa5a63db6715de7ac205c143d3499c3;hp=20a069b251d8ca5552c1a47e34023c388f38923d;hpb=1ed9431031547433266a3b76fbe5c360d001af76;p=webchat%2FWebChat.git diff --git a/profile.js b/profile.js index 20a069b..9734638 100644 --- a/profile.js +++ b/profile.js @@ -264,22 +264,15 @@ function RenderMessage(res,msg,info) // function ProfileCollection() { - var MySQLPool = new require("./mysql_pool.js"); var murmurhash = require("murmurhash"); - 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 Profile = require("./init").GetProfileColletion; this.AuthAsync = function(name,password,cb){ async.waterfall([ function(next){ - pool.query("SELECT password FROM profilelist WHERE name_hash = ? and name = ?",[murmurhash.v3(name),name],next); + Profile.find({name_hash:murmurhash.v3(name), name:name}).done(next); }, function(result,next){ - if(result[0].password == md5_hex(password)) + if(result.password == md5_hex(password)) next(null,true); else next(null,false); @@ -287,30 +280,38 @@ function ProfileCollection() ],cb); } this.GetAsync = function(name,cb){ - pool.query("SELECT * FROM profilelist WHERE name_hash = ? and name = ?",[murmurhash.v3(name),name],cb); + Profile.find({name_hash:murmurhash.v3(name), name:name}).done(cb); } this.AddAsync = function(data,cb){ - var item = GetItem(data);; - pool.query("INSERT INTO profilelist SET ?",[item],cb); + newProfile = Profile.build(GetItem(data)); + newProfile.save().done(cb); } this.UpdatAsync = function(name,data,cb){ - var item = GetItem(data); - pool.query("UPDATE profilelist SET ? WHERE name_hash = ? and name = ?",[item,murmurhash.v3(name),name],cb); + Profile.update(GetItem(data),{name_hash:murmurhash.v3(name), name:name}).done(cb); } this.ClearAsync = function(cb){ - pool.query("TRUNCATE TABLE profilelist",null,cb); + Profile.drop().done(cb); } this.RemoveRangeAsync = function(names,cb){ - pool.query("DELETE FROM profilelist WHERE name IN (?)",[names],cb); + Profile.destroy({where:{ + in:[names] + } + }).done(cb); } this.RemoveAsync = function(name,cb){ - pool.query("DELETE FROM profilelist WHERE name_hash = ? and name = ?",[murmurhash.v3(name),name],cb); + Profile.destroy({name_hash:murmurhash.v3(name), name:name}).done(cb); } this.FindByNameAsync = function(pattern,start,count,cb){ - pool.query("SELECT * FROM profilelist WHERE name LIKE ? LIMIT ?,?",[pattern+"%",start,count],cb); + Profile.findAll({ + offset:start, + limit:count, + where:{ + like:pattern + } + }).done(cb); } this.ToArrayAsync = function(start,count,cb){ - pool.query("SELECT name,lastmodified FROM profilelist LIMIT ?,?",[start,count],cb); + Profile.findAll({offset:start,limit:count}).done(cb); } var crypto = require("crypto");