4.0.0 • Published 6 years ago

@matteo.collina/assets-pg v4.0.0

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

assets-pg

Manage Assets, with node and postgres

An asset can be in three states: 'wait', 'operational' and 'error'.

Install

npm install @matteo.collina/assets-pg --save

API

  • buildAssets()
  • assets.put()
  • assets.get()
  • assets.createSchema()
  • assets.dropSchema()

buildAssets(connectionString)

The factory for the assets module, you can just pass through a pg connection string.

Example:

var connString = 'postgres://localhost/assets_tests'
var assets = require('@matteo.collina/assets-pg')(connString)

assets.put(object, callback(err, asset))

Adds or updates an asset. An asset can have three properties:

  1. the 'id', which needs to be set only for existing assets
  2. the 'name'
  3. the 'status', which can be any of 'wait', 'operational' and 'error'.

Validation is provided by ajv, and a new createError.UnprocessableEntity() (from http-errors) with the ajv errors attached to the details.

The returned asset includes the id, if missing.


assets.get(id, callback(err, asset))

Fetches an assets, returns a new createError.NotFound() (from http-errors) if not present.


assets.createSchema(callback(err))

Create the schema in PostgreSQL for this module.


assets.dropSchema(callback(err))

Drop the schema in PostgreSQL for this module.


assets.end()

Ends the PG connection pool.

License

MIT