Guest User

Meekro Release 3

a guest
Oct 2nd, 2014
17
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. meekro=meekro or{}meekro._debug=false;meekro._drivers={}meekro.error="meekro-error"meekro.lastInsert=0;meekro._placeholders={string="s",boolean="b",number="f"}meekro._drivers["mysqloo"]={init=function()require("mysqloo")end,connect=function(a,b,c,d,e)local f=mysqloo.connect(a,b,c,d,e or 3306)f.onConnected=meekro.OnConnectSuccess;f.onConnectionFailed=meekro.OnConnectFailed;f:connect()meekro._connection=f end,query=function(g)meekro.error=false;local h=meekro._connection:query(g)if not h then error("[meekro] cannot query, not connected")end;h:start()h:wait()if h:error()~=""then meekro.error=true;return h:error()end;meekro.lastInsert=h:lastInsert()return h:getData()end,disconnect=function()MsgC(Color(255,0,0),"[meekro] driver does not implement disconnect\n")end,escape=function(g)return meekro._connection:escape(g)end,connected=function()if meekro._connection:status()==mysqloo.DATABASE_CONNECTED then return true else return false end end}meekro.Driver="mysqloo"meekro.OnConnectSuccess=function()end;meekro.OnConnectFailed=function()end;meekro.init=function()meekro.driver().init()end;meekro.connect=function(a,b,c,d,e)meekro.driver().connect(a,b,c,d,e)end;meekro.update=function(i,j,query,...)local k={}for l,m in pairs(j)do if type(l)~="string"then error("[meekro] insert provided invalid key type")end;local n="`"..l.."`="if type(m)=="string"then n=n.."'"..meekro.escape(m).."'"elseif type(m)=="boolean"then n=n..tostring(m and 1 or 0)else n=n..tostring(m)end;table.insert(k,n)end;local query="UPDATE `"..i.."` ".."SET "..string.Implode(",",k).." WHERE "..meekro.format(query,unpack({...}))if meekro.debug then MsgC(Color(255,127,0),"[meekro] built update: "..query.."\n")end;return meekro.driver().query(query)end;meekro.insert=function(i,j)local o={}local p={}for l,m in pairs(j)do if type(l)~="string"then error("[meekro] insert provided invalid key type")end;table.insert(o,meekro.escape(l))if type(m)=="string"then table.insert(p,"'"..meekro.escape(m).."'")elseif type(m)=="boolean"then table.insert(p,tostring(m and 1 or 0))else table.insert(p,tostring(m))end end;local query="INSERT INTO `"..i.."` ".."("..string.Implode(",",o)..") ".."VALUES ("..string.Implode(",",p)..")"if meekro.debug then MsgC(Color(255,127,0),"[meekro] built insert: "..query.."\n")end;return meekro.driver().query(query)end;meekro.query=function(query,...)print(query)local query=meekro.format(query,unpack({...}))if meekro.debug then MsgC(Color(255,127,0),"[meekro] built query: "..query.."\n")end;return meekro.driver().query(query)end;meekro.queryRow=function(query,...)query=string.TrimRight(query)query=string.TrimRight(query,";")return meekro.query(query.." LIMIT 1;",unpack({...}))end;meekro.delete=function(i,query,...)local query="DELETE FROM `"..i.."` ".." WHERE "..meekro.format(query,unpack({...}))if meekro.debug then MsgC(Color(255,127,0),"[meekro] built delete: "..query.."\n")end;return meekro.driver().query(query)end;meekro.dropTable=function(i)local query="DROP TABLE `"..i.."`"if meekro.debug then MsgC(Color(255,127,0),"[meekro] built table drop: "..query.."\n")end;return meekro.driver().query(query)end;meekro.dropDatabase=function(q)local query="DROP DATABASE `"..q.."`"if meekro.debug then MsgC(Color(255,127,0),"[meekro] built database drop: "..query.."\n")end;return meekro.driver().query(query)end;meekro.tableExists=function(i)local j=meekro.query("SHOW TABLES LIKE %s",i)if meekro.error or type(j)~="table"then return false else if table.Count(j)>0 then return true else return false end end end;meekro.connected=function()return meekro.driver().connected()end;meekro.driver=function()return meekro._drivers[meekro.Driver]end;meekro.escape=function(g)return meekro.driver().escape(g)end;meekro.debug=function(r)meekro._debug=r end;meekro.format=function(g,...)local s="start"local t=""local u={...}local v=1;local w=""for x=1,g:len()do local y=g:sub(x,x)if s=="start"then if y=="%"then if v>#u then error("[meekro] too few arguments passed to query")end;s="percent"w=""else t=t..y end elseif s=="percent"then w=w..y;if w=="?"then if not meekro._placeholders[type(u[v])]then t=t.."%?"s="start"v=v+1;MsgC(Color(255,0,0),"[meekro] query uses invalid value")else w=meekro._placeholders[type(u[v])]end end;if w=="s"then t=t.."'"..tostring(meekro.escape(u[v])).."'"s="start"v=v+1 elseif w=="i"then t=t..math.floor(tonumber(u[v]))s="start"v=v+1 elseif w=="d"then t=t..tonumber(u[v])s="start"v=v+1 elseif w=="b"then t=t..u[v]and 1 or 0;s="start"v=v+1 elseif w=="l"then t=t..tostring(u[v])s="start"v=v+1 end;if w:len()>2 then t=t.."%"..w;s="start"v=v+1;MsgC(Color(255,0,0),"[meekro] query uses invalid placeholder")end end end;return t end
RAW Paste Data