5
I’m starting at Firebase and would like to know how to query with filter, example:
Select, only people who live in Porto Alegre.
Today, what I have is a comic book structure.
I have four tables, street, neighborhood, city and state. The first that I posted is the table is state, the other is street/ street.
This will depend completely on how the data is arranged. Put an example of how your data tree is.
– Pablo Almeida
Sorry Pablo, but I haven’t done the structure yet. I only have my SQL structure.
– GustavoSevero
Ah, I get it. So... Firebase, as you may know, is Nosql, and has structured data in the form of JSON (more or less). Unlike an SQL database, in which we work on a more abstract level, in Firebase you decide exactly where each element is. You’ll have to organize the data in Firebase so it’s easier to make this filter, but it’s kind of in hand. A good exercise might be trying to create an offline JSON and read from it. How would you do? If you follow the good practice of having an abstraction (Repository pattern, for example), do an implementation with JSON
– Pablo Almeida
Going to Firebase later will just be a matter of a few more tweaks.
– Pablo Almeida
Yes Pablo, I am aware that Firebase is Nosql and is structured in the JSON way. You suggest I assemble the structure, right into it and try to make the queries?
– GustavoSevero
You can go straight to it or a JSON on your computer (or even XML). The important thing is to take the information that is in your current scheme and arrange it hierarchically. Once done, it will be clear how to make the query filtering as you need.
– Pablo Almeida
Yeah, I tried to do it by hand, right there, but I could only create data at the root, like, name and value, several, one below the other and just, I couldn’t put the kids.
– GustavoSevero
Click "+" to create a new child.
– Pablo Almeida
Yes, I know that, but I mean, to query as with sql @Pabloalmeida.
– GustavoSevero
I think this page here will help you. I’m also coming from mysql and this concept of noSQL for me is still weird. Querying lists
– Marcello Patto
@Pabloalmeida Because, noSQL is a bit scary for those who come from mysql. But there is this series of articles in Portuguese that can help a lot: https://medium.com/android-dev-moz/firebasesql-4ee3d26a3d15#. h6w3goky4
– Rosário Pereira Fernandes
You can convert your structure to Firebase easily. What has to be clear is that there is no "Where" in Firebase, but a filter in the references. If you want, following your example, to consult all the people who live you have to take the reference and use an equalTo on Child. But by experience, join these tables in a single, even if the fields are repeated. It makes it easier later when it comes to queries. Include address, city, state, etc all in person table.
– Grupo CDS Informática