postgres-large-object
Large object support for PostgreSQL clients using the postgres library.
The API of this library is exactly same with node-postgres-large-object and resembles the JDBC library for PostgreSQL.
Installation
npm install --save postgres-large-object
You will also need to install postgres library. Currently only test with postgres@beta
npm install --save postgres@beta
Some of the methods in this library require PostgreSQL 9.3 (server) and up:
- LargeObject.seek()
- LargeObject.tell()
- LargeObject.size()
- LargeObject.truncate()
All other methods should work on PostgreSQL 8.4 and up.
Large Objects
Large Objects in PostgreSQL lets you store files/objects up to 4 TiB in size. The main benefit of using Large Objects instead of a simple column is that the data can be read and written in chunks (e.g. as a stream), instead of having to load the entire column into memory.
Examples
library exposes a callback style interface (for backwards compatibility) and a promise style interface (see API Documentation). All functions that end with "Async" will return a promise
Reading a large object using a stream:
const postgres = const LargeObjectManager = const createWriteStream = const sql = // When working with Large Objects, always use a transactionsql
Creating a new large object using a stream and pg-promise:
const postgres = const LargeObjectManager = const createReadStream = const sql = // When working with Large Objects, always use a transactionsql
Testing
You can test this library by running:
npm install postgres-large-object
npm test
The test assumes that postgres://nodetest:nodetest@localhost/nodetest is a valid database. Or specify connection URL with environment variable POSTGRES_URL