Skip to main content

Find data using lowcode ArcQL filters with Hypi

How to create User Accounts? How to provide login to access the features? This tutorial explains the process of authenticating user accounts with Hypi’s low code APIs!

written by:
Courtney Robinson

You successfully created a database on Hypi’s low code platform.

Next, how can you easily find the data you need?

Hypi has developed its powerful query language as part of its lowcode platform: ArcQL

‘ArcQL’ works as a filter to select data to process or return. ArcQL statements are used along with query functions like find. If you understand SQL, you will write the ArcQL statements just by guessing at it.

Let’s consider the following schema of a social media App with Post and Profile types

type Profile {
userAccnt: Account
address: Address
friends: [Account!]
}

type Post {
postedby: Account
date: DateTime
text: String
comments: [Post!]
rating: Float
tagFriends: [Account]
}

Suppose the following data has been inserted in the Post and Profile tables. To know about data insertion, check out this tutorial on CRUD Operations.

userAccntuser1user2user3
address /cityNagpurMumbaiPune
friendsuser2/user3user1user1/user2

User Profile

postedbyuser1user2
textUse low code!Future is low code!
date2010-12-122012-10-09

Post

Let’s use ArcQL filters one by one to filter the data.

Term Query

Let’s say we want to search an existing user profile on our App. We can use a term query to refine the profile results.

A term query is a simple filter asking to return results that match the provided exact value. It searches for the record that contains the data mentioned in the arcql statement.

Query Statement:

arcql:”userAccnt.username=’user1′

This arcql filter searches the user1 profile.

{
find(type: Profile, arcql:"userAccnt.username='user1'") {
edges {
node {
… on Profile {
userAccnt{
username
}
address {
city
}
}
}
cursor
}
}
}

#Result
{
"data": {
"find": {
"edges": [
{
"node": {
"userAccnt": {
"username": "user1"
},
"address": {
"city": "Nagpur"
}
},
"cursor": "01F644E2S73ZZMB0QJD8ANM6GP"
}
]
}
}
}

Now we may search the posts where user1 has been tagged. A simple ArcQL statement like this will do the task.

arcql:”tagFriends.username = ‘user1′”

{
find(type: Post, arcql:"tagFriends.username = 'user1'") {
edges {
node {
… on Post {
postedby{
username
}
text
}
}
cursor
}
}
}
{
"data": {
"find": {
"edges": [
{
"node": {
"postedby": {
"username": "user2"
},
"text": "Future is low code!"
},
"cursor": "01F645M1FZ9M09PEV7DC49E701"
}
]
}
}
}

Boolean Logic is possible on all query types. AND and OR logic can be utilized to get specific records.

Let’s say you want to see posts by user1 as well as user2. You may frame an arcql statement like this using OR.

arcql:”postedby.username = ‘user2’ OR postedby.username = ‘user1′”

{
find(type: Post, arcql:"postedby.username = 'user2' OR postedby.username = 'user1'") {
edges {
node {
… on Post {
postedby{
username
}
text
}
}
cursor
}
}
}

#Result
{
"data": {
"find": {
"edges": [
{
"node": {
"postedby": {
"username": "user1"
},
"text": "Use low code!!"
},
"cursor": "01F645AXCE9CRRG0TQFGQC4F8A"
},
{
"node": {
"postedby": {
"username": "user2"
},
"text": "Future is low code!"
},
"cursor": "01F645M1FZ9M09PEV7DC49E701"
}
]
}
}
}

Prefix Query

Now we will look for the user profiles who live in a city starting with the letter P. A prefix query returns records that have data starting with the prefix stated in the query.

Query statement :

arcql:”address.city^’P'”

This arcql searches for the city with the prefix ‘P’.

{
find(type: Profile, arcql:"address.city^'P'") {
edges {
node {
… on Profile {
userAccnt{
username
}
address {
city
}
}
}
cursor
}
}
}
# Result
{
"data": {
"find": {
"edges": [
{
"node": {
"userAccnt": {
"username": "user3"
},
"address": {
"city": "Pune"
}
},
"cursor": "01F644X4BDWAG5SXP5D16TCBM3"
}
]
}
}
}

Phrase Query

On your App, you want to filter posts as per the date of the post. Let’s say you retrieve all the posts posted in the year 2010.

You will frame the Arcql statement with a phrase query like this.

arcql:”date~’2010′”

Phrase query searches for the individual words or exact phrases from the data. It is similar to a search engine that searches the phrase through various web pages.

{
find(type: Post, arcql:"date~'2010'") {
edges {
node {
… on Post {
postedby{
username
}
text
}
}
cursor
}
}
}

#Result
{
"data": {
"find": {
"edges": [
{
"node": {
"postedby": {
"username": "user1"
},
"text": "Use low code!!"
},
"cursor": "01F645AXCE9CRRG0TQFGQC4F8A"
}
]
}
}
}

Match All Query

Now you want to see posts by all users. Just use a wildcard ‘*’ to retrieve all records.

arcql:”*”

{
find(type: Post, arcql:"*") {
edges {
node {
… on Post {
postedby{
username
}
text
}
}
cursor
}
}
}

#Result

{
"data": {
"find": {
"edges": [
{
"node": {
"postedby": {
"username": "user1"
},
"text": "Use low code!!"
},
"cursor": "01F645AXCE9CRRG0TQFGQC4F8A"
},
{
"node": {
"postedby": {
"username": "user2"
},
"text": "Future is low code!"
},
"cursor": "01F645M1FZ9M09PEV7DC49E701"
}
]
}
}
}

Wildcard Query

You may also use wildcards like * and ? to filter the data.

The following query retrieves the data of the user with a username ending with ‘3’.

arcql:”userAccnt.username * ‘*3′”

{
find(type: Profile, arcql:"userAccnt.username * '*3'") {
edges {
node {
… on Profile {
userAccnt{
username
}
address{
city
}
}
}
cursor
}
}
}

#Result
{
"data": {
"find": {
"edges": [
{
"node": {
"userAccnt": {
"username": "user3"
},
"address": {
"city": "Pune"
}
},
"cursor": "01F644X4BDWAG5SXP5D16TCBM3"
}
]
}
}
}

EXIST/ NOT EXIST

EXIST query returns records that have non-null data in a field.

Let’s check the results where the rating has been provided to a post.

{
find(type: Post, arcql: "EXIST rating") {
edges {
node {
… on Post {
postedby {
username
}
rating
text
hypi {
id
}
date
text
tagFriends {
username
}
}
}
cursor
}
}
}
#Result
{
"data": {
"find": {
"edges": [
{
"node": {
"postedby": {
"username": "user1"
},
"rating": 3.5,
"text": "Use low code!!",
"hypi": {
"id": "01F645AXCE9CRRG0TQFGQC4F8A"
},
"date": "2010-12-12T00:00:00Z",
"tagFriends": [
{
"username": "user2"
},
{
"username": "user3"
}
]
},
"cursor": "01F645AXCE9CRRG0TQFGQC4F8A"
}
]
}
}
}

NOT EXIST does the opposite of EXIST. It returns records that have null data in a field.

SORT

You may sort the records in ascending or descending order. Specify ASC/DESC order as per the requirement. If the order is not specified, hypi performs DESC order by default.

Now let’s sort the text of the posts in ascending order.

arcql:”userAccnt.username * ‘*3′”

{
find(type: Post, arcql: "* SORT text ASC") {
edges {
node {
… on Post {
text
}
}
cursor
}
}
}
#Result
{
"data": {
"find": {
"edges": [
{
"node": {
"text": "Future is low code!"
},
"cursor": "01F645M1FZ9M09PEV7DC49E701"
},
{
"node": {
"text": "Use low code!!"
},
"cursor": "01F645AXCE9CRRG0TQFGQC4F8A"
}
]
}
}
}

Range Query

Range queries search for the content that falls within given range.

  • a IN (0, 1] => left inclusive => including 0, excluding 1
  • a IN [0, 1) => right inclusive => excluding 0, including 1
  • a IN (0, 1) => exclusive => not including 0 or 1, only those in between
  • a IN [0, 1] => inclusive => including both 0, 1 and everything in between

Let’s say you want to search for posts in between 2010 and 2011. You may phrase a query like this.

arcql: “date IN (‘2010-01-01′,’2011-01-01’)”

{
find(type: Post, arcql: "date IN ('2010-01-01','2011-01-01')"){
edges {
node {
… on Post {
text
}
}
cursor
}
}
}

#Result
{
"data": {
"find": {
"edges": [
{
"node": {
"text": "Use low code!!"
},
"cursor": "01F645AXCE9CRRG0TQFGQC4F8A"
}
]
}
}
}

Concluding Note

This tutorial may have given you a fair idea of how to frame your ArcQL statements to filter data. In case of more clarifications, you may check the docs here.

Build powerful search features on your Application. Search data using low code ArcQL filter with Hypi!

Let’s check authentication functions provided by the low code Hypi platform!


Powered By Hypi.
Loading...
X

Still not convinced? Contact our sales team for a free demo, we’ll get you started

Make it happen! Access scalable platform for your customers needs.

Phone

By registering you agree to the Terms & Conditions