{"id":16039815,"url":"https://github.com/beartocode/prisma-cache-nosql","last_synced_at":"2025-04-05T05:42:40.778Z","repository":{"id":213313142,"uuid":"733570997","full_name":"BearToCode/prisma-cache-nosql","owner":"BearToCode","description":"📦 Cache Prisma queries results in a local NoSQL storage","archived":false,"fork":false,"pushed_at":"2023-12-21T07:28:05.000Z","size":234,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-04-24T14:57:54.511Z","etag":null,"topics":["acebase","cache","nosql","prisma","query"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/BearToCode.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-19T16:17:28.000Z","updated_at":"2024-08-20T12:50:38.778Z","dependencies_parsed_at":"2023-12-19T19:21:54.812Z","dependency_job_id":"97a62862-de19-42de-99ed-4b96f693204e","html_url":"https://github.com/BearToCode/prisma-cache-nosql","commit_stats":null,"previous_names":["beartocode/prisma-cache-nosql"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BearToCode%2Fprisma-cache-nosql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BearToCode%2Fprisma-cache-nosql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BearToCode%2Fprisma-cache-nosql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BearToCode%2Fprisma-cache-nosql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BearToCode","download_url":"https://codeload.github.com/BearToCode/prisma-cache-nosql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247294463,"owners_count":20915338,"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":["acebase","cache","nosql","prisma","query"],"created_at":"2024-10-08T23:08:10.184Z","updated_at":"2025-04-05T05:42:40.755Z","avatar_url":"https://github.com/BearToCode.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `prisma-cache-nosql`\n\n\u003cdiv\u003e\n\t\u003ca href=\"https://www.npmjs.com/package/prisma-cache-nosql\"\u003e\n\t\t\u003cimg alt=\"npm\" src=\"https://img.shields.io/npm/v/prisma-cache-nosql?logo=npm\u0026logoColor=white\"\u003e\n\t\u003c/a\u003e\n\t\u003ca href=\"https://github.com/BearToCode/prisma-cache-nosql/blob/master/LICENSE\"\u003e\n\t\t\u003cimg alt=\"GitHub License\" src=\"https://img.shields.io/github/license/BearToCode/prisma-cache-nosql?label=license\"\u003e\n\t\u003c/a\u003e\n\t\u003ca href=\"https://github.com/BearToCode/prisma-cache-nosql/actions/\"\u003e\n\t\t\u003cimg alt=\"GitHub Workflow Status (with event)\" src=\"https://img.shields.io/github/actions/workflow/status/BearToCode/prisma-cache-nosql/run-tests.yaml?label=tests\u0026logo=github\"\u003e\n\t\u003c/a\u003e\n\t\u003ca href=\"https://prettier.io/\"\u003e\n\t\t\u003cimg alt=\"Uses prettier\" src=\"https://img.shields.io/badge/code_style-prettier-ce00ff\"\u003e\n\t\u003c/a\u003e\n\t\u003ca href=\"https://github.com/commitizen/cz-cli\"\u003e\n\t\t\u003cimg alt=\"Uses commitizen\" src=\"https://img.shields.io/badge/🎇-commitizen-f71ef3\"\u003e\n\t\u003c/a\u003e\n\t\t\u003ca href=\"https://github.com/commitizen/cz-cli\"\u003e\n\t\t\u003cimg alt=\"Uses semantic release\" src=\"https://img.shields.io/badge/📦🚀-semantic_release-ff008e\"\u003e\n\t\u003c/a\u003e\n\u003c/div\u003e\n\n\u003cbr\u003e\n\nA Prisma extension to store queries results in a temporary NoSQL cache. Currently supported storage options are standard memory and [AceBase](https://github.com/appy-one/acebase).\n\n## Getting Started\n\n### Installation\n\nUsing `npm`:\n\n```\nnpm i prisma-cache-nosql\n```\n\n_If you want to use AceBase, install it as well:_\n\n```\nnpm i acebase\n```\n\n### Setup with RAM\n\n```ts\nimport { cache, adapterMemory } from 'prisma-cache-nosql';\n\nconst adapter = adapterMemory();\n\nconst prisma = new PrismaClient().$extends(\n\tcache({\n\t\tadapter\n\t})\n);\n```\n\n### Setup with AceBase\n\n```ts\nimport { cache, adapterAceBase } from 'prisma-cache-nosql';\n\nconst storage = new AceBase('cache_db');\nconst adapter = adapterAceBase(storage);\n\nawait db.ready();\n\nconst prisma = new PrismaClient().$extends(\n\tcache({\n\t\tadapter\n\t})\n);\n```\n\n## Configuration\n\nBy default, Prisma will work the same and no value will be cached. If you want to start using the cache, you need to provide some configuration, that may look like this:\n\n```ts\n{\n\t// If provided, the result of this query will be saved in cache.\n\t// Can also be set: true\n\tset: {\n\t\t// Time-To-Live in ms\n\t\tttl: 1000 * 60,\n\t},\n\t// If provided, a cached value will be used if a non expired one is found\n\t// Can also be get: true\n\tget: {\n\t\t// Max cache age in ms\n\t\tmax: 1000 * 60 * 5\n\t}\n}\n```\n\nThis can be done in three different scopes:\n\n### Global\n\nThis configuration has the less priority. It will be used where no others were specified.\n\n```ts\n// ...\n\nconst prisma = new PrismaClient().$extends(\n\tcache({\n\t\tdefault: {\n\t\t\t// Here\n\t\t}\n\t})\n);\n```\n\n### Per Model\n\nThis one will be used for a specific model.\n\n```ts\n// ...\n\nconst prisma = new PrismaClient().$extends(\n\tcache({\n\t\tmodels: {\n\t\t\tmyModel: {\n\t\t\t\t// Here\n\t\t\t}\n\t\t}\n\t})\n);\n```\n\n### Per Query\n\nThe most specific one, will be prioritized over all the others:\n\n```ts\nconst result = await prisma.model.findFirst({\n\tcache: {\n\t\t// Here\n\t}\n});\n```\n\n## Supported Methods\n\nThe following methods can be used with cache:\n\n- `findUnique`\n- `findUniqueOrThrow`\n- `findFirst`\n- `findFirstOrThrow`\n- `findMany`\n- `count`\n- `aggregate`\n- `groupBy`\n\n## API\n\n### `cache(opts)`\n\n- `adapter`: the storage adapter to use.\n- `logLevel`: determines the messages logged. Can be `debug`, `log`, `warn`, `error`.\n- `default`: default cache configuration.\n- `models`: models specific cache configuration.\n\n## Development\n\n### Runnings Tests\n\nSetup the tests db using `npm run test:push-schema` and generate Prisma test client with `npm run test:generate-client`.\n\nRun the tests using `npm run test`.\n\n### Committing\n\nPlease, commit using commitizen so that [semantic-release](https://github.com/semantic-release/semantic-release) will be able to automatically determine the new package version:\n\n```\ngit cz\n# or\nnpm run commit\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeartocode%2Fprisma-cache-nosql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeartocode%2Fprisma-cache-nosql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeartocode%2Fprisma-cache-nosql/lists"}