-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathfirebasehelper.js
43 lines (35 loc) · 1005 Bytes
/
firebasehelper.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
import * as firebase from 'firebase/app';
import 'firebase/database';
const config = {
apiKey: "AIzaSyArNJ3oSIk8Y3xPRqAL_0y4hZDwtwcHJ7Q",
authDomain: "songsim-99de9.firebaseapp.com",
databaseURL: "https://songsim-99de9.firebaseio.com",
storageBucket: "songsim-99de9.appspot.com",
messagingSenderId: "845644117075"
};
const SONG_PREFIX = '/songs/';
//const SONG_PREFIX = '/songsTest/';
class DBHelper {
constructor() {
this.loaded = false;
}
get db() {
// Lazy load this to avoid making unnecessary requests (I assume initialization
// involves network, but I could be wrong)
if (!this.loaded) {
firebase.initializeApp(config);
this._db = firebase.database();
this.loaded = true;
}
return this._db;
}
load(key) {
return this.db.ref(SONG_PREFIX + key).once('value');
}
push(verse) {
var newVerseRef = this.db.ref(SONG_PREFIX).push();
newVerseRef.set(verse.raw);
return newVerseRef;
}
}
export default DBHelper;