Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mcollina/timeseries-pg
Store a time series in postgresql
https://github.com/mcollina/timeseries-pg
Last synced: 2 months ago
JSON representation
Store a time series in postgresql
- Host: GitHub
- URL: https://github.com/mcollina/timeseries-pg
- Owner: mcollina
- License: mit
- Created: 2015-06-30T14:15:08.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-11-17T15:55:39.000Z (about 7 years ago)
- Last Synced: 2024-05-02T01:06:03.200Z (8 months ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 3
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
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
```*
buildTimeseries()
*timeseries.put()
*timeseries.createReadStream()
*timeseries.createSchema()
*timeseries.dropSchema()
-------------------------------------------------------
### buildtimeseries(connectionString)The factory for the timeseries module, you can just pass through a
[pg](http:/npm.im/pg) connection string.Example:
```js
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](http://npm.im/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](https://nodejs.org/api/stream.html#stream_class_stream_readable) 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