Skip to content

Instantly share code, notes, and snippets.

@oogatta
Last active October 3, 2017 12:12
Show Gist options
  • Save oogatta/1daac361ba52c3aa99b3cc701e54fe4d to your computer and use it in GitHub Desktop.
Save oogatta/1daac361ba52c3aa99b3cc701e54fe4d to your computer and use it in GitHub Desktop.
// ☁️ Admin node
//   JS だけ value ではソートが効かないのはバグか仕様か
admin.database().ref().child("test").child("Admin")
.orderByChild("fuga") // ソートキー
.on("child_added", snapshot => {
console.log(`(${snapshot.val().hoge}, ${snapshot.val().fuga})`);
});
// 🍎 iOS Swift
Database.database().reference().child("test").child("iOS")
.queryOrdered(byChild: "fuga") // ソートキー
.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("fuga") // ソートキー
.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)
}
}
})
// 🛎 結果はすべて
(5, 1)
(4, 2)
(3, 3)
(2, 4)
(1, 5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment