13.2.1 The JavaScript class Query
The method Prolog.query()
returns an instance of the JavaScript class Query
that may
be used to explore the solutions of the query. The Query
class implements the JavaScript iterator protocol.
- Object Query.next()
- Implements the iterator protocol. This returns an object
holding the keys
done
andvalue
. If exception handling is enabled it returns an object {done
:true
,error
:true
,message
:String}. - Object Query.once()
- Close the query after the first answer. Returns the
.value
of the object returned by.next()
on success and the complete object on failure or error. In addition, on a logical result (no error), a fieldsuccess
is added with a boolean value. Thus, the return value may contain these keys:- {Bindings}
- Query succeeded. Objects holds a key for each output variable. In
addition the
success
key is set totrue
. - {
success
:false} - Query failed. Note that the binding keys all start with an uppercase letter and this is thus not ambiguous.
- {
error
:true,message
:String} - Query raised an exception.
- Object Query.close()
- Closes the query. This can be used inside the iterator to stop further enumeration.