get
firestore-sweet
is smart enough to figure out whether the argument is for collection
doc
where
orderBy
or limit
based on the argument type and the position.
get doc
const user = await db.get("users", "bob")
// equivalent firestore
const user = (await fs.collection("users").doc("bob").get()).data()
get collection
const users = await db.get("users")
// [{"name": "Bob", "age": 35}, {"name": "Alice", "age": 20}]
// equivalent firestore
let users = []
(await fs.collection("users").get())).forEach((ss)=>{
users.push(ss.data())
})
where
get collection with const users = await db.get("users", ["age", "==", 30])
// equivalent firestore
let users = []
(await fs.collection("users").where("age", "==", 30).get())).forEach((ss)=>{
users.push(ss.data())
})
limit
get collection with const users = await db.get("users", 5)
// equivalent firestore
let users = []
(await fs.collection("users").limit(5).get())).forEach((ss)=>{
users.push(ss.data())
})
orderBy
get collection with const users = await db.get("users", ["age", "desc"])
// equivalent firestore
let users = []
(await fs.collection("users").orderBy("age", "desc").get())).forEach((ss)=>{
users.push(ss.data())
})
orderBy
and startAt
get collection with const users = await db.get("users", ["age", "desc"], ["startAt", 30])
// equivalent firestore
let users = []
(await fs.collection("users").orderBy("age", "desc").startAt(30).get())).forEach((ss)=>{
users.push(ss.data())
})
startAt
startAfter
endAt
endBefore
all work the same way.
id
and data
get collection with document const users = await db.getK("users")
// {"bob": {"name": "Bob", "age": 35}, "alice": {"name": "Alice", "age": 20 }}
// equivalent firestore
let users = {}
(await fs.collection("users").get())).forEach((ss)=>{
users[ss.id] = ss.data()
})
id
, data
and snapshot
get collection with document const users = await db.getS("users")
// equivalent firestore
let users = []
(await fs.collection("users").get())).forEach((ss)=>{
users.push({ss: ss, data: ss.data(), id: ss.id})
})