Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Firebase(Realtime Database)について

S-cubism
November 24, 2017

Firebase(Realtime Database)について

S-cubism

November 24, 2017
Tweet

More Decks by S-cubism

Other Decks in Technology

Transcript

  1. σʔλͷಡΈࠐΈ w 'JSFCBTFEBUBCBTF3FGFSFODFͷΠϯελϯεΛੜ੒ // Get a reference to the database

    service this.database = firebase.database(); w ϦιʔεͷύεΛࢦఆ this.messagesRef = this.database.ref(‘messages'); w ΠϯελϯεʹΠϕϯτϦεφʔΛ௥Ճ this.messagesRef.on('child_added', setMessage); //child_added͸ࢦఆͨ͠ύεʹ৽͍͠σʔλ͕௥Ճ͞Εͨ৔߹ʹ࣮ߦ͞ΕΔ
  2. σʔλͷॻ͖ࠐΈ w ಉ͘͡'JSFCBTFʹର͢ΔϦϑΝϨϯεΠϯελϯεΛੜ੒ w TFU Ͱطଘͷσʔλͷஔ׵Λߦ͏ function writeUserData(userId, name, email,

    imageUrl) { firebase.database().ref('users/' + userId).set({ username: name, email: email, profile_picture : imageUrl }); } w QVTI Λ࢖༻͢Δͱɺॻ͖ࠐΈ࣌ʹҰҙͷ*%͕ੜ੒͞Εɺڝ߹Λ൐Θͣʹෳ਺ͷΫϥΠ Ξϯτ͕ॻ͖ࠐΈΛߦ͏͜ͱ͕Ͱ͖Δ this.messagesRef.push({ name: currentUser.displayName, text: this.messageInput.value }).then(function() { }).catch(function(error) { console.error('Error writing new message to Firebase Database', error); });