mysqlproxy.lua 1.18 KB
local skynet = require "skynet"
require "utils.init"

local mysqld_count = tonumber(skynet.getenv("thread"))
local mysqld
skynet.init(function()
	local idx = math.randomInt(1, mysqld_count)
    mysqld = skynet.localname(".mysql" .. idx)

end)

local table_insert = table.insert

local mysqlproxy = {}


setmetatable(mysqlproxy, { __index = function(t, k)
	local cmd = string.upper(k)
    local f = function (self, ...)
        if k == "query" then
			--print(...)
        end
		local ok, result = pcall(skynet.call, mysqld, "lua", cmd, ...)
		if not ok then
			skynet.error(cmd, ..., "\n", debug.traceback(coroutine.running(), nil))
			return
		end
		return result
	end
	t[k] = f
	return f
end})

function mysqlproxy:insertEmail(params)
	local pms = {
		key = string.format("%s", 0),
		roleId = params.roleId,
		emailId = params.emailId,
		createtime = params.createtime or skynet.timex(),
		contentPms = params.contentPms or {},
		rewardPms = params.rewardPms or {},
		title = params.title or "",
		stitle = params.stitle or "",
		content = params.content or "",
		attachments = params.attachments or "",
	}

	local email = require("models.Email").new(pms)
	email:create()
	return true
end

return mysqlproxy