Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mcollina/assets-pg
https://github.com/mcollina/assets-pg
Last synced: 13 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/mcollina/assets-pg
- Owner: mcollina
- License: mit
- Created: 2015-06-27T15:51:03.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-12-03T11:17:03.000Z (about 7 years ago)
- Last Synced: 2024-12-17T15:43:20.176Z (23 days ago)
- Language: JavaScript
- Size: 19.5 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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
```*
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.
-------------------------------------------------------
Ends the PG connection pool.
## License
MIT