hyperledger-composer - 在 hyperledger-composer 的“命名查询”中访问数组属性
问题描述
在我的超级账本作曲家应用程序中,我想编写一个命名查询,返回所有具有特定爱好的人。
“人”的模型如下:
participant Person identified by id {
o String id
o String firstName
o String lastName
o String email
--> Hobby[] hobbies optional
}
“爱好”的模型如下:
asset Hobby identified by name {
o String name
}
命名查询具有以下结构:
query selectPersonsByHobby {
description: "Select all persons with a certain hobby."
statement:
SELECT org.comp.myapp.Person
WHERE //don't know what to put here//
}
我不知道在“WHERE”运算符之后放什么来实现我想要的。
我想要以下内容:
query selectPersonsByHobby {
description: "Select all persons with a certain hobby."
statement:
SELECT org.comp.myapp.Person
WHERE (hobbies.contains(_$hobby))
}
这甚至可能吗?
解决方案
简短的回答是这个查询应该有效:
query selectConsultantsBySkill {
description: "Select all persons with a certain hobby."
statement:
SELECT org.comp.myapp.Person
WHERE (hobbies CONTAINS _$targetHobby)
}
但请注意,因为您的爱好是一个关系数组,所以 targetHobby 参数必须类似于resource:org.acme.Hobby#cycling
. 在生产场景中,您将从 UI 程序“调用”查询,以便您可以预先挂起关系语法。
我想这只是一个测试示例,但我想知道 Hobby 是否需要建立关系?如果没有会更容易。
您也可以使用概念(甚至是概念中的枚举类型!)。这是一个修改后的模型和带有概念的查询的示例:
participant Person identified by id {
o String id
o String firstName
o String lastName
o String email
o Interest[] passTime
}
concept Interest {
o String name
o String description
}
query selectConsultantsBySkill {
description: "Select all persons with a certain hobby."
statement:
SELECT org.comp.myapp.Person
WHERE (passTime CONTAINS (name == _$targetHobby ))
}
推荐阅读
- javascript - 如何从子包中获取 .babelrc?
- select - 为什么datawindow查询不刷新列规范?
- javascript - 我如何重新定位我以前的光滑箭头以变得可操作?
- python - 如何模拟 Vault hvac.Client() 方法
- javascript - Choropleth 地图上的 D3js HTML 工具提示
- cmake - 如何设置不同的CMAKE_EXE_LINKER_FLAGS取决于不同的add_executable?
- javascript - 谷歌地图聚类不适用于单个位置
- oracle-adf - 无法根据我的 systemLocal 变量呈现 outputText
- ruby-on-rails - 创建操作后更新数据库不起作用
- swift - UITableViewCell 中的 UICollectionViewCell 中的按钮点击操作