add exists helper to sqlite wrapper

This commit is contained in:
Sky Johnson 2025-05-24 11:39:13 -05:00
parent bf5a841716
commit ac607213fc

View File

@ -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,