using schemaless data for Hyperledger Fabric/Composer?


using schemaless data for Hyperledger Fabric/Composer?
I need to store data from json files in hyperledger. The data is schemales. Hyperledger Fabric uses Couchdb which stores schemaless data.
I need to query the data later on.
But im unsure if Fabric can handle schemaless data because of the asset definition that is see in the example projects for example (in the marble project)
// ----- Marbles ----- //
type Marble struct
ObjectType string `json:"docType"` //field for couchdb
Id string `json:"id"` //the fieldtags are needed to keep case from bouncing around
Color string `json:"color"`
Size int `json:"size"` //size in mm of marble
Owner OwnerRelation `json:"owner"`
I know that in Composer you can't store schemaless data since you have to use assets.
1 Answer
1
ok, so the modeling language provides a structure for a business network (modeled structure for assets, participants and transaction classes etc etc) because they are important features of a business network/smart contract. The Composer query language provides for retrieval of JSON data, which can be a search pattern, including containing a schemaless structure (its just data at the end of the day) - example below. Although the business network uses a model driven structure (for the reasons stated) it doesn't mean you cannot store schemaless JSON (as you asked above) and query it later in Composer - in the sense that you can store JSON documents in an asset (in Composer) - example is shown below, it may not or may not be what you want - but it can handle schemaless data that you can retrieve.
Lets say I have an asset called SampleAsset
which is defined as :
SampleAsset
asset SampleAsset identified by assetId
o String assetId
o String JSONattributes
and the following assets:
asset 1:
"$class": "org.example.basic.SampleAsset",
"assetId": "1",
"JSONattributes": [
"element1:'/node/attribute/address/DE/NRW/Aeechen/samplestreet/100/1/1','urls':'http://localhost:/web/path1','control_int_array': '[1,2, 3, 4]':'array_of_paths': ['http://localhost:5001', 'http://localhost:5002]'",
"element2:'/node/attribute/address/DE/NRW/boeblingen/samplestreet/100/1/1','urls':'http://localhost:/web/path2','control_int_array': '[4,5, 6, 7]','array_of_paths': ['http://localhost:5002', 'http://localhost:5003]'",
""element3":"/node/attribute/address/DE/NRW/bielefeld/samplestreet/100/1/1","urls":"http://localhost:/web/path3","control_int_array": "[9,10, 11, 12]","array_of_paths": "['http://localhost:9002', 'http://localhost:10003]" "
]
asset 2:
"$class": "org.example.basic.SampleAsset",
"assetId": "22",
"JSONattributes": [
"element",
"element1",
"element2:'/node/attribute/address/DE/NRW/boeblingen/samplestreet/100/1/1','urls':'http://localhost:/web/path2','control_int_array': '[4,5, 6, 7]','array_of_paths': ['http://localhost:5002', 'http://localhost:5003]'",
"'element3':'/node/attribute/address/DE/NRW/Aachen/samplestreet/100/1/1','urls':'http://localhost:/web/path1','control_int_array': '[1,2, 3, 4]':'array_of_paths': ['http://localhost:5001', 'http://localhost:5002]'"
]
you can see I've not defined any real structure to storing this JSON metadata.
If I had a query as:
query containsJSONsgl
description: "test singular"
statement:
SELECT org.example.basic.SampleAsset
WHERE ( JSONattributes CONTAINS "element2:'/node/attribute/address/DE/NRW/boeblingen/samplestreet/100/1/1','urls':'http://localhost:/web/path2','control_int_array': '[4,5, 6, 7]','array_of_paths': ['http://localhost:5002', 'http://localhost:5003]'" )
or
query containsJSONmulti
description: "test multi"
statement:
SELECT org.example.basic.SampleAsset
WHERE ( JSONattributes CONTAINS ["element2:'/node/attribute/address/DE/NRW/boeblingen/samplestreet/100/1/1','urls':'http://localhost:/web/path2','control_int_array': '[4,5, 6, 7]','array_of_paths': ['http://localhost:5002', 'http://localhost:5003]'", "element1:'/node/attribute/address/DE/NRW/Aeechen/samplestreet/100/1/1','urls':'http://localhost:/web/path1','control_int_array': '[1,2, 3, 4]':'array_of_paths': ['http://localhost:5001', 'http://localhost:5002]'"] )
I could run a query as follows to get the results I want - obviously I've used literals above in the WHERE clause, but you get the picture"
let result = await query('containsJSONsgl');
for (var n = 0; n < result.length; n++)
console.log("Identifier is " + result[n].getIdentifier() );
console.log("JSON data is " + result[n].JSONattributes);
and of course thereafter the usual JSON methods (stringify, parse, etc) are available to you.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Comments
Post a Comment