Repository navigation
Expand file tree
/
Copy pathinsertion.lua
More file actions
72 lines (53 loc) · 2.05 KB
/
Copy pathinsertion.lua
File metadata and controls
72 lines (53 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
-- TO SECTION accounts, VALUES(sth, sth, sth, sth), WHERE username IS 'Sthhere'
function insertData(toSection, values) -- values: table, toSection: str
buildConnection()
local sectionContent = dbFileContent['dbcontent'][toSection]
local sectionBaseStructure = sectionContent['baseStructure']
local id = math.random(1, 99999)
table.insert(sectionContent, id, {})
for key, baseStructure in pairs(sectionBaseStructure) do
if values[key] then
table.insert(sectionContent[id], key, values[key])
else
table.insert(sectionContent[id], key, baseStructure[3])
end
end
local dataJSON = toJSON(dbFileContent, true, 'tabs')
delContent()
fileWrite(dbFile, dataJSON)
fileFlush(dbFile)
buildConnection()
return true
end
-- UPDATE accounts, SET id TO 5, WHERE username is 'astreal'
function updateData(inSection, whichData, toValue, whereData, whereValue)
buildConnection()
local sectionContent = dbFileContent['dbcontent'][inSection]
local baseStructure = sectionContent['baseStructure']
local dataIndex = table.index(baseStructure, whichData)
local condition = false
if whereData ~= '' and whereValue ~= '' then
condition = true
local whereDataIndex = table.index(baseStructure, whereData)
condition = {whereDataIndex, whereValue}
end
for key, value in pairs(sectionContent) do
if key ~= 'baseStructure' then
if condition ~= false then
if (value[condition[1]] == condition[2]) then
value[dataIndex] = toValue
end
else
value[dataIndex] = toValue
end
sectionContent[key] = value
end
end
dbFileContent['dbcontent'][inSection] = sectionContent
local dataJSON = toJSON(dbFileContent, true, 'tabs')
delContent()
fileWrite(dbFile, dataJSON)
fileFlush(dbFile)
buildConnection()
return true
end