Package Exports
- pg-tsquery
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (pg-tsquery) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Text-Search parser for PostgreSQL
Why?
Using pg's to_tsquery with user input can throw
There's plainto_tsquery but it's very limited (it just puts an AND between words)
This module allows to parse various user input operators:
- AND:
&+and\s+ - FOLLOWED_BY:
<><-><\d+> - OR:
,|or - NOT:
!- - SUBSTRING:
:* - parentheses:
()[]
Usage
const tsquery = require('pg-tsquery');
pool.query('SELECT * FROM tabby WHERE to_tsvector(col) @@ to_tsquery($1)', [tsquery(str)])| inputs | output |
|---|---|
foo bar |
foo&bar |
foo -bar, foo !bar, foo + !bar |
foo&!bar |
foo bar,bip, foo+bar | bip |
foo&bar|bip |
foo (bar,bip), foo+(bar|bip) |
foo&(bar|bip) |
foo<bar<->bip<2>sun |
foo<->bar<->bip<2>sun |
foo*,bar* bana:* |
foo:*|bar:*&bana:* |