31 lines
738 B
JavaScript
31 lines
738 B
JavaScript
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 }
|
|
}
|
|
} |