@matteo.collina/assets-pg

4.0.0 • Public • Published

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(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

Readme

Keywords

Package Sidebar

Install

npm i @matteo.collina/assets-pg

Weekly Downloads

2

Version

4.0.0

License

MIT

Last publish

Collaborators

  • matteo.collina