Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mcollina/assets-pg


https://github.com/mcollina/assets-pg

Last synced: 13 days ago
JSON representation

Awesome Lists containing this project

README

        

# 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](http:/npm.im/pg) connection string.

Example:

```js
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](http://npm.im/ajv), and a `new
createError.UnprocessableEntity()` (from [http-errors](https://www.npmjs.com/package/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](https://www.npmjs.com/package/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