0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【完全ガイド】DatabuttonのFirestoreインテグレーション

Last updated at Posted at 2025-04-17

🔥 Firestoreとは?

FirestoreはGoogle Cloudが提供するNoSQLドキュメント型データベースです。以下のような特徴を持ちます:

  • スキーマレスなデータ構造(JSON形式)
  • ドキュメント/コレクション階層で直感的に管理可能
  • リアルタイム同期と自動オフライン対応
  • 高いスケーラビリティとセキュリティ(Firebase Authenticationと統合可能)

🧩 Databutton × Firestoreの魅力

Databuttonでは、Firestoreをバックエンドとして使うことで以下のような使い方が可能になります:

  • ユーザー入力データの保存
  • AIアプリのチャットログ記録
  • JSON構造の設定情報管理
  • UIフォームとリアルタイム連携

🚀 インテグレーション手順

① Firestoreの準備

  1. Firebase Console でプロジェクトを作成
  2. 「Cloud Firestore」を有効化
  3. サービスアカウントキーを作成し、Databuttonの Secrets に以下のように登録:
{
  "FIREBASE_PROJECT_ID": "your-project-id",
  "FIREBASE_PRIVATE_KEY": "-----BEGIN PRIVATE KEY-----\\n...",
  "FIREBASE_CLIENT_EMAIL": "firebase-adminsdk@your-project-id.iam.gserviceaccount.com"
}





 DatabuttonでのFirestore操作

Databuttonでは、以下のようにシンプルなコードでFirestoreにアクセスできます。

🔸 データ追加

from databutton.firestore import collection

collection("users").add({
    "name": "Taro",
    "email": "taro@example.com"
})

🔸 データ取得

users = collection("users").get()

for user in users:
    print(user["name"])

🔸 データ更新

collection("users").document("user_id").update({
    "email": "new@example.com"
})

🔸 データ削除

collection("users").document("user_id").delete()

💡 実用ユースケース
• アンケートフォームの結果をFirestoreに保存
• AIチャットの履歴をドキュメント化
• アプリ設定情報をJSONで動的に管理
• 管理者ページからリアルタイムで投稿を編集

✅ まとめ

DatabuttonとFirestoreを組み合わせることで、複雑なバックエンド開発なしにデータ永続化とリアルタイム性を持ったアプリケーションが構築できます。

ノーコードで始めたいが、データはちゃんと扱いたい。そんな開発者にとって、Firestore連携は最適な選択肢です。

📎 関連リンク:

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?