How to update previous inserted data?

I am using the javascript WOQL API to create and insert data (WOQL.query(…) to insert data.
.add_triple(‘doc:city1’, ‘type’, ‘scm:City’)
.add_triple(‘doc:city1’, ‘id’, Q.literal(1, ‘xsd:integer’))
.add_triple(‘doc:city1’, ‘object_id’, Q.literal(1, ‘xsd:integer’))
.add_triple(‘doc:city2’, ‘type’, ‘scm:City’)
.add_triple(‘doc:city2’, ‘id’, Q.literal(2, ‘xsd:integer’))
.add_triple(‘doc:city2’, ‘object_id’, Q.literal(3, ‘xsd:integer’))
How do I update data for this query. How would I change the object_id for doc:city1 and doc:city2


Hello orioncri

The easiest way would be just to delete the triple of interest and then add the triple back with updated value.

let docId='doc:city1'

WOQL.and (
    WOQL.delete_triple(docId, 'object_id', 'v:object_id'),
    WOQL.add_triple(docId, 'object_id', WOQL.literal(5, ‘xsd:integer’))

You can do the same for doc:city2 :grinning:

1 Like

Is there an update command? I may need to add a comment for the update as well.
Are all comments kept or does a new comment overwrite the previous comment?

Hi orioncri,

Yes we do have an update_triple command

let docId='doc:city1'

update_triple(docId, 'comment', 'update comment or whatever new comment')

New comment will be overwritten, when you do an update under the hood the triples are just deleted and overwritten :grinning:

1 Like

I could find an WOQL update_triple. It saying that update_triple is not a function.

Can you send a sample of your code using update_triple, so I can take a look at it?

I think we only added update_triple in 3.0.6 of client - it’s probably an older version. In the meantime, you can just use the underlying woql directly (for any given subject-predicate pair with a new value in new_object):

            WOQL.triple(subject, predicate, "v:AnyObject")
            .delete_triple(subject, predicate, "v:AnyObject")
            .not().triple(subject, predicate, new_object)
        WOQL.add_triple(subject, predicate, new_object)
1 Like

I am currently using the bootstrap container version. I have not pulled from that repo for two months.

Here is my current javascript update logic. It is not failing but I believe it is not working correctly. Please respond with the correct logic if possible.

I also need a select command to pull out the commit message if possible.


    .delete_triple('doc:personContent2', 'first_name', 'v:First Name')
    .add_triple('doc:personContent2', 'first_name', Q.literal('Kelley', 'xsd:string'))
    ,'Test Commit Message'
            WOQL.triple('doc:personContent2',  'first_name', "v:AnyObject")
            .delete_triple('doc:personContent2',  'first_name', "v:AnyObject")
            .not().triple('doc:personContent2', 'first_name',  Q.literal('Kelley', 'xsd:string'))
        WOQL.add_triple('doc:personContent2',  'first_name', Q.literal('Kelley', 'xsd:string'))

There was a bug in an earlier version of WOQL (fixed in 4.0) which meant that you have to not delete the triple if it is already there.

To pull out the latest commit message into (v:Commit Msg), you can use the following:

  WOQL.triple("v:Commit IRI", "ref:commit_id", "v:Commit ID").triple("v:Commit IRI", "ref:commit_message","v:Commit Msg")

How can I pull out all commits for a specific class such as ‘doc:personContent’
FYI - I am trying to search for this commands in your online documentation to no avail.

The query:

triple("v:Person", "type", "scm:PersonContent")
  added_triple("v:Person", "v:Any Added Predicate", "v:Any Added Value"),
  removed_triple("v:Person", "v:Any Deleted Predicate", "v:Any Deleted Value")

Will tell you if there are any updates to triples for a given class in a specific commit. You need to assemble the list of commits to check through a separate query to the commits graph. We are working on a mechanism to make this easier, allowing you to quickly scan a sequence of commits for updates to documents and triples and just returning the relevant commit meta-data records. The current solution is not very performant and is awkward to construct.