Hyperledger Composer Query Language

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")
}
query Q1 {
description: "Select all users based on role"
statement:
SELECT org.acme.User
WHERE (role == _$role)
}
query Q2 {
description: "Select all users of an organization"
statement:
SELECT org.acme.User
WHERE (organization == "resource:org.acme.Organization#1")
}
query Q3 {
description: "Select all products above the minimum quantity"
statement:
SELECT org.acme.Product
WHERE (quantity > _$minimumThreshold)
}
query Q4 {
description: "Select all products above the minimum quantity of an organization"
statement:
SELECT org.acme.Product
WHERE ((quantity > _$minimumThreshold) AND (owner == _$organization))
}
query Q5 {
description: "Select all products above the minimum quantity of an organization and order by quantity"
statement:
SELECT org.acme.Product
WHERE ((quantity > _$minimumThreshold) AND (owner == _$organization))
ORDER BY quantity
}
query Q6 {
description: "Select all users based on givien hobbies"
statement:
SELECT org.acme.User
WHERE (hobbies CONTAINS ['driving', 'swimming']
}

--

--

DevOps/Cloud | 2x AWS Certified | Terraform | Gitlab

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store