By default Balerter distributed with some preset modules, which placed in the modules
folder.
They are not needed for the balerter functional
Usage:
local h = require('h')
tableToMap(table, keyFieldName) table, error
Convert lua table to hash-table with keys as ‘keyFieldName’ value
An example:
table = {
{ date = '2020-01-01', id = 'a', name = 'aa'},
{ date = '2020-01-01', id = 'b', name = 'bb' },
...
}
res, err = h.tableToMap(table, 'id')
-- res
{
'a' = { date = '2020-01-01', id = 'a', name = 'aa'},
'b' = { date = '2020-01-01', id = 'b', name = 'bb' },
...
}
print(table)
Beautify print table or any value to the console
local t = { ['foo'] = { ['bar'] = 42 } }
h.print(t)
-- a result
{
foo = {
bar = 42
}
}
Allows encode/decode json
json = require('json')
json.encode({ 1, 2, 3, { x = 10 } }) -- Returns '[1,2,3,{"x":10}]'
json.decode('[1,2,3,{"x":10}]') -- Returns { 1, 2, 3, { x = 10 } }
Work with csv
An example:
local db = require('datasource.postgres.pg1')
local log = require('log')
local csv = require('csv')
local h = require('h')
res, err = db.query('SELECT * FROM users')
if err ~= nil then
log.error('query error: ' .. err)
return
end
h.print(csv.encode(res, ","))
See more on https://github.com/FourierTransformer/ftcsv