UNPKG

spahql

Version:

A query language and data model for deep Javascript object structures.

214 lines (175 loc) 5.5 kB
<!DOCTYPE html> <html> <head> <title>Try SpahQL</title> <link rel="stylesheet" href="css/normalize.css" type="text/css" media="screen" /> <link rel="stylesheet" href="css/nav.css" type="text/css" media="screen" /> <link rel="stylesheet" href="css/ir_black.css" type="text/css" media="screen" /> <link rel="stylesheet" href="css/repl.css" type="text/css" media="screen" /> <script type="text/javascript" src="js/highlight.pack.js"></script> <script type="text/javascript" src="js/jquery.1.5.2.min.js"></script> <script type="text/javascript" src="js/jquery.scrollTo-1.4.2-min.js"></script> <script type="text/javascript" src="js/spahql-min.js"></script> <script type="text/javascript" src="js/spahql-repl.js"></script> <script type="text/javascript" src="js/nav.js"></script> <script type="text/javascript"> $(document).ready(function() { hljs.initHighlighting(); Nav.init(function(overview) { $("nav .current").first().after(overview); }); }); </script> </head> <body> <a href="https://github.com/danski/spahql"><img style="position: fixed; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png" alt="Fork me on GitHub"></a> <div class="nav-wrapper"> <nav id="nav-overview" class="overview"> <h3>SpahQL</h3> <h4 class="current"><a href="repl.html">Try SpahQL</a></h4> <h4><a href="index.html">SpahQL Manual</a></h4> <h4><a href="src/index.html">API</a></h4> </nav> </div> <article> <script type='text/javascript'> $(function() { var repl = new REPL(); $("#REPL").submit(function(e) { e.preventDefault(); var $form = $(this), $input = $("#json", $form), $query = $("#query", $form), $target = $("#print", $form); repl.exec($input.val(), $query.val(), $target); return false; }); }); </script><form method='GET' action='#' id='REPL'> <h1>Try SpahQL</h1> <fieldset class='read'> <label for='json'>JSON data</label> <textarea name='json' class='text' id='json'> { "hash1": { "a": "hash.a", "b": "hash.b", "c": "hash.c", "subhash": { "a": "hash.subhash.a", "b": "hash.subhash.b", "c": "hash.subhash.c" } }, "hash2": { "a": "hash.a", "b": "hash.b", "c": "hash.c", "subhash": { "a": "hash.subhash.a", "b": "hash.subhash.b", "c": "hash.subhash.c" } }, "arr1": [ "first", "second", "third", "fourth", "fifth" ], "arr2": [ "first", "second", "third", "fourth", "fifth" ], "arrayofobjects": [ { "a": "AA 0", "b": "BB 0", "c": "CC 0", "subhash": { "a": "AAAA 0", "b": "BBBB 0", "c": "CCCC 0" } }, { "a": "AA 1", "b": "BB 1", "c": "CC 1", "subhash": { "a": "AAAA 1", "b": "BBBB 1", "c": "CCCC 1" } }, { "a": "AA 2", "b": "BB 2", "c": "CC 2", "subhash": { "a": "AAAA 2", "b": "BBBB 2", "c": "CCCC 2" } } ] } </textarea> </fieldset> <fieldset class='execute'> <label for='query'>SpahQL query</label> <input name='query' class='text' id='query' type='text' /> <input class='submit' type='submit' value='Run' /> </fieldset> <div class='print' id='print'> </div> </form> <h1 id='examples'>Examples</h1> <p>Select from an object by path:</p> <pre><code>/hash/subhash</code></pre> <p>Select from an array:</p> <pre><code>/arr1/0 /arr2/1 /arr1/2 ...</code></pre> <p>Select from an array of objects:</p> <pre><code>/arrayofobjects/0/a</code></pre> <p>Select recursively by path:</p> <pre><code>/arrayofobjects//a //-&gt; all &quot;a&quot; keys in /arrayofobjects</code></pre> <p>Select all keys in an object:</p> <pre><code>/hash1/* //-&gt; all keys from /hash1</code></pre> <p>Select all matching a criteria:</p> <pre><code>//*[/.type == &#39;array&#39;][/.size &gt; 0] //-&gt; all non-empty arrays</code></pre> <p>Set literals:</p> <pre><code>{&quot;extra string&quot;, /arr1/0, /arr2/*} //-&gt; A single set containing a string literal, the first item from /arr1 and all items from /arr2</code></pre> <p>Basic literals:</p> <pre><code>3 &quot;three&quot; true false</code></pre> <p>Properties:</p> <pre><code>/.size //-&gt; Number of keys on the root object /arr1/.size //-&gt; Length of /arr1 /arr1/0/.size //-&gt; Length of string at /arr1/0 /arr1/.type //-&gt; &quot;array&quot; /.type //-&gt; &quot;object&quot;</code></pre> <p>Basic equalities:</p> <pre><code>/hash1/a == &quot;does the value match this?&quot; /hash1 == /hash2 //-&gt; will be compared recursively</code></pre> <p>Basic inequalities:</p> <pre><code>/arr1/.size &gt; 10 //-&gt; /arr1 longer than 10 items? /arr1/0/.size &lt;= 100 //-&gt; /arr/0 is 100 characters or less?</code></pre> <p>Rough equalities:</p> <pre><code>/hash1/a =~ &quot;^value matches this regex\?&quot;</code></pre> <p>Supersets:</p> <pre><code>//a }&gt;{ &quot;is there an &quot;a&quot; key matching this?&quot;</code></pre> <p>Subsets:</p> <pre><code>/hash1/a }&lt;{ {&quot;does&quot;, &quot;the&quot;, &quot;value&quot;, &quot;match&quot;, &quot;any of these?&quot;}</code></pre> <p>Joint sets:</p> <pre><code>//a }~{ {&quot;any&quot;, &quot;&#39;a&#39; keys&quot;, &quot;matching&quot;, &quot;any of these?&quot;}</code></pre> <p>Disjoint sets:</p> <pre><code>//a }!{ {&quot;none of the&quot;, &quot;&#39;a&#39; keys&quot;, &quot;match&quot;, &quot;any of these&quot;}</code></pre> </article> </body> </html>