Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@resolid/cache-manager-sqlite

Package Overview
Dependencies
Maintainers
0
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@resolid/cache-manager-sqlite - npm Package Compare versions

Comparing version 5.1.5 to 5.1.6

1

dist/index.d.ts

@@ -10,2 +10,3 @@ import Database from 'better-sqlite3';

type SqliteStore = Store & {
name: string;
get client(): ReturnType<typeof Database>;

@@ -12,0 +13,0 @@ };

2

dist/index.js

@@ -11,4 +11,4 @@ import R from 'better-sqlite3';

CREATE INDEX IF NOT EXISTS idx_expired_caches ON ${s}(expiredAt);
`);let m=a.prepare(`SELECT * FROM ${s} WHERE cacheKey = ?`),S=a.prepare(`SELECT * FROM ${s} WHERE cacheKey IN (SELECT value FROM json_each(?))`),f=a.prepare(`INSERT OR REPLACE INTO ${s}(cacheKey, cacheData, createdAt, expiredAt) VALUES (?, ?, ?, ?)`),g=a.prepare(`DELETE FROM ${s} WHERE cacheKey = ?`),T=a.prepare(`DELETE FROM ${s} WHERE cacheKey IN (SELECT value FROM json_each(?))`),y=a.prepare(`SELECT cacheKey FROM ${s} WHERE cacheKey LIKE ? AND (expiredAt = -1 OR expiredAt > ?)`),A=a.prepare(`DELETE FROM ${s} WHERE expiredAt != -1 AND expiredAt < ?`),O=a.prepare(`DELETE FROM ${s}`),d=(...t)=>{let r=l(),n=!1,e=t.length>=3?S.all(JSON.stringify(t)).map(c=>{if(c.expiredAt!==-1&&c.expiredAt<r){n=!0;return}return c}).filter(c=>c!==void 0):t.map(c=>{let i=m.get(c);if(i!==void 0&&i.expiredAt!==-1&&i.expiredAt<r){n=!0;return}return i}).filter(c=>c!==void 0);return n&&process.nextTick(()=>A.run(r)),e},p=(...t)=>{if(t.length>=3)T.run(JSON.stringify(t));else for(let r of t)g.run(r);},E=(t,r)=>{let n=r??o?.ttl,e=l(),c=n!=null&&n!=0?e+n:-1;for(let i of t){if(!u(i[1]))throw new Error(`no cacheable value ${JSON.stringify(i[1])}`);f.run(i[0],JSON.stringify(i[1]),e,c);}};return {del(t){return new Promise((r,n)=>{try{p(t),r();}catch(e){n(e);}})},get(t){return new Promise((r,n)=>{try{let e=d(t);e.length==0?r(void 0):r(JSON.parse(e[0].cacheData));}catch(e){n(e);}})},keys(t){return new Promise((r,n)=>{try{let e=y.all(t?.replaceAll("*","%")??"%",l()).map(c=>c.cacheKey);r(e);}catch(e){n(e);}})},mdel(...t){return new Promise((r,n)=>{try{p(...t),r();}catch(e){n(e);}})},mget(...t){return new Promise((r,n)=>{try{let e=d(...t).map(i=>JSON.parse(i.cacheData)),c=t.length-e.length;r(c?e.concat(Array(c).fill(void 0)):e);}catch(e){n(e);}})},mset(t,r){return new Promise((n,e)=>{try{E(t,r),n();}catch(c){e(c);}})},reset(){return new Promise((t,r)=>{try{O.run(),t();}catch(n){r(n);}})},set(t,r,n){return new Promise((e,c)=>{try{E([[t,r]],n),e();}catch(i){c(i);}})},ttl(t){return new Promise((r,n)=>{try{let e=d(t);e.length==0?r(-2):r(e[0].expiredAt==-1?-1:e[0].expiredAt-l());}catch(e){n(e);}})},get client(){return a}}};
`);let m=a.prepare(`SELECT * FROM ${s} WHERE cacheKey = ?`),S=a.prepare(`SELECT * FROM ${s} WHERE cacheKey IN (SELECT value FROM json_each(?))`),f=a.prepare(`INSERT OR REPLACE INTO ${s}(cacheKey, cacheData, createdAt, expiredAt) VALUES (?, ?, ?, ?)`),g=a.prepare(`DELETE FROM ${s} WHERE cacheKey = ?`),T=a.prepare(`DELETE FROM ${s} WHERE cacheKey IN (SELECT value FROM json_each(?))`),y=a.prepare(`SELECT cacheKey FROM ${s} WHERE cacheKey LIKE ? AND (expiredAt = -1 OR expiredAt > ?)`),A=a.prepare(`DELETE FROM ${s} WHERE expiredAt != -1 AND expiredAt < ?`),O=a.prepare(`DELETE FROM ${s}`),d=(...t)=>{let r=l(),n=!1,e=t.length>=3?S.all(JSON.stringify(t)).map(c=>{if(c.expiredAt!==-1&&c.expiredAt<r){n=!0;return}return c}).filter(c=>c!==void 0):t.map(c=>{let i=m.get(c);if(i!==void 0&&i.expiredAt!==-1&&i.expiredAt<r){n=!0;return}return i}).filter(c=>c!==void 0);return n&&process.nextTick(()=>A.run(r)),e},p=(...t)=>{if(t.length>=3)T.run(JSON.stringify(t));else for(let r of t)g.run(r);},E=(t,r)=>{let n=r??o?.ttl,e=l(),c=n!=null&&n!=0?e+n:-1;for(let i of t){if(!u(i[1]))throw new Error(`no cacheable value ${JSON.stringify(i[1])}`);f.run(i[0],JSON.stringify(i[1]),e,c);}};return {name:"sqlite",del(t){return new Promise((r,n)=>{try{p(t),r();}catch(e){n(e);}})},get(t){return new Promise((r,n)=>{try{let e=d(t);e.length==0?r(void 0):r(JSON.parse(e[0].cacheData));}catch(e){n(e);}})},keys(t){return new Promise((r,n)=>{try{let e=y.all(t?.replaceAll("*","%")??"%",l()).map(c=>c.cacheKey);r(e);}catch(e){n(e);}})},mdel(...t){return new Promise((r,n)=>{try{p(...t),r();}catch(e){n(e);}})},mget(...t){return new Promise((r,n)=>{try{let e=d(...t).map(i=>JSON.parse(i.cacheData)),c=t.length-e.length;r(c?e.concat(Array(c).fill(void 0)):e);}catch(e){n(e);}})},mset(t,r){return new Promise((n,e)=>{try{E(t,r),n();}catch(c){e(c);}})},reset(){return new Promise((t,r)=>{try{O.run(),t();}catch(n){r(n);}})},set(t,r,n){return new Promise((e,c)=>{try{E([[t,r]],n),e();}catch(i){c(i);}})},ttl(t){return new Promise((r,n)=>{try{let e=d(t);e.length==0?r(-2):r(e[0].expiredAt==-1?-1:e[0].expiredAt-l());}catch(e){n(e);}})},get client(){return a}}};
export { x as sqliteStore };
{
"name": "@resolid/cache-manager-sqlite",
"version": "5.1.5",
"version": "5.1.6",
"description": "A new SQLite store for cache-manager",

@@ -18,3 +18,3 @@ "keywords": ["cache-manager", "sqlite", "better-sqlite3"],

"test": "vitest --ui",
"check": "biome check --apply ./src"
"check": "biome check --write ./src"
},

@@ -37,15 +37,15 @@ "main": "./dist/index.cjs",

"devDependencies": {
"@biomejs/biome": "^1.7.2",
"@biomejs/biome": "^1.8.3",
"@faker-js/faker": "^8.4.1",
"@types/better-sqlite3": "^7.6.10",
"@types/better-sqlite3": "^7.6.11",
"@vitest/ui": "^1.6.0",
"better-sqlite3": "^9.6.0",
"cache-manager": "^5.5.2",
"tsup": "^8.0.2",
"typescript": "^5.4.5",
"better-sqlite3": "^11.1.2",
"cache-manager": "^5.7.1",
"tsup": "^8.1.0",
"typescript": "^5.5.3",
"vitest": "^1.6.0"
},
"peerDependencies": {
"better-sqlite3": "^9.6.0",
"cache-manager": "^5.5.2"
"better-sqlite3": "^11.1.2",
"cache-manager": "^5.7.1"
},

@@ -52,0 +52,0 @@ "repository": {

@@ -26,11 +26,18 @@ # SQLite store for cache manager

```js
import {sqliteStore} from '@resolid/cache-manager-sqlite';
import {createCache} from 'cache-manager';
import {join} from 'node:path';
import { sqliteStore } from '@resolid/cache-manager-sqlite';
import cacheManager,{ createCache } from "cache-manager";
import { join } from 'node:path';
// SQLite :memory: cache store
const memStoreCache = cacheManager.caching(sqliteStore({cacheTableName: 'caches'}));
const memStoreCache = await cacheManager.caching(sqliteStore({cacheTableName: 'caches'}));
// On disk cache on caches table
const sqliteStoreCache = cacheManager.caching(sqliteStore({sqliteFile: join(process.cwd(), 'cache.sqlite3'), cacheTableName: 'caches'}))
const sqliteStoreCache = await cacheManager.caching(sqliteStore({sqliteFile: join(process.cwd(), 'cache.sqlite3'), cacheTableName: 'caches'}));
// SQLite :memory: cache store sync version
const memStoreCache = createCache(sqliteStore({cacheTableName: 'caches'}));
// On disk cache on caches table sync version
const sqliteStoreCache = createCache(sqliteStore({sqliteFile: join(process.cwd(), 'cache.sqlite3'), cacheTableName: 'caches'}))
```

@@ -37,0 +44,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc