mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-22 07:13:45 +01:00
Convert indentation to tabs
This commit is contained in:
parent
26de548e32
commit
a2a6cdd64d
@ -41,9 +41,9 @@ end
|
|||||||
|
|
||||||
function new(file_path, root)
|
function new(file_path, root)
|
||||||
return setmetatable({
|
return setmetatable({
|
||||||
database = sqlite3.open(file_path),
|
database = sqlite3.open(file_path),
|
||||||
root = root
|
root = root
|
||||||
}, metatable)
|
}, metatable)
|
||||||
end
|
end
|
||||||
|
|
||||||
function _ENV.setmetatable(self)
|
function _ENV.setmetatable(self)
|
||||||
@ -54,16 +54,16 @@ end
|
|||||||
local set
|
local set
|
||||||
|
|
||||||
local function add_table(self, table)
|
local function add_table(self, table)
|
||||||
if type(table) ~= "table" then return end
|
if type(table) ~= "table" then return end
|
||||||
if self.counts[table] then
|
if self.counts[table] then
|
||||||
self.counts[table] = self.counts[table] + 1
|
self.counts[table] = self.counts[table] + 1
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
self.table_ids[table] = increment_highest_table_id(self)
|
self.table_ids[table] = increment_highest_table_id(self)
|
||||||
self.counts[table] = 1
|
self.counts[table] = 1
|
||||||
for k, v in pairs(table) do
|
for k, v in pairs(table) do
|
||||||
set(self, table, k, v)
|
set(self, table, k, v)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local decrement_reference_count
|
local decrement_reference_count
|
||||||
@ -136,13 +136,13 @@ function set(self, table, key, value)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function exec(self, sql)
|
local function exec(self, sql)
|
||||||
if self.database:exec(sql) ~= sqlite3.OK then
|
if self.database:exec(sql) ~= sqlite3.OK then
|
||||||
error(self.database:errmsg())
|
error(self.database:errmsg())
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function init(self)
|
function init(self)
|
||||||
local database = self.database
|
local database = self.database
|
||||||
local function prepare(sql)
|
local function prepare(sql)
|
||||||
local stmt = database:prepare(sql)
|
local stmt = database:prepare(sql)
|
||||||
if not stmt then error(database:errmsg()) end
|
if not stmt then error(database:errmsg()) end
|
||||||
@ -167,8 +167,8 @@ CREATE TABLE IF NOT EXISTS table_entries (
|
|||||||
value BLOB NOT NULL,
|
value BLOB NOT NULL,
|
||||||
PRIMARY KEY (table_id, key_type, key)
|
PRIMARY KEY (table_id, key_type, key)
|
||||||
)]])
|
)]])
|
||||||
-- Default value
|
-- Default value
|
||||||
self.highest_table_id = 0
|
self.highest_table_id = 0
|
||||||
for id in self.database:urows"SELECT MAX(table_id) FROM table_entries" do
|
for id in self.database:urows"SELECT MAX(table_id) FROM table_entries" do
|
||||||
-- Gets a single value
|
-- Gets a single value
|
||||||
self.highest_table_id = id
|
self.highest_table_id = id
|
||||||
@ -176,7 +176,7 @@ CREATE TABLE IF NOT EXISTS table_entries (
|
|||||||
increment_highest_table_id(self)
|
increment_highest_table_id(self)
|
||||||
local tables = {}
|
local tables = {}
|
||||||
local counts = {}
|
local counts = {}
|
||||||
self.counts = counts
|
self.counts = counts
|
||||||
local function get_value(type_, content)
|
local function get_value(type_, content)
|
||||||
if type_ == types.boolean then
|
if type_ == types.boolean then
|
||||||
if content == 0 then return false end
|
if content == 0 then return false end
|
||||||
@ -216,25 +216,25 @@ CREATE TABLE IF NOT EXISTS table_entries (
|
|||||||
table[get_value(key_type, key)] = get_value(value_type, value)
|
table[get_value(key_type, key)] = get_value(value_type, value)
|
||||||
tables[table_id] = table
|
tables[table_id] = table
|
||||||
end
|
end
|
||||||
if tables[1] then
|
if tables[1] then
|
||||||
self.root = tables[1]
|
self.root = tables[1]
|
||||||
counts[self.root] = counts[self.root] + 1
|
counts[self.root] = counts[self.root] + 1
|
||||||
self.table_ids = modlib.table.flip(tables)
|
self.table_ids = modlib.table.flip(tables)
|
||||||
self:collectgarbage()
|
self:collectgarbage()
|
||||||
else
|
else
|
||||||
self.highest_table_id = 0
|
self.highest_table_id = 0
|
||||||
self.table_ids = {}
|
self.table_ids = {}
|
||||||
add_table(self, self.root)
|
add_table(self, self.root)
|
||||||
end
|
end
|
||||||
databases[self] = true
|
databases[self] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
function rewrite(self)
|
function rewrite(self)
|
||||||
exec(self, "DELETE FROM table_entries")
|
exec(self, "DELETE FROM table_entries")
|
||||||
self.highest_table_id = 0
|
self.highest_table_id = 0
|
||||||
self.table_ids = {}
|
self.table_ids = {}
|
||||||
self.counts = {}
|
self.counts = {}
|
||||||
add_table(self, self.root)
|
add_table(self, self.root)
|
||||||
end
|
end
|
||||||
|
|
||||||
function _ENV.set(self, table, key, value)
|
function _ENV.set(self, table, key, value)
|
||||||
@ -248,7 +248,7 @@ function _ENV.set(self, table, key, value)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function set_root(self, key, value)
|
function set_root(self, key, value)
|
||||||
return _ENV.set(self, self.root, key, value)
|
return _ENV.set(self, self.root, key, value)
|
||||||
end
|
end
|
||||||
|
|
||||||
function collectgarbage(self)
|
function collectgarbage(self)
|
||||||
@ -292,10 +292,10 @@ local function finalize_statements(table)
|
|||||||
for _, stmt in pairs(table) do
|
for _, stmt in pairs(table) do
|
||||||
if type(stmt) == "table" then
|
if type(stmt) == "table" then
|
||||||
finalize_statements(stmt)
|
finalize_statements(stmt)
|
||||||
else
|
else
|
||||||
local errcode = stmt:finalize()
|
local errcode = stmt:finalize()
|
||||||
assert(errcode == sqlite3.OK, errcode)
|
assert(errcode == sqlite3.OK, errcode)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
6
test.lua
6
test.lua
@ -310,10 +310,10 @@ test_logfile(false)
|
|||||||
do
|
do
|
||||||
local sqlite3 = persistence.sqlite3(require"lsqlite3")
|
local sqlite3 = persistence.sqlite3(require"lsqlite3")
|
||||||
local p = sqlite3.new("database.test.sqlite3", {})
|
local p = sqlite3.new("database.test.sqlite3", {})
|
||||||
p:init()
|
p:init()
|
||||||
p:rewrite()
|
p:rewrite()
|
||||||
p:set_root("key", "value")
|
p:set_root("key", "value")
|
||||||
assert(p.root.key == "value")
|
assert(p.root.key == "value")
|
||||||
p:set_root("other key", "other value")
|
p:set_root("other key", "other value")
|
||||||
p:set_root("key", "other value")
|
p:set_root("key", "other value")
|
||||||
p:set_root("key", nil)
|
p:set_root("key", nil)
|
||||||
|
Loading…
Reference in New Issue
Block a user