forked from hyperledger-archives/composer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Short branch (hyperledger-archives#1277)
* Updates for work * Adding Installing Index to ToC * Removing Fabric Composer name * Removing Fabric composer name * Moving images for REST API doc * Fabric Composer Name removal * Fabric Composer name removal * Other name changes (Stack Overflow, GitHub, Rocket.Chat, JavaScript) * wording updates and bug splats * ToC Updates * HLv1 docs updates, couple more bug splats. * Last edit for HLv1 * Whoops, bug splat * Another bug splat... * Quick fixes prereqs navbar * intro diagram fix and bug fixes * Fixes and updates * Rollback optional script for v1.0 * QoL changes and rollback changes - Quickstart * Link fixes * Atom links fix, formatting fix * Odd formatting fix. * Name change and codeblock fix * More odd formatting fixes * Ubuntu root user doc fix + draft of bnd doc changes * update for CLI define + deploy BNA * last bnd update * Events and bug fixes * Last event thing * Updates for #803 and hyperledger-archives#822 * removing unnecessary stuff * Undeploy support #673 * Clarifications on undeploy * Commit? * Revert "Commit?" This reverts commit 9094568. * Quick Fixes * Quick fix for connection profile keyvalstore * Updates to show events docs in ToC * Quick fixes * Last minute docs updates. * changes from issue #912 Signed-off-by: Edward Prosser <[email protected]> * Version 1 auto-generating landing pages * Docs Updates week 2 * 1 more set of updates * last changes * HLFV1 Beta and Query (hyperledger-archives#1247) (hyperledger-archives#1255) System and unit tests Rich query support for fabric V1 alpha Alpha 2 Support * Move HLF v0.6 to use Duktape instead of Otto (hyperledger-archives#1257) * Connection profile, identity import, logic.js * Query v0.1 * Connection profile, Query, Security, Dev Guide * Security updates for local playground * Last minute updates
- Loading branch information
Showing
7 changed files
with
135 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
packages/composer-website/jekylldocs/business-network/query.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--- | ||
layout: default | ||
title: Querying Business Network Data | ||
category: tasks | ||
section: business-network | ||
sidebar: sidebars/businessnetworks.md | ||
excerpt: Using {{site.data.conrefs.hlf_full}} and CouchDB, you can query assets in the stored world-state and return listed assets by using a transaction processor function. | ||
--- | ||
|
||
# Querying business network data | ||
|
||
>Warning | ||
The status of this feature is experimental. You **must** use Hyperledger Composer v0.8+ with the the HLFv1 runtime to use queries. We welcome feedback and comments while we continue to iterate upon query functionality. The API may change based on the feedback received. In future releases we plan to extend this feature with a Composer specific query language, and data-binding to assets, participants and transactions. | ||
|
||
{{site.data.conrefs.hlf_full}} v1.0 can be configured to store the world-state in a CouchDB database. CouchDB is a JSON document store, so all data in the world-state is persisted as JSON documents, including Composer assets, participants and transactions. | ||
|
||
When {{site.data.conrefs.hlf_full}} is used in CouchDB mode chaincode can execute complex (content-based) queries against the world-state data. The queries are written in the Mango query language, the native CouchDB query language. | ||
|
||
An example Mango _selector_ query: | ||
var q = { | ||
selector: { | ||
size: 'SMALL' | ||
} | ||
}; | ||
|
||
This query will select all JSON documents in the document store that contain the property `size` that has the value `SMALL`. Please refer to the CouchDB documentation for the [query syntax for Mango queries](http://docs.couchdb.org/en/2.0.0/api/database/find.html). Note that CouchDB ships with a powerful web interface called [Fauxton](http://couchdb.apache.org/fauxton-visual-guide/). You can use Fauxton to inspect the documents in the document store, run queries, view results etc. | ||
|
||
### Running Native CouchDB Mango Queries from Transaction Processor Functions | ||
|
||
The Composer runtime API includes the `queryNative(queryString)` method, allowing transaction processor functions to submit native Mango queries to CouchDB. Composer will execute the query against CouchDB, returning a promise to a JS Object that captures the results of running the query. | ||
|
||
The JS Object returned is composed of an array of objects, each with a `Key` and `Record` property. `Key` is a string that represents the key of the document in the document store. `Record` is a JS Object that captures the data for the document itself. | ||
|
||
### Example | ||
|
||
The example below runs a content-based query to select all `SMALL` marbles, verifies the number of marbles returned, and that they are indeed all `SMALL`. | ||
``` | ||
/** | ||
* Executes a CouchDB query and checks the results. | ||
* @param {org.fabric_composer.marbles.QueryMarbleByOwner} transaction | ||
* @transaction | ||
* @return {Promise} a promise to the results of transaction processing | ||
*/ | ||
function onQueryMarbleByOwner(transaction) { | ||
var factory = getFactory(); | ||
// create the query | ||
var q = { | ||
selector: { | ||
size: 'SMALL' | ||
} | ||
}; | ||
return queryNative(JSON.stringify(q)) | ||
.then(function (resultArray) { | ||
print('TP function received query result: ', JSON.stringify(resultArray)); | ||
if (resultArray.length !== 5) { | ||
throw new Error('The incorrect number of marbles found: ', resultArray.length); | ||
} | ||
for (var x = 0; x < resultArray.length; x++) { | ||
var currentResult = resultArray[x]; | ||
if (currentResult.Record.size !== 'SMALL') { | ||
throw new Error('Query returned a marble that is not SMALL!', currentResult.Record); | ||
} | ||
} | ||
}); | ||
} | ||
``` | ||
|
||
Using a selector it is possible to query all assets of a given type, with a given set of properties, and then to convert them back into Composer resources using `getSerializer().fromJSON(jsObject)`. Once the JS object returned by a query have been converted back into a Composer object it can be updated and persisted back into an asset registry. | ||
|
||
>Note that in the future Composer will define a query language expressed in terms of assets, participants and transactions and automatically marshall the JS objects returned by CouchDB to the corresponding Composer modelled types. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ All the options are required. The `userId` doesn't have to match any information | |
## Syntax example | ||
|
||
``` | ||
composer identity import -p hlfv1 -u Org1PeerAdmin -c admin.pem -k 9022d671ceedbb24af3ea69b5a8136cc64203df6b9920e26f48123fcfcb1d2e9_sk | ||
node cli.js identity import -p hlfv1 -u PeerAdmin -c ./peerOrganizations/org1.example.com/users/[email protected]/signcerts/[email protected].pem -k ./peerOrganizations/org1.example.com/users/[email protected]/keystore/9022d671ceedbb24af3ea69b5a8136cc64203df6b9920e26f48123fcfcb1d2e9_sk | ||
``` | ||
|
||
## Options | ||
|
@@ -32,8 +32,8 @@ Options: | |
-v, --version Show version number [boolean] | ||
--connectionProfileName, -p The connection profile name [string] [required] | ||
--userId, -u The user ID for the new identity [string] [required] | ||
--signerCertFile, -c signerCert path [string] [required] | ||
--keyFile, -k key file [string] [required] | ||
--publicKeyFile, -c File containing the public key [string] [required] | ||
--privateKeyFile, -k File containing the private key [string] [required] | ||
``` | ||
|
||
#### Define connection profile name | ||
|
@@ -54,15 +54,15 @@ Example: `-u Org1PeerAdmin` | |
|
||
#### Define signers public certificate | ||
|
||
`-c` or `--signerCertFile` | ||
`-c` or `--publicKeyFile` | ||
|
||
Example: `-c admin.pem` | ||
|
||
--- | ||
|
||
#### Define signers private key file | ||
|
||
`-k` or `--keyFile` | ||
`-k` or `--privateKeyFile` | ||
|
||
Example: `-k 9022d671ceedbb24af3ea69b5a8136cc64203df6b9920e26f48123fcfcb1d2e9_sk` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.