PLAY STEEM 모바일 앱 개발자 이타인클럽입니다. Flutter로 웹앱을 개발하고 있습니다. 포스트 데이터를 관리하기 위해 DB 설계가 매우 중요합니다. Firebase의 Firestore를 이용해서 DB를 설계하고 있습니다. ![image.png](https://cdn.steemitimages.com/DQmYGqMHFf3FYKK2U8qmFqZcEseAH6dkWk99ZyvgGyHoKeL/image.png) 사용자 DB에서 하부 collection으로 categories를 가지는 구조입니다. 그리고 categories의 document는 post의 reference이구요. reference를 사용하면 뭔가 복잡해 지는 거 같지만, 여러 collections 데이터를 쉽게 접근할 수 있어서 편합니다. 처음 사용법 익히는데 시간이 좀 걸리는 거 뿐이죠. DB 설계 할 때, 중요한 점은 DB 조회, 쓰기 횟수를 최소로 하는 것입니다. 쓰는 만큼 비용이 나가기 때문이죠. 그래서, 위 그림에서도 document id를 지정할 필요가 있습니다. 미리 document id를 알고 있다면 검색(query)하지 않아도 되기 때문에 db 조횟수를 줄일 수 있습니다. ## StremBuilder, Future Builder Flutter에서는 stream data나 future data를 입력으로 받아서, 필요한 시점에 ui를 그려주는 기능이 있습니다. 매우 편하고 좋습니다. 대략 이렇게 사용합니다! ``` content: StreamBuilder( stream: categoriesRef?.orderBy('id').snapshots(), builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) { print('category snapshot: $snapshot'); if (snapshot.hasError) { return Text('Something went wrong'); } if (snapshot.connectionState == ConnectionState.waiting) { return Text("Loading"); } return Column( children: snapshot.data!.docs.map((doc) { final name = doc.get('name'); ``` ``` final bookmark = bookmarks[index]; return FutureBuilder( future: bookmark.get(), builder: (BuildContext context, AsyncSnapshot<DocumentSnapshot> snapshot) { return Container( height: 40.0, width: double.infinity, child: _buildBookmarkCard(snapshot.data), ); }, ); ``` --- ## 리스팀 / 보팅 / 댓글 / 팔로우 / 응원 부탁드립니다. cc. @steemcurator01 @steemitblog <center> https://steemitimages.com/640x0/https://cdn.steemitimages.com/DQmdGBZB4dH9yTaT6M45YVmUSmLWJ8x8LgTPABu3bWPYeQb/img_0.07502965088307478.jpg https://playsteem.app </center>
post_id | 92,695,637 |
---|---|
author | etainclub |
permlink | play-steem-x-webapp-db |
category | hive-101145 |
json_metadata | {"tags":["playsteem","webapp","steemcurator","steemitdev","flutter","firestore","db"],"users":["steemcurator01","steemitblog"],"image":["https:\/\/cdn.steemitimages.com\/DQmYGqMHFf3FYKK2U8qmFqZcEseAH6dkWk99ZyvgGyHoKeL\/image.png","https:\/\/steemitimages.com\/640x0\/https:\/\/cdn.steemitimages.com\/DQmdGBZB4dH9yTaT6M45YVmUSmLWJ8x8LgTPABu3bWPYeQb\/img_0.07502965088307478.jpg"],"links":["https:\/\/playsteem.app"],"app":"steemit\/0.2","format":"markdown"} |
created | 2021-07-18 16:32:36 |
last_update | 2021-07-18 16:32:36 |
depth | 0 |
children | 2 |
net_rshares | 35,953,337,884,388 |
last_payout | 2021-07-25 16:32:36 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 11.326 SBD |
curator_payout_value | 11.314 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 1,972 |
author_reputation | 790,274,152,641,380 |
root_title | "[PLAY STEEM x WebApp] DB 설계" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
bert0 | 0 | 18,042,746,888 | 8.34% | ||
ghasemkiani | 0 | 92,103,684,452 | 100% | ||
happyworkingmom | 0 | 580,284,252,457 | 66% | ||
cheongpyeongyull | 0 | 86,565,208,599 | 30% | ||
stylegold | 0 | 402,752,182 | 100% | ||
etainclub | 0 | 1,645,906,474,481 | 100% | ||
rayheyna | 0 | 6,696,367,071 | 100% | ||
leeya | 0 | 0 | 3.5% | ||
dobartim | 0 | 23,398,530,140 | 51% | ||
handword | 0 | 2,547,202,994 | 56% | ||
yhoh | 0 | 62,972,295,381 | 100% | ||
sd974201 | 0 | 1,789,542,894 | 5% | ||
tresor | 0 | 30,757,769,032 | 8.34% | ||
wisdomandjustice | 0 | 6,180,278,372,506 | 100% | ||
anpigon | 0 | 19,223,428,329 | 100% | ||
rtytf | 0 | 1,841,988,972,285 | 46% | ||
kakakk | 0 | 38,688,630 | 7% | ||
kaka-aaa | 0 | 184,778,509 | 7% | ||
peterpa.cur | 0 | 3,364,844,796 | 50% | ||
powerego | 0 | 14,326,372,919 | 20% | ||
successgr | 0 | 136,809,981,051 | 7% | ||
dev.supporters | 0 | 132,052,058,041 | 10% | ||
bnk | 0 | 12,172,464,177 | 8.34% | ||
steemcurator01 | 0 | 25,037,739,225,678 | 7% | ||
sakurarte | 0 | 14,225,189,990 | 100% | ||
s4msulb4hri | 0 | 501,159,044 | 100% | ||
m1hard | 0 | 388,338,793 | 100% | ||
niikii | 0 | 8,577,183,069 | 35% |
늘 응원합니다. 감사합니다. ^^
post_id | 92,701,284 |
---|---|
author | yhoh |
permlink | qwgsaj |
category | hive-101145 |
json_metadata | {"app":"steemit\/0.2"} |
created | 2021-07-18 23:37:30 |
last_update | 2021-07-18 23:37:30 |
depth | 1 |
children | 1 |
net_rshares | 0 |
last_payout | 2021-07-25 23:37:30 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 18 |
author_reputation | 278,255,940,220,712 |
root_title | "[PLAY STEEM x WebApp] DB 설계" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
감사합니다~
post_id | 92,701,662 |
---|---|
author | etainclub |
permlink | re-etainclub-2021719t9511973z |
category | hive-101145 |
json_metadata | {"tags":["playsteem","webapp","steemcurator","steemitdev","flutter","firestore","db"],"app":"PLAYSTEEM\/1.1.0","format":"markdown+html"} |
created | 2021-07-19 00:05:12 |
last_update | 2021-07-19 00:05:12 |
depth | 2 |
children | 0 |
net_rshares | 0 |
last_payout | 2021-07-26 00:05:12 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 6 |
author_reputation | 790,274,152,641,380 |
root_title | "[PLAY STEEM x WebApp] DB 설계" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |