상세 컨텐츠

본문 제목

flutter + firebase [기본 셋팅절차] = firestore PROCESS SECOND.

firebase

by carecat 2025. 6. 20. 15:33

본문

반응형

기본 셋팅이후에 두번째 시간으로  FIRESTORE 에 대한 셋팅과 쿼리(CRUD) 절차.

 

 참고: SQL DB 와  Firestore 차이

Sql DB Cloud Firestore 비고
데이타베이스 컨넥션
->테이블 쿼리(필드명 이용)
 컬렉션 컨넥션
->문서.필드명 쿼리
 

 

        참고사이트:  https://firebase.google.com/docs/firestore

 

Firestore  |  Firebase

Google Cloud 인프라를 기반으로 하는 유연하고 확장 가능한 NoSQL 클라우드 데이터베이스를 사용해 클라이언트 측 개발 및 서버 측 개발에 사용되는 데이터를 저장하고 동기화하세요.

firebase.google.com

 

     모델 객체화   

    - City.fromFirestore()  :   파이어서버 데이타 객체화

    - City.toFiresotre():  객체에서 파이어서버 데이타로 

 factory City.fromFirestore(
    DocumentSnapshot<Map<String, dynamic>> snapshot,
    SnapshotOptions? options,
  ) {
    final data = snapshot.data();
    return City(
      name: data?['name'],
      state: data?['state'],
      country: data?['country'],
      capital: data?['capital'],
      population: data?['population'],
      regions:
          data?['regions'] is Iterable ? List.from(data?['regions']) : null,
    );
  }

  Map<String, dynamic> toFirestore() {
    return {
      if (name != null) "name": name,
      if (state != null) "state": state,
      if (country != null) "country": country,
      if (capital != null) "capital": capital,
      if (population != null) "population": population,
      if (regions != null) "regions": regions,
    };
  }
}
반응형

관련글 더보기