-
Notifications
You must be signed in to change notification settings - Fork 1
/
db.js
75 lines (73 loc) · 1.39 KB
/
db.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
75
import firebase from 'firebase';
const config = {
apiKey: 'AIzaSyB0ztjio3hW5x6UKMUH2fBtAwGdPgkVFC8',
authDomain: 'test-d3d42.firebaseapp.com',
databaseURL: 'https://test-d3d42.firebaseio.com',
projectId: 'test-d3d42',
storageBucket: 'test-d3d42.appspot.com',
messagingSenderId: '856945851988',
};
// initialinzing
export const app = firebase.initializeApp(config);
// insert
export const insert = (ref, data) => {
firebase
.database()
.ref(ref)
.set(data)
.then(() => {
console.log('Inserted');
})
.catch(error => {
console.log(error);
});
};
// Push
export const push = (ref, data) => {
firebase
.database()
.ref(ref)
.push(data)
.then(() => {
console.log('Pushed');
})
.catch(error => {
console.log(error);
});
};
// select
export const select = ref => {
firebase
.database()
.ref(ref)
.on('value', data => data.toJSON())
.then(data => {
console.log(data);
});
};
// update
export const update = (ref, data) => {
firebase
.database()
.ref(ref)
.update(data)
.then(() => {
console.log('Updated');
})
.catch(error => {
console.log(error);
});
};
// delete
export const remove = ref => {
firebase
.database()
.ref(ref)
.remove()
.then(() => {
console.log('Deleted');
})
.catch(error => {
console.log(error);
});
};