Last active
October 2, 2017 17:14
-
-
Save oogatta/e22883bb8dbce558f60643591cd6866d 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() // キーでソート | |
.limitToFirst(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(toFirst: 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() // キーでソート | |
.limitToFirst(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) | |
} | |
} | |
}) | |
// 🛎 結果はすべて | |
(1, 5) | |
(2, 4) | |
(3, 3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment