Created
October 3, 2017 12:40
-
-
Save oogatta/61f9e5386bdb4695ee52ea162af94aea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ☁️ Admin node | |
admin.database().ref().child("test").child("Admin") | |
.orderByChild("hoge") // ソートキー | |
.endAt(2) // 切り取る範囲 | |
.limitToLast(2) // 切り取る範囲 | |
.on("child_added", snapshot => { | |
console.log(`(${snapshot.val().hoge}, ${snapshot.val().fuga})`); | |
}); | |
// 🍎 iOS Swift | |
Database.database().reference().child("test").child("iOS") | |
.queryOrdered(byChild: "hoge") // ソートキー | |
.queryEnding(atValue: 2) // 切り取る範囲 | |
.queryLimited(toLast: 2) // 切り取る範囲 | |
.observe(.value, with: { snapshot in | |
snapshot.children.allObjects | |
.flatMap { ($0 as? DataSnapshot)?.value as? [String: Int] } | |
.forEach { print(($0["hoge"] ?? -1, $0["fuga"] ?? -1)) } | |
}) | |
// 🤖 Android Kotlin | |
FirebaseDatabase.getInstance().reference.child("test").child("Android") | |
.orderByChild("hoge") // ソートキー | |
.endAt(2.toDouble()) // 切り取る範囲 | |
.limitToLast(2) // 切り取る範囲 | |
.addListenerForSingleValueEvent(object : ValueEventListener { | |
override fun onCancelled(p0: DatabaseError?) {} | |
override fun onDataChange(snapshot: DataSnapshot?) { | |
snapshot?.children?.forEach { | |
println(it.getValue<Hoge>(Hoge::class.java)?.hoge to it.getValue<Hoge>(Hoge::class.java)?.fuga) | |
} | |
} | |
}) | |
// 🛎 結果はすべて | |
(1, 5) | |
(2, 4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment