0Pricing
Indie Hacker Mobile Apps · 강의

클라우드 데이터베이스 및 함수

실시간 데이터베이스(예: Firestore)를 사용하고 맞춤형 백엔드 로직을 위한 서버리스 클라우드 함수를 배포합니다.

클라우드 데이터베이스 및 함수은(는) CoddyKit의 무료 Indie Hacker Mobile Apps 강의입니다. 이것은 4개 중 3번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Indie Hacker Mobile Apps 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Indie Hacker Mobile Apps 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Cloud Databases Unveiled

Welcome! Today, we'll explore cloud databases and serverless functions, essential tools for scalable mobile apps. They provide robust, managed backends without the hassle of server maintenance.

We'll focus on Firestore, a popular choice for real-time data, and Cloud Functions for custom backend logic.

Firestore's Data Model

Cloud Firestore is a flexible, scalable NoSQL document database. Unlike traditional relational databases with tables and rows, Firestore organizes data into collections and documents.

Each document contains key-value pairs, known as fields. Documents live within collections, and collections can even contain subcollections.

Structuring Your App Data

Understanding collections and documents is key to structuring your app's data efficiently. Imagine a simple e-commerce app:

  • users (collection)
    • user_alice_id (document)
      • name: "Alice"
      • email: "alice@example.com"
  • products (collection)
    • product_xyz_id (document)
      • name: "Cool Gadget"
      • price: 99.99

Adding Data with Ease

Adding data to Firestore is straightforward. You can use add() to let Firestore generate a unique document ID, or set() to specify your own ID or overwrite an existing document.

Here's how to add a new user to a 'users' collection:

db.collection("users").add({
  name: "Bob",
  email: "bob@example.com",
  status: "active"
})
.then((docRef) => {
  console.log("Document written with ID: ", docRef.id);
})
.catch((error) => {
  console.error("Error adding document: ", error);
});

Fetching Data on Demand

To retrieve a document or a collection of documents once, you use the get() method. This is useful for data that doesn't require constant, real-time updates.

Let's fetch a specific user's data using their document ID:

db.collection("users").doc("bob_doc_id").get()
  .then((doc) => {
    if (doc.exists) {
      console.log("Document data:", doc.data());
    } else {
      console.log("No such document!");
    }
  })
  .catch((error) => {
    console.error("Error getting document:", error);
  });

Keeping Data Live with Snapshots

Firestore's real-time capabilities are powerful. By using onSnapshot(), you can listen for changes to documents or collections. Whenever data changes on the backend, your app receives instant updates.

This snippet demonstrates listening to a single document for real-time changes:

db.collection("products").doc("prod_xyz").onSnapshot((doc) => {
  if (doc.exists) {
    console.log("Current product data:", doc.data());
  } else {
    console.log("Product removed or never existed!");
  }
});
// This listener keeps your app updated automatically

Serverless Logic with Functions

Cloud Functions are serverless pieces of code that run in response to specific events. They let you execute custom backend logic without needing to manage or provision any servers.

They're perfect for extending your BaaS (like Firebase) with custom features, security rules, or integrations.

What Makes a Function Run?

Cloud Functions are 'event-driven,' meaning they only run when a specific event occurs. These events are called triggers. Common types include:

  • HTTP triggers: For creating API endpoints.
  • Firestore triggers: React to document creation, updates, or deletions.
  • Authentication triggers: Respond to user sign-ups or deletions.
  • Scheduled triggers: Run functions at specific times (e.g., daily cleanup).

Your First HTTP Cloud Function

Let's create a simple Cloud Function that responds to an HTTP request. This is like building a tiny, serverless API endpoint. It's a great way to handle custom logic that your mobile app might need.

This example will return a basic "Hello from Firebase!" message.

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();

exports.helloHttp = functions.https.onRequest((request, response) => {
  // Set CORS headers for web access, if needed
  response.set('Access-Control-Allow-Origin', '*'); 
  response.set('Access-Control-Allow-Methods', 'GET, POST');
  response.status(200).send("Hello from Firebase!");
});

Automating with Functions + DB

Cloud Functions and Firestore are a powerful combination. Functions can automatically react to changes in your Firestore database, allowing you to:

  • Update aggregate counts (e.g., total likes on a post).
  • Perform data validation or sanitization.
  • Send notifications or emails after a user action.

This keeps your app's logic robust and efficient, handling backend tasks seamlessly.

Cloud Logic Check

Test your understanding of cloud databases and serverless functions.

Databases & Functions Summary

You've explored the core concepts of Cloud Firestore for scalable, real-time data storage using a flexible NoSQL document model. You also learned about Cloud Functions, which enable you to deploy serverless backend logic in response to various triggers.

Mastering these tools is fundamental for building dynamic, robust, and efficient indie mobile apps!

자주 묻는 질문

“클라우드 데이터베이스 및 함수” 강의는 무료인가요?

네 — “클라우드 데이터베이스 및 함수” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Indie Hacker Mobile Apps 강의 전체를 잠금 해제할 수 있습니다. Indie Hacker Mobile Apps 강의에는 총 4개의 강의가 포함되어 있습니다.

“클라우드 데이터베이스 및 함수”에서 뭘 배우나요?

실시간 데이터베이스(예: Firestore)를 사용하고 맞춤형 백엔드 로직을 위한 서버리스 클라우드 함수를 배포합니다. 브라우저에서 직접 실행하는 실습 코드로 Indie Hacker Mobile Apps을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Indie Hacker Mobile Apps을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Indie Hacker Mobile Apps은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 3번째 강의입니다.

“클라우드 데이터베이스 및 함수” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Indie Hacker Mobile Apps 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Indie Hacker Mobile Apps 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. BaaS 플랫폼 입문
  2. 사용자 인증 및 보안
  3. 클라우드 데이터베이스 및 함수
  4. BaaS를 활용한 실시간 데이터와 푸시 알림
← Indie Hacker Mobile Apps(으)로 돌아가기