I am working on a android Firebase project. I need help in implementing this sql query in Firebase real-time database.
SELECT * FROM table
WHERE price BETWEEN $min AND $max;
I am working on a android Firebase project. I need help in implementing this sql query in Firebase real-time database.
SELECT * FROM table
WHERE price BETWEEN $min AND $max;
You can use the following method
new Firebase("https://examples-sql-queries.firebaseio.com/messages")
.startAt(startTime)
.endAt(endTime)
.once('value', function(snap) {
console.log('messages in range', snap.val());
});
There's good documentation on how to do firebase queries as well as apply them to ranges.
Something like:
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference ref = database.getReference("table");
Query query = ref.orderByChild("price").startAt(min).endAt(max);
Then you add the appropriate listener for what you are trying to do. (e.g. a ValueEventListener
or a ChildEventListener
via addValueEventListener
or addChildEventListener
respectively.