Javascript
This commit is contained in:
31
server/db/db.js
Normal file
31
server/db/db.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import QuillDB from "../_/quilldb.js"
|
||||
|
||||
export default class Database extends QuillDB {
|
||||
|
||||
get = {
|
||||
user: (id) => {
|
||||
return this.nodes[id]
|
||||
},
|
||||
userByEmail: (email) => {
|
||||
for (const id of this.labels["User"]) {
|
||||
const user = this.get.user(id);
|
||||
if (user.email === email) {
|
||||
return { id, ...user }
|
||||
}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
}
|
||||
|
||||
generateUserID() {
|
||||
let id = this.labels["User"].length + 1;
|
||||
while (this.get.user(`user-${id}`)) {
|
||||
id++;
|
||||
}
|
||||
return `user-${id}`; // O(1) most of the time
|
||||
}
|
||||
|
||||
async getAll() {
|
||||
return { nodes: this.nodes }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user