<aside> 💡 Owner: @Marcin Hagmajer
</aside>
AskQL is a query language that lets you ask a computer about its resources.
<aside>
💡 For example, if you have access to a computer that shares a resource named hello
and runs AskVM, you may ask it about the value of that resource in the following way.
</aside>
ask {
hello
}
"Hello world, my name is Ask. I'm the core component of AskQL allowing you to easily ask a system to compute something for you."
<aside> 🤖 AskQL queries are AskScript (Ask) programs which can perform any computation you desire.
</aside>
ask {
'Hello world!'
}
"Hello world!"
<aside> ⚙️ Imperative statements can be used to perform transformations.
</aside>
ask {
const factorial = fun (n:int): int {
if (n:lessThan(2)) {
return n
}
n:times(factorial(n:minus(1)))
}
score :factorial
}
120 // for resources { score: 5 }
<aside>
⚡ Ask allows querying many resources at the same time concurrently with the query
expression.
</aside>
ask {
query {
firstName
lastName
}
}
{
firstName: "John"
lastName: "Smith"
}
<aside> 🔍 You can query resources at different levels too.
</aside>
ask {
query {
firstName
lastName
parents {
firstName
lastName
}
}
}
{
firstName: "Luke"
lastName: "Skywalker"
parents: [{
firstName: "Padmé"
lastName: "Amidala"
}, {
firstName: "Anakin"
lastName: "Skywalker"
}],
}
<aside> 🔧 Ask can transform queried data before returning it.
</aside>
ask {
query {
fullName :firstName :concat(' ', lastName) :toUpperCase
}
}
{
fullName: "JOHN SMITH"
}
// for resources { firstName: "John", lastName: "Smith" }
<aside> 🔗 Transformations can be chained together to perform complicated computations.
</aside>
ask {
const sumOfSquares = fun (a:int): int {
const square = fun (a: int): int {
a:times(a) // equivalent of times(n, n)
}
a:square:plus(square(a))
}
score :times(2) :plus(1) :toString :call(fun (s:string): string {
const double = fun (s:string):string {
s:concat(s)
}
s:double // same as s:double()
}) :toInt :sumOfSquares :number
}
2178 // for resources { score: 2 }
<aside>
☝ Values in AskQL can be asserted using special type assertions functions like number
which were also used as type annotations in the anonymous function passed to call
. You can learn more about this in the AskQL Quick Guide.
</aside>