UNPKG

prisma-cache-nosql

Version:

<div> <a href="https://www.npmjs.com/package/prisma-cache-nosql"> <img alt="npm" src="https://img.shields.io/npm/v/prisma-cache-nosql?logo=npm&logoColor=white"> </a> <a href="https://github.com/BearToCode/prisma-cache-nosql/blob/master/LICENSE"> <i

36 lines (33 loc) 1.32 kB
import hash from 'object-hash'; function adapterAceBase(acebase) { return ({ logger }) => ({ async get({ model, operation, args }) { const queryHash = hash({ operation, args }); logger.module('acebase').debug(`Get hash ${queryHash}`); const snapshot = await acebase.ref(`cache/${model}/${queryHash}`).get(); if (snapshot.exists()) { logger.module('acebase').debug(`Found snapshot:`, snapshot.val()); const value = snapshot.val(); // If null was provided Acebase does not save it at all if (value.result === undefined) { value.result = null; } return snapshot.val(); } return null; }, async set({ model, operation, args }, value) { const queryHash = hash({ operation, args }); logger.module('acebase').debug(`Set hash ${queryHash}`); await acebase.ref(`cache/${model}/${queryHash}`).set(value); }, async clear(model) { await acebase.ref(`cache/${model}`).set(null); }, async clearAll() { await acebase.ref('cache').set(null); } }); } export { adapterAceBase }; //# sourceMappingURL=acebase.js.map