Skip to content

Instantly share code, notes, and snippets.

@ilhamsj
Last active January 30, 2020 23:18
Show Gist options
  • Save ilhamsj/d6296bdda1ff3f3bac0e79d14da278b7 to your computer and use it in GitHub Desktop.
Save ilhamsj/d6296bdda1ff3f3bac0e79d14da278b7 to your computer and use it in GitHub Desktop.
<script src="https://www.gstatic.com/firebasejs/7.7.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.7.0/firebase-database.js"></script>
<script>
// Your web app's Firebase configuration
var firebaseConfig = {
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
firebase.analytics();
// index
var getNotes = firebase.database().ref('notes/');
getNotes.on('value', function (snapshot) {
// var key = Object.keys(snapshot.val())
$.map(snapshot.val(), function (elementOrValue, indexOrKey) {
console.log(elementOrValue.title);
});
});
// store
store = (title, content) => {
firebase.database().ref("notes/").push({
title: title,
content: content,
});
}
// update
update = (title, content) => {
firebase.database().ref('notes/-Lzsf7HSEGUhGmJ3s4XD').update({
title,
content,
})
}
// destroy
destroy = () => {
firebase.database().ref('notes/-Lzsf7HSEGUhGmJ3s4XD').remove()
}
// store('Trying React Native', 'R is the strongest no sql for today')
// update('Trying Firebase', 'Firebase is the strongest no sql for today')
// destroy();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment