Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Database {
- protected data: object;
- protected path: string;
- constructor() {
- this.data = {};
- }
- public ref(path: string): Database {
- if(!path) {
- throw new Error("Path is not set");
- }
- this.path = path;
- return this;
- }
- public push(obj: object): string {
- if(!obj) {
- throw new Error("Data object is missing");
- }
- const pushId: string= this.generatePushID();
- const key: string = this.path + '/' + pushId;
- this.data[key] = obj;
- return pushId;
- }
- public remove() {
- Object.keys(this.data).forEach((key) => {
- if(key.substr(0, this.path.length) === this.path) {
- delete this.data[key];
- }
- })
- }
- public once(continuation: any) {
- // tslint:disable-next-line:no-console
- console.log("Implement once");
- }
- // This should be updated to return more firebase like push id
- private generatePushID() {
- return Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 5);
- }
- }
- export default Database;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement