{"id":15814325,"url":"https://github.com/stevenvachon/sql-match","last_synced_at":"2025-03-14T20:32:08.842Z","repository":{"id":54301093,"uuid":"116713244","full_name":"stevenvachon/sql-match","owner":"stevenvachon","description":"Match a string using an SQL pattern.","archived":false,"fork":false,"pushed_at":"2020-06-01T01:00:57.000Z","size":32,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-06T04:24:17.000Z","etag":null,"topics":["match","nodejs","sql","wildcard"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stevenvachon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-08T18:33:33.000Z","updated_at":"2024-03-27T14:27:15.000Z","dependencies_parsed_at":"2022-08-13T11:20:58.078Z","dependency_job_id":null,"html_url":"https://github.com/stevenvachon/sql-match","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenvachon%2Fsql-match","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenvachon%2Fsql-match/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenvachon%2Fsql-match/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenvachon%2Fsql-match/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stevenvachon","download_url":"https://codeload.github.com/stevenvachon/sql-match/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221508325,"owners_count":16834649,"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":["match","nodejs","sql","wildcard"],"created_at":"2024-10-05T04:24:12.450Z","updated_at":"2024-10-26T07:20:49.218Z","avatar_url":"https://github.com/stevenvachon.png","language":"JavaScript","readme":"# sql-match [![NPM Version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coverage Status][coveralls-image]][coveralls-url] [![Dependency Monitor][greenkeeper-image]][greenkeeper-url]\n\n\u003e Match a string using an SQL pattern.\n\nThis library is basically a spec-compliant implementation of a `LIKE` between two strings:\n```sql\nSELECT 'string' LIKE '%ing';  --\u003e true\n```\n\nSupported features:\n* `%` wildcard sequence\n* `_` wildcard\n* `\\` escape\n\nUnsupported features:\n* Custom escape character (`ESCAPE`)\n* Ignored trailing spaces (MySQL's `=`)\n* Disallowed trailing escape character (PostgreSQL)\n* Collated international characters (`COLLATE` with `=`)\n* `[charlist]` patterns (Access and SQL Server)\n* `?` and `#` wildcards (Access)\n\n\n## Installation\n\n[Node.js](http://nodejs.org/) `\u003e= 8` is required. To install, type this at the command line:\n```shell\nnpm install sql-match\n```\n\n\n## Usage\n\n`isSQLMatch(pattern, testString)`\n\n```js\nconst {isSQLMatch} = require('sql-match');\n\nisSQLMatch('string', 'string');  //-\u003e true\n\nisSQLMatch('%ing', 'string');  //-\u003e true\nisSQLMatch('s%ng', 'string');  //-\u003e true\nisSQLMatch('str%', 'string');  //-\u003e true\n\nisSQLMatch('_tring', 'string');  //-\u003e true\nisSQLMatch('st__ng', 'string');  //-\u003e true\nisSQLMatch('strin_', 'string');  //-\u003e true\n```\n\nOptionally, you can create a reusable/cacheable regular expression to improve performance:\n```js\nconst {sqlToRegex} = require('sql-match');\n\nconst pattern = sqlToRegex('%ing');\n\n['string','stringing'].every(testString =\u003e pattern.test(testString));\n//-\u003e true\n```\n\n\n## Gotchas\n\nBecause JavaScript strings are interpreted, you may want to use [`String.raw`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/raw) to avoid some annoyances that reduce consistency with SQL.\n\nNon-wildcard escape sequences are possible:\n```js\nisSQLMatch('\\t', '\t');  //-\u003e true\nisSQLMatch('\\u0020', ' ');  //-\u003e true\n// or\nisSQLMatch(String.raw`\\t`, 't');  //-\u003e true\nisSQLMatch(String.raw`\\u0020`, 'u0020');  //-\u003e true\n```\n```sql\nSELECT 't' LIKE '\\t';  --\u003e true\nSELECT 'u0020' LIKE '\\u0020';  --\u003e true\n```\n\nMatching a literal wildcard will require you to escape the escape character:\n```js\nisSQLMatch('\\\\%trin\\\\_', '%trin_');  //-\u003e true\n// or\nisSQLMatch(String.raw`\\%trin\\_`, '%trin_');  //-\u003e true\n```\n```sql\nSELECT '%trin_' LIKE '\\%trin\\_';  --\u003e true\n```\n\nMatching a literal backslash will require you to escape the escaped escape character:\n```js\nisSQLMatch('\\\\\\\\string', '\\\\string');  //-\u003e true\n// or\nisSQLMatch(String.raw`\\\\string`, String.raw`\\string`);  //-\u003e true\n```\n```sql\nSELECT '\\string' LIKE '\\\\string';  --\u003e true\n```\n\n\n[npm-image]: https://img.shields.io/npm/v/sql-match.svg\n[npm-url]: https://npmjs.com/package/sql-match\n[travis-image]: https://img.shields.io/travis/stevenvachon/sql-match.svg\n[travis-url]: https://travis-ci.org/stevenvachon/sql-match\n[coveralls-image]: https://img.shields.io/coveralls/stevenvachon/sql-match.svg\n[coveralls-url]: https://coveralls.io/github/stevenvachon/sql-match\n[greenkeeper-image]: https://badges.greenkeeper.io/stevenvachon/sql-match.svg\n[greenkeeper-url]: https://greenkeeper.io/\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevenvachon%2Fsql-match","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstevenvachon%2Fsql-match","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevenvachon%2Fsql-match/lists"}