123456789101112131415161718192021222324252627282930313233343536373839404142 |
- const db = require("../db.js");
- var CryptoJS = require('crypto-js');
- class CardsRepository {
- getByID(id) {
- return db.get('card:' + id);
- }
- getAllCards() {
- const results = [];
- return new Promise((res,rej) => {
- db.createReadStream({
- 'lt': 'card;',
- 'gt': 'card:'
- })
- .on('data', function (data) {
- console.log(data);
- results.push(data);
- })
- .on('error', function (err) {
- rej(err);
- })
- .on('close', function () {
- res(results);
- })
- .on('end', function () {
- });
- });
- }
- insert(id, data) {
- return db.put('card:' + id, data);
- }
- }
- let cardsRepository = null;
- function getSingleton() {
- return cardsRepository = (cardsRepository === null ? new CardsRepository(): userRepository);
- }
- module.exports = getSingleton();
|