Last active
October 2, 2017 17:13
-
-
Save oogatta/2bddba1ce13d23826124b4de5b3ecfa7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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") | |
.orderByKey() // キーでソート | |
.limitToLast(3) // 切り取る範囲 | |
.once("value", snapshot => { | |
Object.values(snapshot.val()).forEach(value => { | |
console.log(`(${value.hoge}, ${value.fuga})`); | |
}); | |
}); | |
// 🍎 iOS Swift | |
Database.database().reference().child("test").child("iOS") | |
.queryOrderedByKey() // キーでソート | |
.queryLimited(toLast: 3) // 切り取る範囲 | |
.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") | |
.orderByKey() // キーでソート | |
.limitToLast(3) // 切り取る範囲 | |
.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) | |
} | |
} | |
}) | |
// 🛎 結果はすべて | |
(3, 3) | |
(4, 2) | |
(5, 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment