@matteo.collina/timeseries-pg
v3.0.0
Published
Manage a timeseries using a module, with node and postgres
Downloads
5
Readme
timeseries-pg
Manage timeseries, with node and postgres
An datapoint can be in three states: 'wait'
, 'operational'
and
'error'
.
Install
npm install @matteo.collina/timeseries-pg --save
API
- buildTimeseries()
- timeseries.put()
- timeseries.createReadStream()
- timeseries.createSchema()
- timeseries.dropSchema()
buildtimeseries(connectionString)
The factory for the timeseries module, you can just pass through a pg connection string.
Example:
var connString = 'postgres://localhost/timeseries_tests'
var timeseries = require('@matteo.collina/timeseries-pg')(connString)
timeseries.put(object, callback(err, datapoint))
Adds or updates an datapoint. An datapoint can have three properties:
- the
'id'
, which needs to be set only for existing datapoints - the
'asset'
, the asset from which this datapoint was acquired - the
'value'
, a double that is the core of the datapoint - the
'timestamp'
, which defaults toDate.now()
Validation is provided by Joi, and a Joi error object will be provided in case of validation errors.
The returned datapoint includes the id
and timestamp
, if missing.
timeseries.createReadStream(opts)
Returns a Readable Stream that returns the data points.
Acceptable options are:
asset
: specify the asset that generated the datapointfrom
: the minimum timestamp that will be considered, it must be aDate
objectto
: the maximum timestamp that will be considered, it must be aDate
object
timeseries.createSchema(callback(err))
Create the schema in PostgreSQL for this module.
timeseries.dropSchema(callback(err))
Drop the schema in PostgreSQL for this module.
License
MIT