{"id":24561843,"url":"https://github.com/alenap93/kysely-cache","last_synced_at":"2025-03-16T22:44:37.304Z","repository":{"id":273083510,"uuid":"918183161","full_name":"alenap93/kysely-cache","owner":"alenap93","description":"Cache layer for Kysely","archived":false,"fork":false,"pushed_at":"2025-03-08T04:12:28.000Z","size":865,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-08T05:18:57.270Z","etag":null,"topics":["cache","database","kysely","lru","query-builder","sql"],"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/alenap93.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":"2025-01-17T12:15:07.000Z","updated_at":"2025-03-08T04:12:28.000Z","dependencies_parsed_at":"2025-03-08T05:28:40.290Z","dependency_job_id":null,"html_url":"https://github.com/alenap93/kysely-cache","commit_stats":null,"previous_names":["alenap93/kysely-cache"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alenap93%2Fkysely-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alenap93%2Fkysely-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alenap93%2Fkysely-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alenap93%2Fkysely-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alenap93","download_url":"https://codeload.github.com/alenap93/kysely-cache/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243945535,"owners_count":20372894,"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":["cache","database","kysely","lru","query-builder","sql"],"created_at":"2025-01-23T08:46:22.767Z","updated_at":"2025-03-16T22:44:37.296Z","avatar_url":"https://github.com/alenap93.png","language":"TypeScript","funding_links":[],"categories":["Addons"],"sub_categories":[],"readme":"\n# kysely-cache\n\n[![CI](https://github.com/alenap93/kysely-cache/actions/workflows/tests.yml/badge.svg)](https://github.com/alenap93/kysely-cache/actions/workflows/tests.yml)\n[![NPM version](https://img.shields.io/npm/v/kysely-cache.svg?style=flat)](https://www.npmjs.com/package/kysely-cache)\n[![NPM downloads](https://img.shields.io/npm/dm/kysely-cache.svg?style=flat)](https://www.npmjs.com/package/kysely-cache)\n[![js-prettier-style](https://img.shields.io/badge/code%20style-prettier-brightgreen.svg?style=flat)](https://prettier.io/)\n\nKysely Cache plugin; with this plugin you can cache a query and make next queries faster, that will not go directly to the database, but will be getted from the cache.\nThis plugin has three different implementation **KyselyLRUSQLCache**, **KyselyLRUCache** and **KyselyLRUKeyVCache**.\n\n## Install\n\n```\nnpm i kysely kysely-cache\n```\n\n## Usage\n\n### KyselyLRUSQLCache\n\n**Description**\n\nThis cache stores data inside a DB (sqlite, mysql or postgres) and sets a cached query (and results) lifetime (ttl) and a maximum number of queries (and elements)\n\n**Options**\n\n- max:  *max number of items (query results) in cache, default 50*\n- ttl:  *time to live (milliseconds), default: 60000*\n- debounceTime:  *debounce time (ms) to wait for expired items check after single \"set\" value in cache, if 0 no check will be done after the set, default: 1000*\n- intervalCheckTime:  *interval time (ms) between each expired items check (further to check after the \"set\" value in cache), default: 60000*\n- dialect:  *Kysely Dialect, default: SQLite Dialect with in memory DB*\n- queryCompiler:  *sqlite, mysql or postgres, default: sqlite*\n\n**Api**\n\n- clear(): *clear the cache, return: Promise\\\u003cvoid\\\u003e*\n- destroy(): *clear the cache and release all resources and disconnects from the cache database, return: Promise\\\u003cvoid\\\u003e*\n- createCache(opts): *create the cache, return: Promise\\\u003cKyselyLRUSQLCache\\\u003cDB\\\u003e\\\u003e*\n- execute(queryBuilder: SelectQueryBuilder): *execute the query or return data from the cache as a list of items*\n- executeTakeFirst(queryBuilder: SelectQueryBuilder): *execute the query or return data from the cache, it return only the first element*\n- executeTakeFirstOrThrow(queryBuilder: SelectQueryBuilder, errorConstructor:  NoResultErrorConstructor): *execute the query or return data from the cache, it return only the first element, if no element will be found, it will throw an error*\n\n**How to use**\n\n    const sqliteDialect = new SqliteDialect({ database: new Database(':memory:')})\n    \n    const kyselyInstance = new Kysely\u003cDatabase\u003e({ dialect:  sqliteDialect })\n    \n    await kyselyInstance.schema\n    .createTable('person')\n    .addColumn('id', 'integer', (col) =\u003e col.primaryKey())\n    .addColumn('first_name', 'varchar(255)')\n    .addColumn('last_name', 'varchar(255)')\n    .addColumn('gender', 'varchar(255)')\n    .execute()\n    \n    await kyselyInstance\n    .insertInto('person')\n    .values({\n    first_name: 'Max',\n    last_name: 'Jack',\n    gender: 'man',\n    })\n    .execute()\n    \n    const kyselyLRUSQLCacheInstance = await KyselyLRUSQLCache.createCache\u003cDatabase\u003e(opt.config)\n    \n    const queryBuilderSelectFrom = kyselyInstance\n    .selectFrom('person')\n    .selectAll()\n    \n    const people = await kyselyLRUSQLCacheInstance.execute(queryBuilderSelectFrom)\n\n### KyselyLRUCache\n\n**Description**\n\nThis cache keeps data in memory (inside an object) and sets a cache query (and results) lifetime (ttl) and a maximum number of queries (and elements)\n\n**Options**\n\n- max:  *max number of items (query results) in cache, default 50*\n- ttl:  *time to live (milliseconds), default: 60000*\n\n**Api**\n\n- clear(): *clear the cache, return: void*\n- createCache(opts): *create the cache, return: KyselyLRUCache\\\u003cDB\\\u003e*\n- execute(queryBuilder: SelectQueryBuilder): *execute the query or return data from the cache as a list of items*\n- executeTakeFirst(queryBuilder: SelectQueryBuilder): *execute the query or return data from the cache, it return only the first element*\n- executeTakeFirstOrThrow(queryBuilder: SelectQueryBuilder, errorConstructor:  NoResultErrorConstructor): *execute the query or return data from the cache, it return only the first element, if no element will be found, it will throw an error*\n\n**How to use**\n\n    const sqliteDialect = new SqliteDialect( { database: new  Database(':memory:') } )\n    \n    const kyselyInstance = new Kysely\u003cDatabase\u003e( { dialect:  sqliteDialect } )\n    \n    await kyselyInstance.schema.createTable('person')\n    .addColumn('id', 'integer', (col) =\u003e  col.primaryKey())\n    .addColumn('first_name', 'varchar(255)')\n    .addColumn('last_name', 'varchar(255)')\n    .addColumn('gender', 'varchar(255)')\n    .execute()\n    \n    await kyselyInstance.insertInto('person').values( { first_name: 'Max', last_name: 'Jack', gender: 'man' } )\n    .execute()\n    \n    const kyselyLRUCacheInstance = KyselyLRUCache.createCache\u003cDatabase\u003e( { max: 50, ttl: 60000 } )\n    \n    const kyselySelectQueryBuilderOne = kyselyInstance.selectFrom('person').selectAll()\n    const persone = await KyselyLRUCacheInstance.executeTakeFirstOrThrow(kyselySelectQueryBuilderOne)\n\n### KyselyLRUKeyVCache\n\n**Description**\n\nThis cache keeps data using KeyV storage, with this cache you have to use KeyV options of the different stores\n\n***This cache needs KeyV!***\n\n    npm i --save keyv\n\n**Options**\n\n- store: *The storage adapter instance to be used by Keyv.*\n- ttl: *TTL, default: 60000*\n- compression: *Enable compression options*\n\n**Api**\n\n- clear(): *clear the cache, return: void*\n- disconnect(): *clear the cache and release all resources and disconnects from the cache database, return: Promise\\\u003cvoid\\\u003e*\n- createCache(opts): *create the cache, return: KyselyLRUKeyVCache\\\u003cDB\\\u003e*\n- execute(queryBuilder: SelectQueryBuilder): *execute the query or return data from the cache as a list of items*\n- executeTakeFirst(queryBuilder: SelectQueryBuilder): *execute the query or return data from the cache, it return only the first element*\n- executeTakeFirstOrThrow(queryBuilder: SelectQueryBuilder, errorConstructor:  NoResultErrorConstructor): *execute the query or return data from the cache, it return only the first element, if no element will be found, it will throw an error*\n\n**How to use**\n\n    const sqliteDialect = new SqliteDialect( { database: new  Database(':memory:') } )\n    \n    const kyselyInstance = new Kysely\u003cDatabase\u003e( { dialect:  sqliteDialect } )\n    \n    await kyselyInstance.schema.createTable('person')\n    .addColumn('id', 'integer', (col) =\u003e  col.primaryKey())\n    .addColumn('first_name', 'varchar(255)')\n    .addColumn('last_name', 'varchar(255)')\n    .addColumn('gender', 'varchar(255)')\n    .execute()\n    \n    await kyselyInstance.insertInto('person').values( { first_name: 'Max', last_name: 'Jack', gender: 'man' } )\n    .execute()\n    \n    const kyselyLRUKeyVCacheInstance = KyselyLRUKeyVCache.createCache\u003cDatabase\u003e( { ttl: 60000 } )\n    \n    const kyselySelectQueryBuilderOne = kyselyInstance.selectFrom('person').selectAll()\n    const persone = await kyselyLRUKeyVCacheInstance.executeTakeFirstOrThrow(kyselySelectQueryBuilderOne)\n\n\n## License\n\nLicensed under [MIT](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falenap93%2Fkysely-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falenap93%2Fkysely-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falenap93%2Fkysely-cache/lists"}