Repository navigation
Expand file tree
/
Copy pathfetch.lua
More file actions
57 lines (47 loc) · 1.65 KB
/
Copy pathfetch.lua
File metadata and controls
57 lines (47 loc) · 1.65 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
-- FROM SECTION accounts, GET username, WHERE id IS 5
function fetchData(fromSection, values, whereData, whereValue)
-- fromSection: str, values: table, whereName: str, whereValue: str
buildConnection()
if not whereData then
whereData = ''
end
if not whereValue then
whereValue = ''
end
local sectionContent = dbFileContent['dbcontent'][fromSection]
local baseStructure = sectionContent['baseStructure']
local indexes = {}
local condition = false
if whereData ~= '' and whereValue ~= '' then
condition = true
local whereDataIndex = table.index(baseStructure, whereData)
condition = { whereDataIndex, whereValue }
end
for _, v in pairs(values) do
local index = table.index(baseStructure, v)
if index then
table.insert(indexes, index)
end
end
local returnValues = {}
for key, value in pairs(sectionContent) do
if key ~= 'baseStructure' then
if condition ~= false then
if (value[condition[1]] == condition[2]) then
local section = {}
for i, j in pairs(indexes) do
table.insert(section, value[j])
end
table.insert(returnValues, section)
end
else
local section = {}
for i, j in pairs(indexes) do
table.insert(section, value[j])
end
table.insert(returnValues, section)
end
end
end
return returnValues;
end