complex data query

This chapter details the data model based process and Gou Query DSL has two data query methods. It is recommended to learn the basics of relational databases and understand SQL syntax before reading , you can write basic SQL statements.

Query using the Model process

Data model processes Find, Get, Paginate, UpdateWhere, DeleteWhere, DestroyWhere all support the incoming query parameter Object QueryParam to limit the scope of reading records.

Object QueryParam:

View source code

Data structure description:

View Data Structure

Query using Query DSL

Query DSL can be used in data streams, and is generally used for more complex scenarios such as data analysis and statistics.

Analyze the data table service (see the table below) and count the highest scores in each industry.

idindustriescityscorecreated_atupdated_at
1["Tourism", "Education"]Beijing992021-10-03 13:40:52NULL
2["Tourism", "Education"]Shanghai682021-10-03 13:40:52NULL
3["Tourism", "Education"]Beijing922021-10-03 13:40:52NULL
4["Tourism", "Education"]Shanghai872021-10-03 13:40:52NULL
5["Tourism", "Education"]Beijing712021-10-03 13:46:06NULL

Query DSL example:

View source code

use in Flow

In a data flow, you can use {{$in}} or ?:$in to receive parameters, and {{$res}} or ?:$res to refer to node query results.

Tip: Pass {{$xxx}} or ?:$xxx Equivalent to using variable notation.

Using the model process

{
"label": "Query latest data",
"version": "1.0.0",
"description": "Query the latest data of the system",
"nodes": [
{
"name": "pet",
"process": "models.pet.Get",
"args": [
{
"select": ["id", "name", "kind", "created_at"],
"wheres": [{ "column": "kind", "value": "{{$in.0}}" }],
"orders": [{ "column": "created_at", "option": "desc" }],
"limit": 10
}
]
}
],
"output": "{{$res.pet}}"
}

Using the Query DSL

{
"label": "Query latest data",
"version": "1.0.0",
"description": "Query the latest data of the system",
"nodes": [
{
"name": "pet",
"engine": "xiang",
"query": {
"select": ["id", "name", "kind", "created_at"],
"from": "$pet",
"wheres": [{ ":kind": "type", "=": "?:$in.0" }],
"orders": "created_at desc",
"limit": 10
}
}
],
"output": "{{$res.pet}}"
}

use in script

function test(id) {
var query = new Query();
var data = query.Get({
name: "pet",
engine: "xiang",
query: {
select: ["id", "name", "kind", "created_at"],
from: "$pet",
wheres: [{ ":kind": "type", "=": id }],
orders: "created_at desc",
limit: 10,
},
});
}

use in the data table

In data tables, query parameters can be passed using filter. Query parameters are passed to the data table interface via URL Query String.

Specify the query parameter name:

{
"name": "pet",
"version": "1.0.0",
"decription": "Pet Management Form",
"bind": { "model": "pet" },
"apis": {},
"columns": {},
"filters": {
"Key words": {
"label": "Keyword",
"bind": "where.name.match",
"input": { "type": "input", "props": { "placeholder": "Please enter keywords" } }
}
},
"list": {
"filters": ["Keywords"],
...
},
"edit": {}
}

When clicking the search button on the interface, the system requests data from the form search API, and passes in the parameter name declared in bind and the value filled in by the user:

GET /api/xiang/table/pet?where.name.match=xxx

complex data query

This chapter details the data model based process and Gou Query DSL has two data query methods. It is recommended to learn the basics of relational databases and understand SQL syntax before reading , you can write basic SQL statements.

Query using the Model process

Data model processes Find, Get, Paginate, UpdateWhere, DeleteWhere, DestroyWhere all support the incoming query parameter Object QueryParam to limit the scope of reading records.

Object QueryParam:

View source code

Data structure description:

View Data Structure

Query using Query DSL

Query DSL can be used in data streams, and is generally used for more complex scenarios such as data analysis and statistics.

Analyze the data table service (see the table below) and count the highest scores in each industry.

idindustriescityscorecreated_atupdated_at
1["Tourism", "Education"]Beijing992021-10-03 13:40:52NULL
2["Tourism", "Education"]Shanghai682021-10-03 13:40:52NULL
3["Tourism", "Education"]Beijing922021-10-03 13:40:52NULL
4["Tourism", "Education"]Shanghai872021-10-03 13:40:52NULL
5["Tourism", "Education"]Beijing712021-10-03 13:46:06NULL

Query DSL example:

View source code

use in Flow

In a data flow, you can use {{$in}} or ?:$in to receive parameters, and {{$res}} or ?:$res to refer to node query results.

Tip: Pass {{$xxx}} or ?:$xxx Equivalent to using variable notation.

Using the model process

{
"label": "Query latest data",
"version": "1.0.0",
"description": "Query the latest data of the system",
"nodes": [
{
"name": "pet",
"process": "models.pet.Get",
"args": [
{
"select": ["id", "name", "kind", "created_at"],
"wheres": [{ "column": "kind", "value": "{{$in.0}}" }],
"orders": [{ "column": "created_at", "option": "desc" }],
"limit": 10
}
]
}
],
"output": "{{$res.pet}}"
}

Using the Query DSL

{
"label": "Query latest data",
"version": "1.0.0",
"description": "Query the latest data of the system",
"nodes": [
{
"name": "pet",
"engine": "xiang",
"query": {
"select": ["id", "name", "kind", "created_at"],
"from": "$pet",
"wheres": [{ ":kind": "type", "=": "?:$in.0" }],
"orders": "created_at desc",
"limit": 10
}
}
],
"output": "{{$res.pet}}"
}

use in script

function test(id) {
var query = new Query();
var data = query.Get({
name: "pet",
engine: "xiang",
query: {
select: ["id", "name", "kind", "created_at"],
from: "$pet",
wheres: [{ ":kind": "type", "=": id }],
orders: "created_at desc",
limit: 10,
},
});
}

use in the data table

In data tables, query parameters can be passed using filter. Query parameters are passed to the data table interface via URL Query String.

Specify the query parameter name:

{
"name": "pet",
"version": "1.0.0",
"decription": "Pet Management Form",
"bind": { "model": "pet" },
"apis": {},
"columns": {},
"filters": {
"Key words": {
"label": "Keyword",
"bind": "where.name.match",
"input": { "type": "input", "props": { "placeholder": "Please enter keywords" } }
}
},
"list": {
"filters": ["Keywords"],
...
},
"edit": {}
}

When clicking the search button on the interface, the system requests data from the form search API, and passes in the parameter name declared in bind and the value filled in by the user:

GET /api/xiang/table/pet?where.name.match=xxx