How to use query builder with adonis repl - database

Im trying to figure out how can I manipulate my database using adonis repl.
I understand models.User is what I should start with to manipulate Users table and I tried using models.User.query() and this function does exist but I cannot understand how to use this method because I was expecting it to bring back all the users but it seems to be bringing back an instance and configurations of model.
my goal is to query users and then change the role of a certain user that I query with it's username.
somthing like this:
models.User.query().select().where('username','admin')
and then :
admin.role='editor'

Related

Access value in expand and use it in filter (Graph API)

I'm trying to get generate a list of users that has the same manager in the Azure AD using the Graph API.
Using https://graph.microsoft.com/v1.0/users?$expand=manager($select=id)&$select=userPrincipalName,manager will give be the necessary id for the managers set for the users.
I would now like to get all users with a certain manager id. I can't figure out how I use the id from manager field. This query doesn't work, it returns all users.
https://graph.microsoft.com/v1.0/users?$expand=manager($select=id;$filter=manager/id eq '<manager id>')&$select=userPrincipalName
If I instead have the filter after the select I get the manager object itself since it seems to take manager/id as the id for the manager.
https://graph.microsoft.com/v1.0/users?$expand=manager($select=id)&$select=userPrincipalName,manager&$filter=manager/id eq '<manager id>'
Any clues?
To get all the users with specific manager id use below api request:
https://graph.microsoft.com/v1.0/users/XX/directReports
XX- It is Manager Id
I'm afraid you need to write your custom logic in your code to filter the users who have the same manager. According to official document,
$expand is not currently supported with advanced queries.
And per my test, when we used expand in graph SDK, it will return null property when a user doesn't have a manager, you may try to avoid null reference exception when writing your custom logic to do a filter.

Saving "likes" database design (Parse)

Im using Parse to save data from my social network. So far I have three class: Users, Posts, and Relationships. I want the user to be able to like a post.
Should I create a new table for Likes. If so, then on my storyboard page I would have to query through Relationships to get the user followers, then Posts to get the posts from the followers, and then Likes to get the likes from those posts?
Is it efficient to have three API requests to parse on one page. I feel like this will slow down performance but I'm not sure how else to save likes.
Another thing is, I would like to display a notifications tableView. So all likes and requested follows. So Im guessing I would save likes in Relationships and just query through it twice on the storyboard to first get followers, then likes. And on the notification page, have one class to query though once to get all recent notifications.
What are your suggestions?
Thanks.
This is sort of a broad question so there is no way that I could say for sure, but I do have a couple suggestion that you can do with parse.com.
Use the local datastore: You can save all of the likes that the user has in the local datastore as well as in the cloud of your application. So, for instance, you create the like when the user likes something, save it to the cloud, and then pin it to the local datastore. That way, you can efficiently query all of the likes that your user has created without using an API request. But in the event the user logs into the app somewhere else, you also have the likes in the cloud to retrieve. So, I would create a new table for likes.
You could use a join table to implement the followers, so, you could also pin the followers of the user to the local datastore like you would for a like. This is like is done in the Parse.com anypic tutorial.
I would also have another table for notifications. In cloud code, you could even update how many notifications the user has with an afterSave method, and then get all the notifications through a query when requested by the user.

Get list of all fields in all salesforce objects

I have a specific field that I am trying to find. The salesforce instance I am in has hundreds of tables/objects so I can't look through them manually.
I also only have read only access, so I can't run an APEX script or create objects. I am using an API to access the database, and store the data outside of salesforce.
What I need is to find the object/table that this field is stored in so I can write an SOQL query to get the field's values. Any ideas?
Easiest way is with Workbench.

GAE datastore -- proper ways to implement search/data retrieval in response to a user request?

I am writing a web app and I am trying to improve the performance of search/displaying results. I am relatively new to programming this sort of thing, so I apologize in advance if these are simple questions/concepts.
Right now I have a database of ~20,000 sites, each with properties, and I have a search form that (for now) just asks the database to pull all sites within a set distance (for this example, say 50km). I have put the data into an index and use the Search API to find sites.
I am noticing that the database search takes ~2-3 seconds to:
1) Search the index
2) Get a list of key names (this is stored in the search index)
3) Using key names, pull from datastore (in a loop) and extract data properties to be displayed to the user
4) Transmit data to the user via jinja template variables
This is also only getting 20 results (the default maximum for a Search API query.. I haven't implemented cursors here yet, although I will have to).
For whatever reason, it feels quite slow.. I am wondering what websites do to make the process seem faster. Do they implement some kind of "asynchronous" search, where a page loads while in the background the search/data pulls are processed, and then subsequently shown to the user...?
Are there "standard" ways of performing searches here where the processing/loading feels seamless to the user?
Thanks.
edit
Would doing something like just passing a "query ID" via the page work, and then using AJAX to get data from the datastore via JSON work? Like... can app engine redirect the user to the final page, pass in only a "query ID", and then search in the meantime, and then once the data is ready, pass the information the user via JSON?
Make sure you are getting entities from the datastore in parallel. Since you already have the key names, you just have to pass your list of keys to the appropriate method.
For db:
MyModel.get_by_key_name(key_names)
For ndb:
ndb.get_multi([ndb.Key.from_path('MyModel', key_name) for key_name in key_names])
If you needed to do datastore queries, you could enable parallel fetches with the query.run (db) and query.fetch_async (ndb) methods.

Make Friendlier SSRS Report URLS

We have SSRS reports setup something like so:
http://myserver/reports/Pages/Report.aspx?ItemPath=%2fChanges-By-SSN&ViewMode=Detail
Is there an easy way to change the url to something like:
http://myserver/reports/?changes-by-ssn
These reports are going to be used by non-technical people and I'd like the url to be friendlier and easier to remember.
I have not tried URL Rewrite with SSRS, so don't know how easy it would be.
What about the other way? Either integrate a ReportViewer into your application so that users can select a report from a list of reports.
And/or create report models and allow to use a ReportBuilder - URLs in that case are pretty clean and users work with models and folder-like structure
You could create a simple asp.net page, that accepts the pretty url and uses Server.Redirect or Server.Transfer (if you want to keep the redirect hidden), to show the correct report. Or use a ReportViewer, that shows the correct report depending on the url parameter.
The only problme has to do with authentication. Perhaps you'll have to impersonate or pass crdentials or use any other method, because, depending on your chosen solution, it will be the web application identity the one that will acces the report server.

Resources