Where In using FrontQL
Introduction
In web applications, filtering data based on specific values is a common requirement. FrontQL allows you to filter data using the search
query parameter with a specific syntax.
Implementing Where In
To filter data using the “where in” criteria with FrontQL:
- Use the
search
query parameter to specify the criteria. - For a single value, format it as
search: field::value
. - For multiple values, format it as
search: field::value1/value2/value3
.
Example
Here are examples of how to implement the “where in” filter using FrontQL:
Single Value
async function getUsers() { const response = await Api.get("/users", { search: "post::1", });
return response;}
async function getUsers() { const url = `${BASE_URL}/users?search=post::1`; // Replace BASE_URL with the base URL of API server const response = await fetch(url, { method: "GET", headers: { "Content-Type": "application/json", app: DATABASE, // Replace DATABASE with the name of your database token: TOKEN, // Replace TOKEN with the token // OR // Authorization: `Bearer ${AUTH_TOKEN}`, // Replace AUTH_TOKEN with the authorization token, } })
const data = await response.json(); return data;}
Multiple Values
async function getUsers() { const response = await Api.get("/users", { search: "post::1/2/3", });
return response;}
async function getUsers() { const url = `${BASE_URL}/users?search=post::1/2/3`; // Replace BASE_URL with the base URL of API server const response = await fetch(url, { method: "GET", headers: { "Content-Type": "application/json", app: DATABASE, // Replace DATABASE with the name of your database token: TOKEN, // Replace TOKEN with the token // OR // Authorization: `Bearer ${AUTH_TOKEN}`, // Replace AUTH_TOKEN with the authorization token, } })
const data = await response.json(); return data;}
In these examples, the
search
query parameter filters theusers
table by thepost
field. For the single value example, it searches for records wherepost
equals1
. For the multiple values example, it searches for records wherepost
equals1
,2
, or3
.