{"id":15390292,"url":"https://github.com/gajus/slonik-interceptor-query-cache","last_synced_at":"2026-03-07T14:01:27.400Z","repository":{"id":57363298,"uuid":"219158746","full_name":"gajus/slonik-interceptor-query-cache","owner":"gajus","description":"Caches Slonik query results.","archived":false,"fork":false,"pushed_at":"2024-05-07T18:29:16.000Z","size":662,"stargazers_count":13,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-15T21:40:53.628Z","etag":null,"topics":["cache","postgresql","slonik"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gajus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","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},"funding":{"github":"gajus","patreon":"gajus"}},"created_at":"2019-11-02T13:36:55.000Z","updated_at":"2024-10-30T20:06:29.000Z","dependencies_parsed_at":"2024-05-07T19:49:40.281Z","dependency_job_id":null,"html_url":"https://github.com/gajus/slonik-interceptor-query-cache","commit_stats":{"total_commits":48,"total_committers":1,"mean_commits":48.0,"dds":0.0,"last_synced_commit":"34fed5199995247437fc3b3d5aa0d8215f55299b"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/gajus/slonik-interceptor-query-cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gajus%2Fslonik-interceptor-query-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gajus%2Fslonik-interceptor-query-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gajus%2Fslonik-interceptor-query-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gajus%2Fslonik-interceptor-query-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gajus","download_url":"https://codeload.github.com/gajus/slonik-interceptor-query-cache/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gajus%2Fslonik-interceptor-query-cache/sbom","scorecard":{"id":417381,"data":{"date":"2025-08-11","repo":{"name":"github.com/gajus/slonik-interceptor-query-cache","commit":"34fed5199995247437fc3b3d5aa0d8215f55299b"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.9,"checks":[{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/feature.yaml:1","Warn: no topLevel permission defined: .github/workflows/main.yaml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":3,"reason":"dependency not pinned by hash detected -- score normalized to 3","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/feature.yaml:8: update your workflow using https://app.stepsecurity.io/secureworkflow/gajus/slonik-interceptor-query-cache/feature.yaml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/feature.yaml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/gajus/slonik-interceptor-query-cache/feature.yaml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/feature.yaml:28: update your workflow using https://app.stepsecurity.io/secureworkflow/gajus/slonik-interceptor-query-cache/feature.yaml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/feature.yaml:32: update your workflow using https://app.stepsecurity.io/secureworkflow/gajus/slonik-interceptor-query-cache/feature.yaml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yaml:8: update your workflow using https://app.stepsecurity.io/secureworkflow/gajus/slonik-interceptor-query-cache/main.yaml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yaml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/gajus/slonik-interceptor-query-cache/main.yaml/main?enable=pin","Info:   0 out of   6 GitHub-owned GitHubAction dependencies pinned","Info:   3 out of   3 npmCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"License","score":9,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Warn: project license file does not contain an FSF or OSI license."],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":0,"reason":"24 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-h5c3-5r3r-rr8q","Warn: Project is vulnerable to: GHSA-rmvr-2pp2-xj38","Warn: Project is vulnerable to: GHSA-xx4v-prfh-6cgc","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-f6v4-cf5j-vf3w","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97","Warn: Project is vulnerable to: GHSA-9pv7-vfvm-6vr7","Warn: Project is vulnerable to: GHSA-rc47-6667-2j5j","Warn: Project is vulnerable to: GHSA-78xj-cgh5-2h22","Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j","Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36","Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3","Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7","Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q","Warn: Project is vulnerable to: GHSA-m95q-7qp3-xv42"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-19T00:15:59.328Z","repository_id":57363298,"created_at":"2025-08-19T00:15:59.328Z","updated_at":"2025-08-19T00:15:59.328Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30216489,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-07T13:35:13.914Z","status":"ssl_error","status_checked_at":"2026-03-07T13:35:13.569Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["cache","postgresql","slonik"],"created_at":"2024-10-01T15:05:15.523Z","updated_at":"2026-03-07T14:01:27.383Z","avatar_url":"https://github.com/gajus.png","language":"TypeScript","funding_links":["https://github.com/sponsors/gajus","https://patreon.com/gajus"],"categories":[],"sub_categories":[],"readme":"# slonik-interceptor-query-cache\n\n[![NPM version](http://img.shields.io/npm/v/slonik-interceptor-query-cache.svg?style=flat-square)](https://www.npmjs.org/package/slonik-interceptor-query-cache)\n[![Canonical Code Style](https://img.shields.io/badge/code%20style-canonical-blue.svg?style=flat-square)](https://github.com/gajus/canonical)\n[![Twitter Follow](https://img.shields.io/twitter/follow/kuizinas.svg?style=social\u0026label=Follow)](https://twitter.com/kuizinas)\n\nCaches [Slonik](https://github.com/gajus/slonik) query results.\n\n\u003e [!WARNING]\n\u003e Deprecated in favor of https://github.com/gajus/slonik monorepo.\n\n## Usage\n\nQuery cache interceptor is initialized using a custom storage service. The [Example Usage](#example-usage) documentation shows how to create a compatible storage service using [`node-cache`](https://www.npmjs.com/package/node-cache).\n\nWhich queries are cached is controlled using cache attributes. Cache attributes are comments starting with `-- @cache-` prefix. Only queries with cache attributes are cached (see [Cache attributes](#cache-attributes))\n\n## Behavior\n\n* Does not cache queries inside of a transaction.\n\n## Cache attributes\n\n#### `@cache-ttl`\n\n|Required|Format|Default|\n|---|---|---|\n|Yes|`/^d+$/`|N/A|\n\nNumber (in seconds) to cache the query for.\n\n#### `@cache-key`\n\n|Required|Format|Default|\n|---|---|---|\n|No|`/^[$A-Za-z0-9\\-_:]+$/`|`$bodyHash:$valueHash`|\n\nCache key that uniquely identifies the query.\n\nIf present, `$bodyHash` is substituted with the hash of the query (comments and white-spaces are stripped before hashing the query).\n\nIf present, `$valueHash` is substituted with the hash of the parameter values.\n\n#### `@cache-discard-empty`\n\n|Required|Format|Default|\n|---|---|---|\n|No|`/^(false\\|true)$/`|`false`|\n\nIf set to `true`, then `storage.set` is not invoked when query produces no results.\n\n### Example usage\n\nThis example shows how to create a compatible storage service using [`node-cache`](https://www.npmjs.com/package/node-cache).\n\n```js\nimport NodeCache from 'node-cache';\nimport {\n  createPool\n} from 'slonik';\nimport {\n  createQueryCacheInterceptor\n} from 'slonik-interceptor-query-cache';\n\nconst nodeCache = new NodeCache({\n  checkperiod: 60,\n  stdTTL: 60,\n  useClones: false,\n});\n\nconst pool = await createPool('postgres://', {\n  interceptors: [\n    createQueryCacheInterceptor({\n      storage: {\n        get: (query, cacheAttributes) =\u003e {\n          // Returning null results in the query being executed.\n          return cache.get(cacheAttributes.key) || null;\n        },\n        set: (query, cacheAttributes, queryResult) =\u003e {\n          cache.set(cacheAttributes.key, queryResult, cacheAttributes.ttl);\n        },\n      },\n    }),\n  ]\n});\n```\n\nThese are example queries:\n\n```ts\n// Caches the query results based on a combination of the query hash and the parameter value hash.\nawait connection.any(sql`\n  -- @cache-ttl 60\n  SELECT\n    id,\n    code_alpha_2\n  FROM country\n  WHERE\n    code_alpha_2 = ${countryCode}\n`);\n\n// Does not cache the result when query produces no results.\nawait connection.any(sql`\n  -- @cache-ttl 60\n  -- @cache-discard-empty true\n  SELECT\n    id,\n    code_alpha_2\n  FROM country\n  WHERE\n    code_alpha_2 = ${countryCode}\n`);\n\n// Caches the query results based only on the parameter value hash.\nawait connection.any(sql`\n  -- @cache-ttl 60\n  -- @cache-key $bodyHash\n  SELECT\n    id,\n    code_alpha_2\n  FROM country\n  WHERE\n    code_alpha_2 = ${countryCode}\n`);\n\n// Caches the query results using 'foo' key.\nawait connection.any(sql`\n  -- @cache-ttl 60\n  -- @cache-key foo\n  SELECT\n    id,\n    code_alpha_2\n  FROM country\n  WHERE\n    code_alpha_2 = ${countryCode}\n`);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgajus%2Fslonik-interceptor-query-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgajus%2Fslonik-interceptor-query-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgajus%2Fslonik-interceptor-query-cache/lists"}