Skip to content

Commit

Permalink
同步代码
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaobangyu committed Apr 19, 2024
1 parent d59763b commit 2cb5f81
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions script/driver/sqlite.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ function Sqlite:register_prepare(sheet)
}
end

function Sqlite:get_prepare(sheet)
function Sqlite:get_prepare(sheet, primary_id)
if not self.prepares[sheet] then
self:register_prepare(sheet)
self:init_sheet(sheet, primary_id)
end
return self.prepares[sheet]
end
Expand All @@ -67,14 +67,14 @@ end

function Sqlite:init_sheet(sheet, primary_id)
log_debug("[Sqlite][init_sheet] sheet:{} primary_id:{}", sheet, primary_id)
self:register_prepare(sheet)
self.driver.exec(sformat("CREATE TABLE IF NOT EXISTS '%s' (KEY %s PRIMARY KEY NOT NULL, VALUE BLOB);", sheet,
type(primary_id) == "string" and "TEXT" or "INTEGER"))
self:register_prepare(sheet)
end

function Sqlite:put(primary_id, data, sheet)
log_debug("[Sqlite][put] primary_id:{} data:{} sheet:{}", primary_id, data, sheet)
local rc = self:get_prepare(sheet).update.run(primary_id, data)
local rc = self:get_prepare(sheet, primary_id).update.run(primary_id, data)
if rc ~= SQLITE_DONE then
log_debug("[Sqlite][put] fail rc={}", rc)
return false
Expand All @@ -84,15 +84,15 @@ end

function Sqlite:get(primary_id, sheet)
log_debug("[Sqlite][get] sheet:{} primary_id:{}", sheet, primary_id)
local rc, data = self:get_prepare(sheet).select.run(primary_id)
local rc, data = self:get_prepare(sheet, primary_id).select.run(primary_id)
if rc == SQLITE_NFOUND or rc == SQLITE_DONE then
return (data[1] and data[1].VALUE) and data[1].VALUE or {}, true
end
return {}, false
end

function Sqlite:del(primary_id, sheet)
local rc = self:get_prepare(sheet).delete.run(primary_id)
local rc = self:get_prepare(sheet, primary_id).delete.run(primary_id)
return rc == SQLITE_NFOUND or rc == SQLITE_OK
end

Expand Down

0 comments on commit 2cb5f81

Please sign in to comment.