add exists helper to sqlite wrapper
This commit is contained in:
parent
bf5a841716
commit
ac607213fc
@ -263,6 +263,21 @@ local connection_mt = {
|
|||||||
return results[1]
|
return results[1]
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
exists = function(self, table_name, where, params, ...)
|
||||||
|
if type(table_name) ~= "string" then
|
||||||
|
error("connection:exists: table_name must be a string", 2)
|
||||||
|
end
|
||||||
|
|
||||||
|
local query = "SELECT 1 FROM " .. table_name
|
||||||
|
if where then
|
||||||
|
query = query .. " WHERE " .. where
|
||||||
|
end
|
||||||
|
query = query .. " LIMIT 1"
|
||||||
|
|
||||||
|
local results = self:query(query, normalize_params(params, ...))
|
||||||
|
return #results > 0
|
||||||
|
end,
|
||||||
|
|
||||||
begin = function(self)
|
begin = function(self)
|
||||||
return self:exec("BEGIN TRANSACTION")
|
return self:exec("BEGIN TRANSACTION")
|
||||||
end,
|
end,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user