initial commit
[urlittler] / src / db / base.js
1 'use strict';
2
3 const common = require('../common');
4 const DBErrors = require('./errors');
5
6 const _fileScope = common.fileScope(__filename);
7
8 class BaseDatabase {
9 constructor(logger) {
10 this.logger = logger;
11 }
12
13 static _camelfy(snakeCase, delim = '_') {
14 if (!snakeCase || typeof snakeCase.split !== 'function') {
15 return undefined;
16 }
17 const words = snakeCase.split(delim);
18 return [
19 words.shift(),
20 ...words.map((word) => word.charAt(0).toUpperCase() + word.slice(1)),
21 ].join('');
22 }
23
24 _notImplemented(method, args) {
25 const _scope = _fileScope(method);
26 this.logger.error(_scope, 'abstract method called', Array.from(args));
27 throw new DBErrors.NotImplemented();
28 }
29
30 async context(fn) {
31 this._notImplemented('context', { fn });
32 }
33
34 async transaction(dbCtx, fn) {
35 this._notImplemented('transaction', { dbCtx, fn });
36 }
37
38 async getAuthById(dbCtx, id) {
39 this._notImplemented('getAuthById', { dbCtx, id });
40 }
41
42 async insertLink(dbCtx, id, url, authToken) {
43 this._notImplemented('insertLink', { dbCtx, id, url, authToken });
44 }
45
46 async getLinkById(dbCtx, id) {
47 this._notImplemented('getLinkById', { dbCtx, id });
48 }
49
50 async getLinkByUrl(dbCtx, url) {
51 this._notImplemented('getLinkByUrl', { dbCtx, url });
52 }
53
54 async accessLink(dbCtx, id) {
55 this._notImplemented('accessLink', { dbCtx, id });
56 }
57
58 async expireLink(dbCtx, id, expires) {
59 this._notImplemented('expireLink', { dbCtx, id, expires });
60 }
61
62 async updateLink(dbCtx, id, url) {
63 this._notImplemented('updateLink', { dbCtx, id, url });
64 }
65
66 async getAllLinks(dbCtx) {
67 this._notImplemented('getAllLinks', { dbCtx });
68 }
69
70 }
71
72 module.exports = BaseDatabase;