LLIST has update and update_all intefaces. PHP client does not seem to be exposing that interface. The actual code would look like
public function updateMany(array $values) {
$status = $this->db->apply($this->key, 'llist', 'update_all', array($this->bin, $values));
$this->processStatusCode($status);
return $this->errorno;
}
public function update($value) {
if (!is_string($value) && !is_int($value) && !is_array($value)) {
$this->errorno = self::ERR_INPUT_PARAM;
$this->error = self::MSG_TYPE_NOT_SUPPORTED;
return $this->errorno;
}
$status = $this->db->apply($this->key, 'llist', 'update', array($this->bin, $value));
$this->processStatusCode($status);
return $this->errorno;
}
If you have php client code handy you should be able to add this to $PHPCLIENT/LDT/LList.php and build.
Other option would be to use apply and directly invoke LLIST udf (LLIST is a UDF module) The parameter as you can see above are array of values of update_all and a single value of update
LLIST bin essentially stores KEY->VALUE pair (Implemented as B+tree in server). When you pass a map type data to LLIST, it looks for keyword key and uses it as KEY sort and passed in data in entirety as VALUE.
Now if you want to update something in the LLIST you need to specify KEY and VALUE. There is no notion of updating only subpart of VALUE.
What you are trying to do would in logic look like
oldValue = llist.find(key)
newValue = updateValue(oldValue)
llist.update(newValue)
which has fundamental problem of two round trips to the server and performing IO twice.
This can be worked around by using UDF which would look like.
listExtention.lua
local llist = required('ldt/lib_llist')
function findAndUpdate(rec, listBin, key, setValue)
if (llist.ldt_exists(rec, listBin)) then
return 1;
end
local rc = 1;
local oldValue = llist.find(rec, listBin, key)
if (oldValue ~= nil) then
oldValue['value'] = setValue;
rc = llist.update(rec, listBin, oldValue);
end
return rc;
end
This function would return 0 in case of success and nonzero in case of failure.
Invocation of this from aql would look like
aql > register module 'listExtension.lua'
aql > execute findAndUpdate('mylist', 0, 86) on test.demo where PK='1'
Note: first parameter which is rec is implicit in UDF system passes it. Others you have to pass.
How does the UDF know, it has to update 86 in the “value” field and not in any other field, say “id”?
The UDF that you created, only updates the value field. Can we pass the bin’s key to UDF as well so that the parameter which needs to be updated is dynamic.
I mean
findAndUpdate('mylist', 0, 86, 'value') // last parameter is the key which needs to be updated
Just want to understand how it works so that I can write my wrapper correctly.
You can pass anything you want to pass to UDF. For example if your entry were {key:0, v1:1, v2:2, v3:3) you can pass newValueMap = {v1:10, v2:30} to indicate set v1’s new value as 10 and v2’s new value as 30.