reorganization

This commit is contained in:
kepler155c
2017-09-15 00:19:09 -04:00
parent a1a036dadd
commit b435fe47fc
31 changed files with 15201 additions and 0 deletions

54
apis/tableDB.lua Normal file
View File

@@ -0,0 +1,54 @@
local class = require('class')
local Util = require('util')
local TableDB = class()
function TableDB:init(args)
local defaults = {
fileName = '',
dirty = false,
data = { },
tabledef = { },
}
Util.merge(defaults, args)
Util.merge(self, defaults)
end
function TableDB:load()
local table = Util.readTable(self.fileName)
if table then
self.data = table.data
self.tabledef = table.tabledef
end
end
function TableDB:add(key, entry)
if type(key) == 'table' then
key = table.concat(key, ':')
end
self.data[key] = entry
self.dirty = true
end
function TableDB:get(key)
if type(key) == 'table' then
key = table.concat(key, ':')
end
return self.data[key]
end
function TableDB:remove(key)
self.data[key] = nil
self.dirty = true
end
function TableDB:flush()
if self.dirty then
Util.writeTable(self.fileName, {
-- tabledef = self.tabledef,
data = self.data,
})
self.dirty = false
end
end
return TableDB