You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.6 KiB

11 months ago
  1. const prisma = require("../utils/prisma");
  2. const CacheData = {
  3. new: async function (inputs = {}) {
  4. try {
  5. const cache = await prisma.cache_data.create({
  6. data: inputs,
  7. });
  8. return { cache, message: null };
  9. } catch (error) {
  10. console.error(error.message);
  11. return { cache: null, message: error.message };
  12. }
  13. },
  14. get: async function (clause = {}, limit = null, orderBy = null) {
  15. try {
  16. const cache = await prisma.cache_data.findFirst({
  17. where: clause,
  18. ...(limit !== null ? { take: limit } : {}),
  19. ...(orderBy !== null ? { orderBy } : {}),
  20. });
  21. return cache || null;
  22. } catch (error) {
  23. console.error(error.message);
  24. return null;
  25. }
  26. },
  27. delete: async function (clause = {}) {
  28. try {
  29. await prisma.cache_data.deleteMany({
  30. where: clause,
  31. });
  32. return true;
  33. } catch (error) {
  34. console.error(error.message);
  35. return false;
  36. }
  37. },
  38. where: async function (clause = {}, limit = null, orderBy = null) {
  39. try {
  40. const caches = await prisma.cache_data.findMany({
  41. where: clause,
  42. ...(limit !== null ? { take: limit } : {}),
  43. ...(orderBy !== null ? { orderBy } : {}),
  44. });
  45. return caches;
  46. } catch (error) {
  47. console.error(error.message);
  48. return [];
  49. }
  50. },
  51. count: async function (clause = {}) {
  52. try {
  53. const count = await prisma.cache_data.count({
  54. where: clause,
  55. });
  56. return count;
  57. } catch (error) {
  58. console.error(error.message);
  59. return 0;
  60. }
  61. },
  62. };
  63. module.exports = { CacheData };