···3131 if self:count() > 0 then
3232 db:with_open(function()
3333 -- check if entry exists in db
3434- local res = db:select("bank", {
3535- where = {
3636- yank_text = yank_text,
3737- reg_type = reg_type,
3838- },
3939- })
3434+ local res = db:eval(
3535+ "SELECT * FROM bank WHERE yank_text = :yank_text and reg_type = :reg_type",
3636+ { yank_text = yank_text, reg_type = reg_type }
3737+ )
40384141- -- if result is empty, proceed to insertion
4242- if #res == 0 then
3939+ -- if result is empty (eval returns boolean), proceed to insertion
4040+ if type(res) == "boolean" then
4341 return
4442 end
4543···7270end
73717472--- trim database size if it exceeds max_entries option
7373+--- WARN: if all entries are pinned, behavior is undefined
7574function data:trim_size()
7675 if self:count() > max_entries then
7776 -- remove the oldest entry
7877 local e = db:with_open(function()
7979- -- TODO: figure out what to do if all entries are pinned
8078 return db:select("bank", {
8179 where = { pinned = 0 },
8280 order_by = { asc = "rowid" },