-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathclient-query.js
More file actions
51 lines (41 loc) · 1.5 KB
/
client-query.js
File metadata and controls
51 lines (41 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'use strict';
/**
* Part of a course on Hyperledger Fabric:
* http://ACloudFan.com
*
* Tested with Composer 0.20.5
*
* Pre-Requisites
* 1. Launch Fabric - Deploy Aircraft v8
* 2. Poupulate the flight data ... use utility or REST Server
*
* Demostrates the use Client module : query & buildQuery
* 1. Create the Client Connection
* 2. Execute a Named Query using Client Module : query()
* 3. Create a Dynamic Query using Client Module : buildQuery()
* 4. Execute the Query
*/
const bnUtil = require('./bn-connection-util');
// #1 Connect to the airlinev8
bnUtil.cardName='admin@airlinev8';
bnUtil.connect(main);
function main(error){
// for clarity sake - ignored the error
// #2 Execute the named query : AllFlights
return bnUtil.connection.query('AllFlights').then((results)=>{
console.log('Received flight count:', results.length)
var statement = 'SELECT org.acme.airline.aircraft.Aircraft WHERE (aircraftId == _$id)';
// #3 Build the query object
return bnUtil.connection.buildQuery(statement);
}).then((qry)=>{
// #4 Execute the query
return bnUtil.connection.query(qry,{id:'CRAFT01'});
}).then((result)=>{
console.log('Received aircraft count:', result.length);
if(result.length > 0) console.log(result[0].aircraftId);
bnUtil.connection.disconnect();
}).catch((error)=>{
console.log(error);
bnUtil.connection.disconnect();
});
}