Logic Machine Forum
filter table data NON DB - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: filter table data NON DB (/showthread.php?tid=3409)



filter table data NON DB - Frank68 - 09.06.2021

It is possible to filter id atts in a non-DB table

if I have a table from which I take data with

PowTable = storage.get ('MyPowerLog', {})

can I make a select on the data?

Thanks so much


RE: filter table data NON DB - admin - 10.06.2021

You need to filter the table manually in a "for" loop. In this example the result table is populated will all items where the time field is not older than 1 day (86400 seconds).
Code:
items = storage.get('MyPowerLog', {})
result = {}

now = os.time()
mintime = now - 86400

for _, item in ipairs(items) do
  if item.time >= mintime then
    table.insert(result, item)
  end
end

log(result)