Last active
October 3, 2017 12:37
-
-
Save oogatta/d578f79697061eb952dd6b443666ef05 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") // ソートキー | |
.startAt(2) // 切り取る範囲 | |
.endAt(4) // 切り取る範囲 | |
.on("child_added", snapshot => { | |
console.log(`(${snapshot.val().hoge}, ${snapshot.val().fuga})`); | |
}); | |
// 🍎 iOS Swift | |
Database.database().reference().child("test").child("iOS") | |
.queryOrdered(byChild: "hoge") // ソートキー | |
.queryStarting(atValue: 2) // 切り取る範囲 | |
.queryEnding(atValue: 4) // 切り取る範囲 | |
.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") // ソートキー | |
.startAt(2.toDouble()) // 切り取る範囲 | |
.endAt(4.toDouble()) // 切り取る範囲 | |
.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) | |
} | |
} | |
}) | |
// 🛎 結果はすべて | |
(2, 4) | |
(3, 3) | |
(4, 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment