Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

So, I wanted to move my local database to the Firebase by using Firebase's Realtime Database feature, however, I am struggling a bit as I am completely new to Firebase, and I am using the library called 'pyrebase'

What I am looking for:

database {
    userid1 {
        mail:"email1"
    },
    userid2 {
        mail:"email2"
    },
    userid3 {
        mail:"email3"}
        ...
}
  1. My first question is regarding to how to create such structure using Firebase?

  2. If such structure in the realtime database was accomplished, how to update any specific userid's data?

  3. If wanted any of the user to be deleted from the system by just using their userid, how is it done?

  4. And lastly, which is very important, if wanted to retrieve any of the user emails by looking through their userid, how is it retrieved?

What I have done so far:

  1. I have created the realtime database so far

  2. Downloaded and integrated the credentials

p.s literally in need of source related to Firebase.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
3.7k views
Welcome To Ask or Share your Answers For Others

1 Answer

So, I have finally figured out how to do all of these as shown below:

Inserting Data:

from firebase import firebase  
firebase = firebase.FirebaseApplication('https://xxxxx.firebaseio.com/', None)  
data =  { 'Name': 'Vivek',  
          'RollNo': 1,  
          'Percentage': 76.02  
          }  
result = firebase.post('/python-sample-ed7f7/Students/',data)  
print(result)  

Retrieving Data:

from firebase import firebase  
firebase = firebase.FirebaseApplication('https://xxxx.firebaseio.com/', None)  
result = firebase.get('/python-sample-ed7f7/Students/', '')  
print(result)

Updating Data:

from firebase import firebase  
firebase = firebase.FirebaseApplication('https://xxxx.firebaseio.com/', None)  
firebase.put('/python-sample-ed7f7/Students/-LAgstkF0DT5l0IRucvm','Percentage',79)   
print('updated')  

Delete Data:

from firebase import firebase  
firebase = firebase.FirebaseApplication('https://xxxx.firebaseio.com/', None)  
firebase.delete('/python-sample-ed7f7/Students/', '-LAgt5rGRlPovwNhOsWK')  
print('deleted') 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...