@xfx/pg
v1.0.5
Published
- `Base` - provide default `init` function and `dsn` prop - `ArrayQuery` - execute query by `sql`, `values` and push rows to `out` port
Downloads
6
Readme
Postgresql nodes
Base
- provide defaultinit
function anddsn
propArrayQuery
- execute query bysql
,values
and push rows toout
port
Usage
ArrayQuery
'use strict'
const def = `
ticks(@xfx/time/Ticks) -> tasks(@xfx/pg/ArrayQuery) -> dispatch(./Dummy)
`
const props = {
ticks: {
interval: 5000
},
tasks: {
dsn: 'pg://u:p@host/dbname',
sql: `select * from generate_series(1,5,1) as t(id) limit $1`,
values: message => [ 2 ],
shiftBy: 2,
out: 'task'
}
}
build(def, props, {}, (err, flow) => {
flow.ticks.start.write()
})
Custom query node
// custom/SimpleQuery.node.js
module.exports = (args, env) => ({
base: '@xfx/pg/Base',
out_: 1,
_in(message, done) {
let sql = `select * from generate_series(1,5,1) as t(id) limit $1`
let values = [ 5 ]
this.__pool.query(sql, values, (error, res) => {
if (err) this.send('errors', { error, ...message })
else this.send('out', { rows: res.rows, ...message })
done()
})
}
})
// exp.flow.js
const def = `
ticks(@xfx/time/Ticks) -> tasks(./custom/SimpleQuery) -> dispatch(./Dummy)
`
const props = {
ticks: {
interval: 5000
},
tasks: {
dsn: 'pg://u:p@host/dbname',
}
}
build(def, props, {}, (err, flow) => {
flow.ticks.start.write()
})