3.0.0 • Published 7 years ago

@matteo.collina/timeseries-pg v3.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
7 years ago

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:

  1. the 'id', which needs to be set only for existing datapoints
  2. the 'asset', the asset from which this datapoint was acquired
  3. the 'value', a double that is the core of the datapoint
  4. the 'timestamp', which defaults to Date.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 datapoint
  • from: the minimum timestamp that will be considered, it must be a Date object
  • to: the maximum timestamp that will be considered, it must be a Date 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