-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
63 lines (62 loc) · 1.7 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { firestore } from "./firebase.js";
window.onload = async () => {
// データの追加
// const value = {
// task: "hogehoge",
// status: 1,
// createdAt: new Date(),
// };
// await firestore.collection("todos1").add(value);
//
// データの読み取り(1件)
// const docId = "";
// const doc = await firestore.collection("todos").doc(docId).get();
// console.log(doc);
// console.log(doc.id);
// const data = doc.data();
// console.log(data.createdAt.toDate());
//
// データの読み取り(複数)
// const snapShot = await firestore.collection("todos").get();
// const todos = snapShot.docs.map((doc) => ({
// id: doc.id,
// status: doc.data().status,
// task: doc.data().task,
// }));
// console.log(todos);
//
// データの更新
// const docId = "";
// await firestore.collection("todos").doc(docId).update({
// task: "mogemoge",
// });
//
// データの削除
// const docId = "";
// await firestore.collection("todos").doc(docId).delete();
//
// リアルタイム更新の取得
// const docId = "";
// firestore
// .collection("todos")
// .doc(docId)
// .onSnapshot((doc) => {
// console.log("Current data: ", doc.data());
// });
//
// 複数のクエリを用いた取得(絞り込み、並び替え、ページ)
// const snapShot = await firestore
// .collection("todos")
// .where("status", "==", 4)
// .orderBy("task")
// .startAt("hoge")
// .startAt(doc)
// .limit(3)
// .get();
// const todos = snapShot.docs.map((doc) => ({
// id: doc.id,
// status: doc.data().status,
// task: doc.data().task,
// }));
// console.log(todos);
};