New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

pg-tsquery

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pg-tsquery

Parse user input into valid text search queries

  • 8.4.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
14K
increased by8.65%
Maintainers
1
Weekly downloads
 
Created
Source

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 options defaults values

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)]);

// or get a reusable instance
const {Tsquery} = require('pg-tsquery');

const parser = new Tsquery(/* options can be passed to override the defaults */);

// then process your input with parser.parse(str).toString()
inputsoutput
foo barfoo&bar
foo -bar, foo !bar, foo + !barfoo&!bar
foo bar,bip, foo+bar | bipfoo&bar|bip
foo (bar,bip), foo+(bar|bip)foo&(bar|bip)
foo>bar>bipfoo<->bar<->bip
foo*,bar* bana:*foo:*|bar:*&bana:*

Demo

Support

Please consider reporting issues and trying to create a pull request as well

Keywords

FAQs

Package last updated on 31 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc