Skip to main content

Add vote Smart Function

Now, we have a smart function, voteWhere. This function returns a string with the relevant where clause. If we use this where clause in a query, we will be able to look up the results of the proposed vote for the relevant subject, predicate, and object we are updating.

Remember, this is the query we want to issue:

{
"select": {"?vote": ["*"]},
"where": [
["?change", "change/subject", (?sid)],
["?change", "change/predicate", (?pid)],
["?change", "change/object", (?o)],
["?change", "change/vote", "?vote"]
]
}

We will create smart function that replicates this query. We will call the function, vote as you see below.

[
{
"_id": "_fn",
"name": "vote",
"code": "SMART FUNCTION HERE"
}
]

It is your job to write the smart function code.

There is a built-in universal smart function, query, that takes the query as a string. We can use the (voteWhere) function we created for the where clause. We'll have to concatenate (using str) (voteWhere) with the rest of the

Write The Code for vote


Follow the instructions above to write the code for vote.