Closed Zaid-Mirza closed 8 years ago
hi @Zaid-Mirza Please take a look this article Common SQL Queries Converted for Firebase
Hi @ziyasal this artical looks based on JavaScript. not C#
Hi @Zaid-Mirza,
First of all, Firebase isn't like a relational database, There are few ways to do Joins, but Firebase wasn't developed for do that.
Firesharp library don't have support for the "child" and "once" of the Javascript library.
You will need to adapt your model to work with it. I will show you 3 examples how to resolve this problem. Maybe one of them can help you
// Firebase Model
-Risk
+kkKHhhuuwyYYyr
-Id: 'kkKHhhuuwyYYyr'
-Name: 'Test'
+KkkHahyahsyaTQ
-Id: 'KkkHahyahsyaTQ'
-Name: 'Victim'
-RiskVictimDetail
+kkKHhhuuwyYYyr
-VictimId: 'RiskVictimDetailId'
-RiskId: 'kkKHhhuuwyYYyr'
-RiskVictimDetail: 'Bla ble bli'
FirebaseResponse response = await _client.GetAsync("Risk/kkKHhhuuwyYYyr");
Risk risk = response.ResultAs<Risk>();
// Now to get Children
FirebaseResponse response = await _client.GetAsync("RiskVictimDetail/kkKHhhuuwyYYyr");
RiskVictimDetail riskDetail = response.ResultAs<RiskVictimDetail>();
But there is big problem, I now you don't have just one children.
// Firebase model 2
-Risk
+kkKHhhuuwyYYyr
-Id: 'kkKHhhuuwyYYyr'
-Name: 'Test'
+KkkHahyahsyaTQ
-Id: 'KkkHahyahsyaTQ'
-Name: 'Victim'
-RiskVictimDetail
+YUUtGGgRRrrFForm
-VictimId: 'YUUtGGgRRrrFForm'
-RiskId: 'kkKHhhuuwyYYyr'
-RiskVictimDetail: 'Bla ble bli'
+AWDIopkIwForm
-VictimId: 'AWDIopkIwForm'
-RiskId: 'kkKHhhuuwyYYyr'
-RiskVictimDetail: 'Bla ble bli'
FirebaseResponse response = await _client.GetAsync("Risk/kkKHhhuuwyYYyr");
Risk risk = response.ResultAs<Risk>();
// Now to get Children
FirebaseResponse response = await _client.GetAsync("RiskVictimDetail");
List<RiskVictimDetail> riskDetail = response.ResultAs<List<RiskVictimDetail>>().Where(rd => rd.RiskId == "kkKHhhuuwyYYyr");
But with this example you will have a desnecessary amount of data in your network.
// Firebase model 3
-Risk
+kkKHhhuuwyYYyr
-Id: 'kkKHhhuuwyYYyr'
-Name: 'Test'
+KkkHahyahsyaTQ
-Id: 'KkkHahyahsyaTQ'
-Name: 'Victim'
-RiskVictimDetail
+kkKHhhuuwyYYyr
+YUUtGGgRRrrFForm
-VictimId: 'YUUtGGgRRrrFForm'
-RiskId: 'kkKHhhuuwyYYyr'
-RiskVictimDetail: 'Bla ble bli'
+AWDIopkIwForm
-VictimId: 'AWDIopkIwForm'
-RiskId: 'kkKHhhuuwyYYyr'
-RiskVictimDetail: 'Bla ble bli'
+KkkHahyahsyaTQ
+AWdikdiijForm
-VictimId: 'AWdikdiijForm'
-RiskId: 'KkkHahyahsyaTQ'
-RiskVictimDetail: 'Test 1'
+opINMWiuawdnUForm
-VictimId: 'opINMWiuawdnUForm'
-RiskId: 'KkkHahyahsyaTQ'
-RiskVictimDetail: 'Test 2'
FirebaseResponse response = await _client.GetAsync("Risk/kkKHhhuuwyYYyr");
Risk risk = response.ResultAs<Risk>();
// Now to get Children
FirebaseResponse response = await _client.GetAsync("RiskVictimDetail/kkKHhhuuwyYYyr");
List<RiskVictimDetail> riskDetail = response.ResultAs<List<RiskVictimDetail>>();
For you, I think that is better example.
I hope have helped you!
https://www.airpair.com/firebase/posts/structuring-your-firebase-data https://www.firebase.com/docs/web/guide/structuring-data.html
hi @bhdebrito,according to these above mentioned links, Your examples are not patterned according to standards to define relationships on firebase. Im confused at your examples
@Zaid-Mirza
Sorry about them, I don't know your objects and they relationship, so that's examples are very poor for you.
Anyway, in firebase you don't have joins, so you can't use Query, you will need to structure your data. Look at these articles that you have mentioned, they are helpfull.
hi @bhdebrito I have structured my data as mentioned in links which I have given in comments.My objects have relationships same as in these links. Moral of the story is, FireSharp dont support maintainance of these kind of standard relationship which firebase actually supports?
@Zaid-Mirza,
FireSharp use Official Rest Api.
The official rest api from firebase, https://www.firebase.com/docs/rest/api/, support some query's in Get: https://www.firebase.com/docs/rest/guide/retrieving-data.html#section-rest-queries
You can use this kind of parameters on Get, but actually FireSharp doesn't support it.
But don't worry, If javascript do, it's possible to do with Rest, In lower level either one or the other are using Rest Api.
Who know if @ziyasal agree a Pull Request with support to query filter
Like I said, Firebase isn't like a relational database. It's more NoSql's approach, so thinking relational you always have trouble like this.
Ps: I will test another time the "child" and "once" from Javascript api, I guess that these features download all data from Firebase to filter it.
hi @all Adds query support for items like orderBy, startAt, endAt, etc merged I'll be publish new version asap.
hi @ziyasal and @bhdebrito , so i have to use pure Rest API for my solution untill you add Custom query features in FireSharp? Im right?
hi @bhdebrito im using Indices for relationships as mentioned in below link. https://www.firebase.com/docs/web/guide/structuring-data.html
hi @ziyasal , You updated FireSharp, but QueryBuilder have no Constructor. Im unable to make object of querybuilder
hi @Zaid-Mirza here is sample;
var response = await
_client.GetAsync("todos", QueryBuilder.New().OrderBy("field").StartAt("a"));
Now, Im getiing error index not defined, Even I have defined .indexOn my field in secruity and rules
If you are collaborator of project at firebase. Then security rules will not work. Owner of application have to define rules On Jun 27, 2016 8:54 AM, "dat nguyen" notifications@github.com wrote:
Hello Zaid-Mirza, About error index not defined, Even I have defined .indexOn my field in secruity and rules. You already fixed? Please support me on this.
Thanks.
— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/ziyasal/FireSharp/issues/39#issuecomment-228649146, or mute the thread https://github.com/notifications/unsubscribe/AMsSQmOtSfR5itmq9Q4iEIWAYCT80AjLks5qP0mKgaJpZM4IZ02m .
Hi, Im new to FireSharp. I have some data on firebase. Data Have some relation with other data
-Books -HJSSgGGggaggGGArR -BookName:"Android" -Pages:"400" -Editors -HGYgsyysyyysygggy:true -HYTRayyYTTtteggErRu -BookName:"C# Intro" -Pages:"60" -Editors -HGYgsyysyyysygggy -EditorName:"Zaid"
I want a custom query to pass in Get Method so that I Can get desired data. e.g Where BookName=Android join Editors where EditorName=Zaid