{"id":15024865,"url":"https://github.com/caub/pg-tsquery","last_synced_at":"2025-04-06T04:16:25.479Z","repository":{"id":22338166,"uuid":"95988099","full_name":"caub/pg-tsquery","owner":"caub","description":":mag: Parse user input into a valid PostgreSQL tsquery","archived":false,"fork":false,"pushed_at":"2024-01-31T18:59:10.000Z","size":72,"stargazers_count":58,"open_issues_count":2,"forks_count":8,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-30T03:07:56.965Z","etag":null,"topics":["parser","postgresql","search-in-text"],"latest_commit_sha":null,"homepage":"https://caub.github.io/pg-tsquery","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/caub.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-01T21:19:18.000Z","updated_at":"2024-04-30T15:29:37.000Z","dependencies_parsed_at":"2023-01-11T21:34:52.553Z","dependency_job_id":"650c24ba-09cd-4f1e-a281-4284327ffdb4","html_url":"https://github.com/caub/pg-tsquery","commit_stats":{"total_commits":73,"total_committers":2,"mean_commits":36.5,"dds":0.0273972602739726,"last_synced_commit":"76b388c42ab2081dde0b81f49c48de6d8bf80733"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caub%2Fpg-tsquery","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caub%2Fpg-tsquery/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caub%2Fpg-tsquery/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caub%2Fpg-tsquery/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/caub","download_url":"https://codeload.github.com/caub/pg-tsquery/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247430966,"owners_count":20937875,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["parser","postgresql","search-in-text"],"created_at":"2024-09-24T20:01:05.577Z","updated_at":"2025-04-06T04:16:25.376Z","avatar_url":"https://github.com/caub.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Text-Search parser for PostgreSQL\n\n[![npm version][npm-image]][npm-url]\n[![build status][travis-image]][travis-url]\n[![coverage status][codecov-image]][codecov-url]\n\n### Why?\n\nUsing 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.\n\nThis module allows customizable text-search operators: and, or, followedBy, not, prefix, parentheses, quoted text (same behavior than `websearch_to_tsquery`).\n\nSee the [options defaults values](index.js#L52-L61)\n\n### usage\n```js\nconst tsquery = require('pg-tsquery')(/* options can be passed to override the defaults */);\n\npool.query('SELECT * FROM tabby WHERE to_tsvector(col) @@ to_tsquery($1)', [tsquery(str)]);\n\n// or get a reusable instance\nconst {Tsquery} = require('pg-tsquery');\n\nconst parser = new Tsquery(/* options can be passed to override the defaults */);\n\n// then process your input with parser.parse(str).toString()\n```\n\n\n| inputs | output |\n| --- | --- |\n| `foo bar` | `foo\u0026bar` |\n| `foo -bar`, `foo !bar`, `foo + !bar` | `foo\u0026!bar` |\n| `foo bar,bip`, `foo+bar \\| bip` | `foo\u0026bar\\|bip` |\n| `foo (bar,bip)`, `foo+(bar\\|bip)` | `foo\u0026(bar\\|bip)` |\n| `foo\u003ebar\u003ebip` | `foo\u003c-\u003ebar\u003c-\u003ebip` |\n| `foo*,bar* bana:*` | `foo:*\\|bar:*\u0026bana:*` |\n\n\n### [Demo](https://caub.github.io/pg-tsquery)\n\n[npm-image]: https://img.shields.io/npm/v/pg-tsquery.svg?style=flat-square\n[npm-url]: https://www.npmjs.com/package/pg-tsquery\n[travis-image]: https://img.shields.io/travis/caub/pg-tsquery.svg?style=flat-square\n[travis-url]: https://travis-ci.org/caub/pg-tsquery\n[codecov-image]: https://img.shields.io/codecov/c/github/caub/pg-tsquery.svg?style=flat-square\n[codecov-url]: https://codecov.io/gh/caub/pg-tsquery\n\n### Support\n\nPlease consider reporting issues and trying to create a pull request as well\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaub%2Fpg-tsquery","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcaub%2Fpg-tsquery","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaub%2Fpg-tsquery/lists"}