spahql
Version:
A query language and data model for deep Javascript object structures.
214 lines (175 loc) • 5.5 kB
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 //-> all "a" keys in /arrayofobjects</code></pre>
<p>Select all keys in an object:</p>
<pre><code>/hash1/* //-> all keys from /hash1</code></pre>
<p>Select all matching a criteria:</p>
<pre><code>//*[/.type == 'array'][/.size > 0] //-> all non-empty arrays</code></pre>
<p>Set literals:</p>
<pre><code>{"extra string", /arr1/0, /arr2/*} //-> 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
"three"
true
false</code></pre>
<p>Properties:</p>
<pre><code>/.size //-> Number of keys on the root object
/arr1/.size //-> Length of /arr1
/arr1/0/.size //-> Length of string at /arr1/0
/arr1/.type //-> "array"
/.type //-> "object"</code></pre>
<p>Basic equalities:</p>
<pre><code>/hash1/a == "does the value match this?"
/hash1 == /hash2 //-> will be compared recursively</code></pre>
<p>Basic inequalities:</p>
<pre><code>/arr1/.size > 10 //-> /arr1 longer than 10 items?
/arr1/0/.size <= 100 //-> /arr/0 is 100 characters or less?</code></pre>
<p>Rough equalities:</p>
<pre><code>/hash1/a =~ "^value matches this regex\?"</code></pre>
<p>Supersets:</p>
<pre><code>//a }>{ "is there an "a" key matching this?"</code></pre>
<p>Subsets:</p>
<pre><code>/hash1/a }<{ {"does", "the", "value", "match", "any of these?"}</code></pre>
<p>Joint sets:</p>
<pre><code>//a }~{ {"any", "'a' keys", "matching", "any of these?"}</code></pre>
<p>Disjoint sets:</p>
<pre><code>//a }!{ {"none of the", "'a' keys", "match", "any of these"}</code></pre>
</article>
</body>
</html>