npm

npm’s 2019 JavaScript ecosystem survey analysis is now available!Get your copy here »

pg-tsquery

8.0.4 • Public • Published

Text-Search parser for PostgreSQL

npm version build status coverage status

Why?

Using pg's to_tsquery directly with user input can throw errors. plainto_tsquery sanitizes the user input, but it's very limited (it just puts an and between words), websearch_to_tsquery extends this behavior a little further only between double-quotes, with followedBy operator and negations.

This module allows customizable text-search operators: and, or, followedBy, not, prefix, parentheses, quoted text (same behavior than websearch_to_tsquery).

See the full options and defaults

Usage

const tsquery = require('pg-tsquery')(/* options can be passed to override the defaults */);
 
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 foo<->bar<->bip
foo*,bar* bana:* foo:*\|bar:*&bana:*

Demo

install

npm i pg-tsquery

Downloadsweekly downloads

1,088

version

8.0.4

license

ISC

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability