【GCP】FirebaseのCRUDの仕方メモ

cred = credentials.ApplicationDefault()
firebase_admin.initialize_app(cred, {
    'projectId': PROJECT_ID,
})
db = firestore.client()


def set_id(id: int):
    ''' create and update '''
    path = 'xxxxxx'
    db.document(path).set({
        "id": id
    })


def get_id():
    ''' get '''
    path = 'xxxxxx'
    db.document(path).get()
    if data.exists:
        return data.to_dict().get('id')


def get_ids():
    ''' get list '''
    path = 'xxxxxx'
    docs = db.collection(path).stream()
    for doc in docs:
        data = doc.to_dict()
        ......


def delete_id(id: int):
    ''' delete '''
    path = 'xxxxxx'
    doc = db.document(path).get()
    if doc.exists:
        db.document(path).delete()

One thought on “【GCP】FirebaseのCRUDの仕方メモ”

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です