I'm trying to write a messaging app using PhoneGap, AngularJS and Firebase. I'm trying to work out what the correct the correct database structure should be given Firebase unusual query methods (1, 2).
I need a messages 'table' where all messages are stored, however the issue is that this is a NoSQL table, so it's quite hard to retrieve data if it's not formatted specifically.
For example, I originally considered something like /messages/{userId} to get all messages for a user, and /messages/{userId}/{partnerId} to get a specific message chain, but I can't do that because it would mean that data has to be duplicated, once for the person sending the message and once for the person receiving.
Can anyone suggest a layout which would work well with Firebase's query structure, and allows:
Retrieval of all messages to/from a user
Retrieval of a specific thread from one user to another
look in this post about data denormalizing . I faced a similar challenge and the solution which worked for me was storing all data under auto ID in specific object and if needed I stored a reference to that data in as many places as required.
Applying this to your problem, if simplified, I would go for something like this:
root/messages/{message_by_auto_id}/{message_body}
root/users/{user_id}/messages_this_user_can_see/{ref_to_message}
so If a user posts a message the app needs to save the message in messages and save the reference to that message to each friend as above.
Related
I send JSON's to my app via Postman in a list with a type of mapping(CRUD) to send it to my database.
I want my controller to put all this data, from multiple senders, in a list that will send the information to my DB. The problem is that i don't know how to store in the same list the Json and the Mapping, so when my threads do their work to know if that json must be inserted, updated, deleted and so on.
Do you guys have any ideea ?
PS: It is a spring-boot app that need to be able to send 12000 objects ( made from that jsons ) to the db.
I don't see a reason for putting all data in one list and sharing it later, each HTTP request receives own thread.
On decent server you can handle couple thousands of requests/sec which perform simple CRUD operations.
I’m developing a REST-API with NodeJS and Express with a MySQL-backend. The existing database has a lot of 1:n relationships and I’m struggling to find the right URI-scheme for these specific cases.
A simple example:
user {
id
name
}
comment {
id
text
user_id
}
Now, when I try to get the a list of all users, my uri would be: /users
- for one specific user: /user/{id}
- data for one specific user: /user/{id}/name
- for a list of all comments: /comment
- for one specific comment: /comment/{id}
- data for one specific comment: /comment/{id}/text
Now, the part where I’m struggling.
There is a 1:n relationship between user and comment. One user can have multiple comments, one comment belongs to one user. I want to implement something like a ‘back-reference’, so that when I access the data (meaning one specific field) for one specific comment, I can also get the information about the user the comment ‘belongs’ to.
The API doesn't know about these relationships, I'm also not using an ORM, so I have to hard code the information about the relationships somewhere anyway.
I already implemented a route where I can make a request on /comment/{id}/user_id where I redirect the request to /user/{id} with the id the comment belongs to. But this would be the same request for when I just want to get the user id for that comment, not the whole dataset for the user.
I've read a lot about the REST architecture and roy fielding always talks about making the API "browsable" or "explorable". One approach I came upon was adding a reference uri to the linked dataset, in my example that would mean expanding the user_id field to something like this :
user_id {
id:id
ref:/user/id
}
The results I'm getting from the database are much more complex than that and extracting the respective fields and adding this information seems like a bit much to do for this ‘simple’ problem.
I don't know if I'm missing something here, I'm developing this API for a project on which I also write a paper about and I try to follow the rules of the REST architecture as much as I can, but I'm a bit stuck right now.
What about publishing the comments "under" the user resources like this:
/user/{userid}
/user/{userid}/comments/{commentid}
Note, that you don't have to publish "database rows" one-to-one in a REST API. Indeed, this is usually frowned upon by REST people.
Also note, you don't have to publish each attribute of a resource as a resource. The resource /user/{userid} could very well return a complex (json, xml, etc.) representation that includes all the necessary data. Of course there are reasons to do it your way, for example I would make the text of a comment a separate resource if it is available in pdf, text, html, or in other formats which I don't control.
A minor point about Fielding's "browsable" API: What he means is that these resources reference each other through links in the returned data representations. Comments would reference the users (link to user), and users should reference their comments (links to comments). The client should never have to "guess" or "construct" an URI on its own, it should "browse" resources by following links only!
during the process of discontinuing our node we need to retrieve the user emails in order to notify them to migrate their VM's.
We have tried using keystone user-list after sourcing our openrc config file but to no avail.
Is there a command sequence we should use in order to retrieve what we need?
There is an way to get the information about the users that can be using your node. The steps that you should follow are the following:
Get the id of your region from the GET to http://cloud.lab.fiware.org:4730/v3/OS-EP-FILTER/endpoint_groups
Get the complete list of projects in your region: GET to http://cloud.lab.fiware.org:4730/v3/OS-EP-FILTER/endpoint_groups/{{Region-Id}}/projects where Region-id comes from endpoints_groups[i].id in the previous JSON response.
Get the user of those project, for each project: GET to http://cloud.lab.fiware.org:4730/v3/role_assignments?scope.project.id={{project_id}}, where project_id comes from projects[i].id in the previous JSON response.
Get detailed information of the user: GET to http://cloud.lab.fiware.org:4730/v3/users/{{user-id} where user-id comes from role_assignments[i].user.id in the previous JSON response.
Keep in mind that all the operations have to be done with the corresponding X-Auth-Token.
I hope that it can help you.
I have an ExpressionEngine site that I'm building with Bootstrap. It's a site for volunteers to find projects to help with. On the home page I have a modal with a form for them to select when they're available and what categories of jobs they're looking for. Then they can click submit and it'll go to a new page with filtered entries.
I don't know if this is possible using the GET method or POST method on the form. I've figured out how to use the GET method and get a query string into my URL but I don't know how to use that data to filter my entries on the entries page. Or would using POST and JSON be a better option? I don't know really how to implement either so any help would be great.
Thanks a lot!
It depends on how the information you would like to show is stored.
If you are using MySQL (a common RDMS), or any other form of SQL Database for that matter, the most common way is to send your GET query string (for example) to your server, have a sever-side language (such as PHP) handle that request by accessing your database, and then echo the result. This can be done synchronously, or with AJAX.
For example, the flow of everything might look like this:
User selects an option (say, "Gardening Projects").
JavaScript converts the value of that input option to a query string and sends an HTTP request using the GET method.
The destination of this request is "filter.php" (for example).
"filter.php" access your database using an SQL query, which searches for any entries in your database, say, having a tag of "gardening".
"filter.php" echos a statement with those entries (or, better yet, returns a JSON object)
JavaScript then parses the resultant JSON object into the DOM, which displays as a bunch of links in a result area that your user can click on.
The question you have about how to handle this is very broad, so I would recommend simply doing some Google searches or looking around this site for resources that show you how to set up databases, access those databases with possibly PHP/SQL, and maybe even use AJAX to return those results, etc.
To get you started (these are in no particular order):
AJAX Tutorial
PHP - JSON encode
SQL tutorial
jQuery AJAX
I got it figured out with some help from #JoshBeam. It turns out that I was trying to make it way more complicated than it actually is. Rookie mistake. In the end I just ended up using method=get in my form and the setting the action as the page with the filtered entries. I then used php to echo the inputs into my EE channel:entries tag.
One thing I still haven't figured out is how to make it so that my query string will combine values for matching names. Currently I have checkboxes for days of the week, each with name="day" and different values for each day. If there are multiple checked, my query string becomes example.com/?day=sun&day=mon when I'd rather have it as example.com/?day=sun&mon. So if anyone has any tips on that, I'd welcome them! I also wonder if there's a way to add pipes between each value when I echo them in my EE tag so that I can have multiples - e.g. {exp:channel:entries category="1|2|3"}. But I have really yet to Google either of these questions so I'll do that.
Thanks!
I am doing an analysis of Credit Union social activity. I have some code that takes a link like this...
https://www.facebook.com/americanlakecu/likes
... and converts it to this...
http://graph.facebook.com/americanlakecu
..which enables me to grab 'Likes' and 'People Talking'. The problem is many institutions, particularly the smaller ones, seem to use a different format. Here's an example.
https://www.facebook.com/pages/EvergreenDIRECT-Credit-Union/276887662722?sk=likes
Anyone know how to convert the link above so I can use the api to render JASON in the same way as http://graph.facebook.com/americanlakecu ?
You need to reference the facebook id when hitting the graph for the other institutions. For americanlakecu, that id is americanlakecu. For Evergreen's case, try 276887662722. But for some reason, your "smaller" pages need an access token. I think the difference might be a simple matter of availability of data.
You can still get their data as I described above, but you need an api access token. For instance, following this link directly will show you nothing: http://developers.facebook.com/tools/explorer/?method=GET&path=276887662722 , but after you get there, if you fetch an access token, you will see all the info you need.
So, configure your implementation of the SDK to use an access token, and you ought to be able to continue using the handy graph method.