data query

Regular data CURD queries can be implemented using the process of the data model.

For complex scenarios such as data aggregation statistics, or need to connect to the data warehouse, you can use Query DSL in the data flow (Domain Specific Language) implementation.

Using the data model handler

Write the data flow description file query.flow.json and place it in the flows directory of the application.

{
"label": "pet",
"version": "1.0.0",
"description": "Data query",
"nodes": [
{
"name": "List",
"process": "models.pet.Get",
"args": [
{
"select": ["id", "name", "remark"],
"wheres": [{ "column": "name", "value": "cat" }],
"limit": 3
}
]
},
{
"name": "Pagination",
"process": "models.pet.Paginate",
"args": [
{
"select": ["id", "name", "remark"],
"wheres": [{ "column": "name", "value": "cat" }],
"limit": 1
},
1,
3
]
},
{
"name": "A record",
"process": "models.pet.Find",
"args": [1, { "select": ["id", "name", "remark"] }]
},
{
"name": "Update Record",
"process": "models.pet.Update",
"args": [1, { "name": "This is a lazy cat" }]
},
{
"name": "Insert Record",
"process": "models.pet.Save",
"args": [
{ "name": "Roaring Dog", "amount": "2000", "remark": "New Member" }
]
},
{
"name": "Delete record",
"process": "models.pet.Delete",
"args": [1]
}
],
"output": "{{$res}}"
}

Run Dataflow

yao run flows.query

Use in JS files

get multiple

Process("models.pet.Get", {
wheres: [{ column: "name", value: "cat", op: "=" }],
limit: 1,
});

Get 1 piece of data with id 1

Process("models.pet.find", 1, {});

save data

Process("models.pet.save", {
id: 1,
name: "cats foo bar",
});

delete data

Process("models.pet.delete", 1, {});

Write the data flow description file stat.flow.json and place it in the flows directory of the application.

{
"label": "Pet Statistics",
"version": "1.0.0",
"description": "Pet Statistics",
"nodes": [
{
"name": "Type Statistics S1",
"engine": "xiang",
"query": {
"select": [":COUNT(id) as number", "name as name"],
"groups": "Name",
"from": "$pet"
}
},
{
"name": "Type Statistics S2",
"engine": "xiang",
"query": {
"select": [":SUM(amount) as amount", "name as name"],
"groups": "Name",
"from": "$pet"
}
}
],
"output": "{{$res}}"
}
FieldDescription
enginedata engine name, xiang uses the data source connection stored by the data model
queryQuery DSL, according to the data source connection type, write the corresponding query logic

Run Dataflow

yao run flows.stat

data query

Regular data CURD queries can be implemented using the process of the data model.

For complex scenarios such as data aggregation statistics, or need to connect to the data warehouse, you can use Query DSL in the data flow (Domain Specific Language) implementation.

Using the data model handler

Write the data flow description file query.flow.json and place it in the flows directory of the application.

{
"label": "pet",
"version": "1.0.0",
"description": "Data query",
"nodes": [
{
"name": "List",
"process": "models.pet.Get",
"args": [
{
"select": ["id", "name", "remark"],
"wheres": [{ "column": "name", "value": "cat" }],
"limit": 3
}
]
},
{
"name": "Pagination",
"process": "models.pet.Paginate",
"args": [
{
"select": ["id", "name", "remark"],
"wheres": [{ "column": "name", "value": "cat" }],
"limit": 1
},
1,
3
]
},
{
"name": "A record",
"process": "models.pet.Find",
"args": [1, { "select": ["id", "name", "remark"] }]
},
{
"name": "Update Record",
"process": "models.pet.Update",
"args": [1, { "name": "This is a lazy cat" }]
},
{
"name": "Insert Record",
"process": "models.pet.Save",
"args": [
{ "name": "Roaring Dog", "amount": "2000", "remark": "New Member" }
]
},
{
"name": "Delete record",
"process": "models.pet.Delete",
"args": [1]
}
],
"output": "{{$res}}"
}

Run Dataflow

yao run flows.query

Use in JS files

get multiple

Process("models.pet.Get", {
wheres: [{ column: "name", value: "cat", op: "=" }],
limit: 1,
});

Get 1 piece of data with id 1

Process("models.pet.find", 1, {});

save data

Process("models.pet.save", {
id: 1,
name: "cats foo bar",
});

delete data

Process("models.pet.delete", 1, {});

Write the data flow description file stat.flow.json and place it in the flows directory of the application.

{
"label": "Pet Statistics",
"version": "1.0.0",
"description": "Pet Statistics",
"nodes": [
{
"name": "Type Statistics S1",
"engine": "xiang",
"query": {
"select": [":COUNT(id) as number", "name as name"],
"groups": "Name",
"from": "$pet"
}
},
{
"name": "Type Statistics S2",
"engine": "xiang",
"query": {
"select": [":SUM(amount) as amount", "name as name"],
"groups": "Name",
"from": "$pet"
}
}
],
"output": "{{$res}}"
}
FieldDescription
enginedata engine name, xiang uses the data source connection stored by the data model
queryQuery DSL, according to the data source connection type, write the corresponding query logic

Run Dataflow

yao run flows.stat