LoopBack storage postgres component provides Node.js and REST APIs to manage binary contents using Postgres Large Object
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib add test for pg expose Apr 4, 2016
source expose pg object Apr 4, 2016
test
.gitignore First commit Jan 20, 2016
.travis.yml
README.md
gulpfile.coffee First commit Jan 20, 2016
gulpfile.js
package.json

README.md

loopback-component-storage-postgres

Build Status Dependency Status codecov.io

LoopBack storage postgres component provides Node.js and REST APIs to manage binary contents using Postgres Large Object

Installation

Install the storage component as usual for a Node package:

  npm install --save loopback-component-storage-postgres

Using it

Create a table to store file descriptions

  CREATE TABLE "my-table-to-store-files" (
    id SERIAL PRIMARY KEY,
    container TEXT NOT NULL,
    filename TEXT NOT NULL,
    mimetype TEXT,
    objectid INTEGER UNIQUE NOT NULL
  );

Edit you datasources.json and add the following part

"pg_file": {
  "name": "pg_file",
  "connector": "loopback-component-storage-postgres",
  "host": "localhost",
  "port": 5432,
  "database": "test",
  "table": "my-table-to-store-files",
  "username": "test-user",
  "password": "test-password"
}

And the you can use it as a datasource of your model.

API

Description Container model method REST URI
List all containers getContainers(callback) GET /api/<model>
Get information about specified container getContainer(container, callback) GET /api/<model>/:container
Create a new container createContainer(options, callback) PORT /api/<model>
Delete specified container destroyContainer(options, callback) DELETE /api/<model>/:container
List all files within specified container getFiles(container, callback) GET /api/<model>/:container/files
Get information for specified file within specified container getFile(container, file, callback) GET /api/<model>/:container/files/:file
Delete a file within a given container by name removeFile(container, file, callback) DELETE /api/<model>/:container/files/:file
Upload one or more files into the specified container upload(container, req, res, callback) POST /api/<model>/:container/upload
Download a file within specified container download(container, file, res, callback) GET /api/<model>/:container/download/:file