Skip to content

boromisp/postgres-composite

Repository files navigation

postgres-composite tests

Parse and serialize postgres composite values

Install

npm install --save postgres-composite

yarn add postgres-composite

Usage

const { parse, serialize } = require('postgres-composite')

[...parse('(1,2,3)')]
// => ['1', '2', '3']

[...parse('(1,," 3")')]
// => ['1', null, ' 3']

[...parse('()')]
// => [null]

serialize(['1', '2', '3'])
// => '(1,2,3)'

serialize(['1', null, ' 3'])
// => '(1,," 3")'

API

parse(value: string): Iterable<string | null>

The value must match format produced by the Postgres' composite output routine. The behavior with other formats is undefined.

serialize(attributes: Iterable<string | null>): string

Throws RangeError on empty input.

License

MIT © Peter B (@boromisp)