Latest news about Bitcoin and all cryptocurrencies. Your daily crypto news habit.
Hyperledger Composer is a very popular Blockchain application development, the popularity is mainly because of it’s ease of use. Learn more.
One of the key component is the Query language which resembles SQL language. In this article I’ll go through how we can build queries for your blockchain application.
In current version of Hyperledger Fabric, the LIMIT and SKIP is not supported it is so in Composer too.
THE DATA MODEL
For this example, I’ll consider the following data model as our application’s data model.
enum UserRole { o ADMIN o MODERATOR o USER}participant User identified by id { o String id o String name o UserRole role o String[] hobbies --> Organization organization}
participant Organization identified by id { o String id o String name}
asset Product identified by id { o String id o String name o String description o Double quantity o DateTime createdAt --> Organization owner}
QUERIES
Get the users based on role. In order to get the list of users based on their roles, we can use the where filter
query Q1 { description: "Select all users based on role" statement: SELECT org.acme.User WHERE (role == "ADMIN")}
Also you can give the value from paramater as below
query Q1 { description: "Select all users based on role" statement: SELECT org.acme.User WHERE (role == _$role)}
Get users based on organization To get the nodes based on their related or associated files you can use the where with following type
query Q2 { description: "Select all users of an organization" statement: SELECT org.acme.User WHERE (organization == "re
Disclaimer
The views and opinions expressed in this article are solely those of the authors and do not reflect the views of Bitcoin Insider. Every investment and trading move involves risk - this is especially true for cryptocurrencies given their volatility. We strongly advise our readers to conduct their own research when making a decision.