Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
Mathias Rangel Wulff edited this pageJul 2, 2018 ·3 revisions

KeywordSEARCH

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

More relevant example:

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 array
  • AS @team - save result into temporary variableteam
  • members - take member property of previous result
  • / - walk over all members of members array
  • AS @member - save result into temporary variablemember
  • categories - take category property of previous result
  • /- walk over categories array
  • RETURN(...) - pseudo-function to create result record
  • RETURN(@team->teamname AS team,...) - take temporary variable 'team', take its teamname property and store it as team property of result object
  • FROM ? - standard source from array clause
  • alasql('...',[data]) - take source data fromdata array

Other examples ofSEARCH operator:

  • [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

Clone this wiki locally


[8]ページ先頭

©2009-2025 Movatter.jp