diff options
author | Kim Alvefur <zash@zash.se> | 2015-08-20 13:05:22 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2015-08-20 13:05:22 +0200 |
commit | 6ef7c4d80892f486d71e660b054bdfdb993c8528 (patch) | |
tree | 103fd7d9396b60b9f76071a009c54d3ca9d35744 /util/sql.lua | |
parent | a9029bd099734436154fc4e794d3b958e54d1943 (diff) | |
parent | d32f36b2817739d7f8d5f1208a3009b7be379562 (diff) | |
download | prosody-6ef7c4d80892f486d71e660b054bdfdb993c8528.tar.gz prosody-6ef7c4d80892f486d71e660b054bdfdb993c8528.zip |
Merge 0.10->trunk
Diffstat (limited to 'util/sql.lua')
-rw-r--r-- | util/sql.lua | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/util/sql.lua b/util/sql.lua index be34c381..70e103df 100644 --- a/util/sql.lua +++ b/util/sql.lua @@ -13,7 +13,7 @@ local DBI = require "DBI"; DBI.Drivers(); local build_url = require "socket.url".build; -module("sql") +local _ENV = nil; local column_mt = {}; local table_mt = {}; @@ -21,17 +21,17 @@ local query_mt = {}; --local op_mt = {}; local index_mt = {}; -function is_column(x) return getmetatable(x)==column_mt; end -function is_index(x) return getmetatable(x)==index_mt; end -function is_table(x) return getmetatable(x)==table_mt; end -function is_query(x) return getmetatable(x)==query_mt; end -function Integer(n) return "Integer()" end -function String(n) return "String()" end +local function is_column(x) return getmetatable(x)==column_mt; end +local function is_index(x) return getmetatable(x)==index_mt; end +local function is_table(x) return getmetatable(x)==table_mt; end +local function is_query(x) return getmetatable(x)==query_mt; end +local function Integer(n) return "Integer()" end +local function String(n) return "String()" end -function Column(definition) +local function Column(definition) return setmetatable(definition, column_mt); end -function Table(definition) +local function Table(definition) local c = {} for i,col in ipairs(definition) do if is_column(col) then @@ -42,7 +42,7 @@ function Table(definition) end return setmetatable({ __table__ = definition, c = c, name = definition.name }, table_mt); end -function Index(definition) +local function Index(definition) return setmetatable(definition, index_mt); end @@ -302,7 +302,7 @@ function engine:set_encoding() -- to UTF-8 end local engine_mt = { __index = engine }; -function db2uri(params) +local function db2uri(params) return build_url{ scheme = params.driver, user = params.username, @@ -313,8 +313,19 @@ function db2uri(params) }; end -function create_engine(self, params, onconnect) +local function create_engine(self, params, onconnect) return setmetatable({ url = db2uri(params), params = params, onconnect = onconnect }, engine_mt); end -return _M; +return { + is_column = is_column; + is_index = is_index; + is_table = is_table; + is_query = is_query; + Integer = Integer; + String = String; + Column = Column; + Table = Table; + Index = Index; + create_engine = create_engine; +}; |