Creating Queries
Creating queries to retrieve to dos from our database using the Query Desinger
Last updated
Creating queries to retrieve to dos from our database using the Query Desinger
Last updated
In this section, we will create different queries to retrieve specific tasks from the database, namely :
For in-depth documentation about Queries, you can check out the corresponding documentation page :
To create a new query, click on Query then click on New Query
For this query, we simply want to retrieve all todos. We also give access to the Viewer group to run this query and access to the Editor group to modify this query.
In the Common Tab :
In the Fields Tab we can select which fields we want the query to return. For this tutorial, we will retrieve all the fields. Check the All checkbox on the right and click on Add Fields. This will populate our query with all the available fields in our To Do class.
In the Fields Tab :
When done, click the Save button to save the query.
This query will only return tasks of which we are the owner and make use of Conditions.
In the Common Tab :
In the Fields Tab :
Now we want to compare our user ID to the Owner field of the To Do class to determine if it should be retrieved or not. To add a new condition to our query, switch to the Conditions Tab, and click Add Condition.
We want this query to return all to incomplete task due today. This means that we will once again make use of conditions to check both the IsCompleted and the DueDate fields of our To Do class.
In the Common Tab :
In the Fields Tab :
In the Conditions Tab, we click on Add Condition. Our first condition we want to check is MyToDos.IsCompleted = 0
.
We now want to check if the due date is less or equal to today's date, which is denoted by MyToDos.DueDate <= {DateTime.Now.Date}
.
To add a second condition, click on Add Condition and make sure to choose AND as the first connector Set the Field column to the MyToDos.DueDate
field of your class set the middle Operator to <=
.
For this last query we simply want to return completed queries.
In the Common Tab :
In the Fields Tab :
In the Conditions Tab, we click on Add Condition set the condition to MyToDos.IsCompleted = 1
We also want to sort the results of this query by having the latest task created first, so we sort the CreatedOn field in descending order by clicking on the Order By Descending Button.
On the right-hand side, choose the Owner field of your class. Click on the gear icon to open the Condition Properties window. Set Compare To to Expression and Value to {CurrentUser.ID}
Click on the gear icon to open the Condition Properties window. Set Compare To to Expression and Value to {DateTime.Now.Date}