- Notifications
You must be signed in to change notification settings - Fork689
SEARCH
AlaSQLSEARCH operator is designed to traverse over JSON objects and graphs and is inspired by theOrientDB graph search
Syntax:
SEARCH selectors [FROM (table|object)]You can use it with graphs:
varres=alasql('SEARCH / "Harry" PATH("Roger") VERTEX name');
or with JSON files:
varcatalog={Europe:{fruits:[{fruit:'Apple'},{fruit:'Peach'},]},Asia:{fruit:'Pineapple'},Africa:{fruit:'Banana'}};varres=alasql('SEARCH Europe FROM ?',[catalog]);// [{fruits: [// {fruit:'Apple'},// {fruit:'Peach'},// ]}]);varres=alasql('SEARCH /fruits/ FROM ?',[catalog]);// [{fruit:'Apple'}, {fruit:'Peach'}]varres=alasql('SEARCH /fruits/fruit FROM ?',[catalog]);// ['Apple','Peach']varres=alasql('SEARCH /fruits/WHERE(fruit="Apple") FROM ?',[catalog]);// [{fruit:'Apple'}]varres=alasql('SEARCH ///WHERE(fruit="Apple") FROM ?',[catalog]);// [{fruit:'Apple'}]
Have a look atRETURN to modify the output when wanting to finetuneSEARCH outputs
varalasql=require('alasql');vardata=[{teamname:'Alpha',members:[{membername:'Andrey',categories:['JavaScript','C++']},{membername:'Mathias',categories:['JavaScript','PHP']},]},{teamname:'Beta',members:[{membername:'Ole',categories:['JavaScript']}]},];varres=alasql('SEARCH / AS @team \members / AS @member \categories / AS @category \RETURN(@team->teamname AS team, @member->membername AS member, @category AS category) \FROM ?',[data]);console.log(res);
returns
[{team:'Alpha',member:'Andrey',category:'JavaScript'},{team:'Alpha',member:'Andrey',category:'C++'},{team:'Alpha',member:'Mathias',category:'JavaScript'},{team:'Alpha',member:'Mathias',category:'Java'},{team:'Beta',member:'Ole',category:'JavaScript'}]
Here:
SEARCH- search keyword/- walk over all members of arrayAS @team- save result into temporary variableteammembers- take member property of previous result/- walk over all members of members arrayAS @member- save result into temporary variablemembercategories- take category property of previous result/- walk over categories arrayRETURN(...)- pseudo-function to create result recordRETURN(@team->teamname AS team,...)- take temporary variable 'team', take its teamname property and store it as team property of result objectFROM ?- standard source from array clausealasql('...',[data])- take source data fromdataarray
- [How to parse a Json with array and objects and export the data into Excel file](How to parse a Json with array and objects and export the data into Excel file)
The following testfiles has examples on how to useSEARCH: ,test289.js,test292.js,test300.js,test301.js,test302.js,test303.js,test304.js,test305.js,test306.js,test307.js,test308.js,test309.js,test310.js,test311.js,test312.js,test313.js,test314.js,test315.js,test318.js,test319.js,test320.js,test321.js,test322.js,test323.js,test328.js,test337.js,test343.js,test346.js,test385.js,test386.js,test406.js,test411.js, andtest606.js
See also:RETURN
© 2014-2026,Andrey Gershun &Mathias Rangel Wulff
Please help improve the documentation by opening a PR on thewiki repo