安装调试

本章节介绍如何在本地建立 Yao 开发调试环境。生产环境使用,请参考 部署 文档。

约定

  1. 示例中约定应用根目录为 /data/app, 实际编写时需替换为应用根目录。
  2. 使用 <> 标识自行替换的内容。 例如: icon-<图标名称>, 实际编写时应替换为: icon-foo, icon-bar ...
  3. 文件.yao的后缀和格式和.json结构是一样的,不影响使用都可以兼容。

安装

在终端下运行脚本:

curl -fsSL https://website.yaoapps.com/install.sh | bash
Yao 默认使用 Sqlite 存储数据,如果您需要使用 MySQL、PostgreSQL数据库作为数据源,请参照数据库官方文档下载并安装。推荐使用 MySQL 8 或Postgres14。

启动命令

yao start

进入应用目录,使用 start 命令,启动服务。默认服务端口为 5099, 可通过声明环境变量,指定服务端口。 环境变量

cd /data/app
yao start

参数表:

参数必填说明
--disable-watching禁止使用 watching 监听 yao start --disable-watching 命令启动
--debug强制开启开发模式 yao start --debug 命令启动

调试命令

Run 运行处理器

进入应用目录,使用 run 命令,运行数据流、脚本、插件以及内建的处理器。

yao run <process> [args...]

cd /data/app
yao run utils.app.Ping

参数表:

参数必填说明
process运行处理器名称. 处理器文档
args...处理器的输入参数表。处理器文档

查看日志

在开发模式下,可以再日志中查看运行的 SQL 语句等调试信息。 日志文件默认存在在应用 logs 目录。

cd /data/app
tail -n 1000 logs/application.log

Query DSL 调试

在编写 Query DSL 时,可以开启 debug 参数, 在日志中查看解析后的 SQL 语句

在 Flow DSL 中开启 debug 新建模型:/data/app/models/category.mod.yao然后执行命令 yao migrate && yao start

{
"name": "::category",
"table": { "name": "category", "label": "类目表" },
"columns": [
{ "name": "id", "label": "ID", "type": "ID" },
{
"name": "name",
"label": "名称",
"type": "string",
"length": 80,
"index": true,
"nullable": true
},
{
"name": "parent_id",
"label": "上级类目",
"type": "integer",
"nullable": true
}
],
"relations": {},
"values": [],
"indexes": [],
"option": {
"timestamps": true,
"soft_deletes": true
}
}

在目录新增/data/app/flows/test.flow.yao,如下代码:

{
"label": "类目树",
"version": "1.0.0",
"description": "类目树",
"nodes": [
{
"name": "类目",
"engine": "default",
"query": {
"debug": true,
"select": ["id", "name", "name as label", "id as value", "parent_id"],
"wheres": [{ ":deleted_at": "删除", "=": null }],
"from": "category",
"limit": 1000
}
}
],
"output": "{{$res.类目}}"
}

运行命令 yao run flows.test

在 Script 开启 Debug

新建文件:/data/app/scripts/test.js

function DD() {
let qb = new Query();
return qb.Get({
debug: true,
select: ["id", "name", "name as label", "id as value", "parent_id"],
wheres: [{ ":deleted_at": "删除", "=": null }],
from: "category",
limit: 1000,
});
}
yao run scripts.test.DD

Script 调试

可以使用 console.loglog 打印调试信息

/data/app/scripts/test.js

function Debug() {
console.log("Hello", { foo: "bar" }); // 在控制台打印
log.Info("Foo %d %s", 1, "hello");
log.Debug("Foo");
log.Trace("Foo");
log.Error("Foo");
}
yao run scripts.test.Debug

相关内容

接下来,建议学习以下章节:

创建数据模型:了解如何创建模型,存储数据到数据库

安装调试

本章节介绍如何在本地建立 Yao 开发调试环境。生产环境使用,请参考 部署 文档。

约定

  1. 示例中约定应用根目录为 /data/app, 实际编写时需替换为应用根目录。
  2. 使用 <> 标识自行替换的内容。 例如: icon-<图标名称>, 实际编写时应替换为: icon-foo, icon-bar ...
  3. 文件.yao的后缀和格式和.json结构是一样的,不影响使用都可以兼容。

安装

在终端下运行脚本:

curl -fsSL https://website.yaoapps.com/install.sh | bash
Yao 默认使用 Sqlite 存储数据,如果您需要使用 MySQL、PostgreSQL数据库作为数据源,请参照数据库官方文档下载并安装。推荐使用 MySQL 8 或Postgres14。

启动命令

yao start

进入应用目录,使用 start 命令,启动服务。默认服务端口为 5099, 可通过声明环境变量,指定服务端口。 环境变量

cd /data/app
yao start

参数表:

参数必填说明
--disable-watching禁止使用 watching 监听 yao start --disable-watching 命令启动
--debug强制开启开发模式 yao start --debug 命令启动

调试命令

Run 运行处理器

进入应用目录,使用 run 命令,运行数据流、脚本、插件以及内建的处理器。

yao run <process> [args...]

cd /data/app
yao run utils.app.Ping

参数表:

参数必填说明
process运行处理器名称. 处理器文档
args...处理器的输入参数表。处理器文档

查看日志

在开发模式下,可以再日志中查看运行的 SQL 语句等调试信息。 日志文件默认存在在应用 logs 目录。

cd /data/app
tail -n 1000 logs/application.log

Query DSL 调试

在编写 Query DSL 时,可以开启 debug 参数, 在日志中查看解析后的 SQL 语句

在 Flow DSL 中开启 debug 新建模型:/data/app/models/category.mod.yao然后执行命令 yao migrate && yao start

{
"name": "::category",
"table": { "name": "category", "label": "类目表" },
"columns": [
{ "name": "id", "label": "ID", "type": "ID" },
{
"name": "name",
"label": "名称",
"type": "string",
"length": 80,
"index": true,
"nullable": true
},
{
"name": "parent_id",
"label": "上级类目",
"type": "integer",
"nullable": true
}
],
"relations": {},
"values": [],
"indexes": [],
"option": {
"timestamps": true,
"soft_deletes": true
}
}

在目录新增/data/app/flows/test.flow.yao,如下代码:

{
"label": "类目树",
"version": "1.0.0",
"description": "类目树",
"nodes": [
{
"name": "类目",
"engine": "default",
"query": {
"debug": true,
"select": ["id", "name", "name as label", "id as value", "parent_id"],
"wheres": [{ ":deleted_at": "删除", "=": null }],
"from": "category",
"limit": 1000
}
}
],
"output": "{{$res.类目}}"
}

运行命令 yao run flows.test

在 Script 开启 Debug

新建文件:/data/app/scripts/test.js

function DD() {
let qb = new Query();
return qb.Get({
debug: true,
select: ["id", "name", "name as label", "id as value", "parent_id"],
wheres: [{ ":deleted_at": "删除", "=": null }],
from: "category",
limit: 1000,
});
}
yao run scripts.test.DD

Script 调试

可以使用 console.loglog 打印调试信息

/data/app/scripts/test.js

function Debug() {
console.log("Hello", { foo: "bar" }); // 在控制台打印
log.Info("Foo %d %s", 1, "hello");
log.Debug("Foo");
log.Trace("Foo");
log.Error("Foo");
}
yao run scripts.test.Debug

相关内容

接下来,建议学习以下章节:

创建数据模型:了解如何创建模型,存储数据到数据库