-
Notifications
You must be signed in to change notification settings - Fork 9
/
database.js
74 lines (58 loc) · 1.18 KB
/
database.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const monk = require('monk');
const urls = monk(MONGODB_URI);
const db = urls.get('shortem')
db.createIndex({ slug: 1 }, { unique: true });
// MongoDB
class mongoDatabase {
constructor(data) {
}
async get(name) {
var data = await db.findOne({ slug: name });
if(data){
return data.url;
}
}
async set(name, value) {
return await db.insert({
url: value,
slug: name
});
}
async delete(name) {
return await db.remove({
slug: name
});
}
async list() {
var data = await db.find({ });
var list = [];
for(var i of data){
list.push(
`${i.slug}`
)
}
return list;
}
}
// Replit Database
/*
const Database = require('@replit/database');
const db = new Database();
class replitDatabase {
constructor(data) {
}
async get(name) {
return await db.get(name);
}
async set(name, value) {
return await db.set(name, value);
}
async delete(name) {
return await db.delete(name)
}
async list() {
return await db.list()
}
}
*/
module.exports = mongoDatabase;