How to delete a document found by a search in the FaunaDB? - go

I can get a searched document as following golang code:
ret, err := client.Query(f.Get(f.MatchTerm(f.Index("label_search_by_externalID"), externalID)))
Then, I tried to delete a searched document as similar manner as follow:
ret, err := client.Query(f.Delete(f.MatchTerm(f.Index("label_search_by_externalID"), externalID)))
But, this code occurs an error:
Response error 400. Errors: [delete](invalid argument): Ref expected, Set provided.
I'm confused, by the API document, both Get and Delete request Ref for a document as param, and MatchTerm returns a Set, not Ref.
Then I have 2 questions.
How can I get the document Ref which the result of the search?
Is there any way to get the document ref from the search result with Index like RefCollection for collection, for example like RefIndex as follows?
ret, err := client.Query(f.Delete(f.RefIndex(f.Index("label_search_by_externalID"), externalID)))
Why my code for getting search result document works well? Is there more good coding for getting search result document?
Thank you for your suggestion!

Get will only return 1 result. If you have multiple values returned from this index search you will have problems. I would suggest the function Paginate(). This will return a set of results, which you can then map over and execute other functionality, such as a get() or delete(). I would strong suggest you look at the following tutorial (https://docs.fauna.com/fauna/current/tutorials/indexes/pagination).
This is pseudo code to delete a page of documents found. You can adjust the page size either up or down:
Map(
Paginate(Match(Index("label_search_by_externalID"), true)),
Lambda("X", Delete(Var("X")))
)

Related

IMPORTXML To Return a Value from dividendhistory.org

I want to return the value of "Yield:" from a series of stocks from a URL dividenhistory.org, for example HDIF into a Google sheet using IMPORTXML, where F7 represents the user supplied ticker.
=IMPORTXML("https://dividendhistory.org/payout/TSX/"&F7, "/html/body/div/div[2]/div[2]/p[4]")
The problem with the above is the yield value is not always located in the same paragraph, depending on the ticker. It also returns with the word "Yield:" as part of the value.
I believe I should be using the XPATH parameter which should find and return the yield value only, but I am lost. I am open to all suggestions!
I tried with a few of the tickers there, and this should work. For example:
=IMPORTXML("https://dividendhistory.org/payout/ctas/", "//p[contains(.,'Yield')]/text()")
Output:
Yield: 1.05%
Obviously, you can change 'ctas' for any user input.
Try this and see if it works on all tickers.
EDIT:
To get only the number 1.05, you need to split the result and output the 2nd part:
=index(split(IMPORTXML("https://dividendhistory.org/payout/ctas/", "//p[contains(.,'Yield')]/text()"), ": "),2)
Output:
0.0105

Powerautomate Parsing JSON Array

I've seen the JSON array questions here and I'm still a little lost, so could use some extra help.
Here's the setup:
My Flow calls a sproc on my DB and that sproc returns this JSON:
{
"ResultSets": {
"Table1": [
{
"OrderID": 9518338,
"BasketID": 9518338,
"RefID": 65178176,
"SiteConfigID": 237
}
]
},
"OutputParameters": {}
}
Then I use a PARSE JSON action to get what looks like the same result, but now I'm told it's parsed and I can call variables.
Issue is when I try to call just, say, SiteConfigID, I get "The output you selected is inside a collection and needs to be looped over to be accessed. This action cannot be inside a foreach."
After some research, I know what's going on here. Table1 is an Array, and I need to tell PowerAutomate to just grab the first record of that array so it knows it's working with just a record instead of a full array. Fair enough. So I spin up a "Return Values to Virtual Power Agents" action just to see my output. I know I'm supposed to use a 'first' expression or a 'get [0] from array expression here, but I can't seem to make them work. Below are what I've tried and the errors I get:
Tried:
first(body('Parse-Sproc')?['Table1/SiteConfigID'])
Got: InvalidTemplate. Unable to process template language expressions in action 'Return_value(s)_to_Power_Virtual_Agents' inputs at line '0' and column '0': 'The template language function 'first' expects its parameter be an array or a string. The provided value is of type 'Null'. Please see https://aka.ms/logicexpressions#first for usage details.'.
Also Tried:
body('Parse-Sproc')?['Table1/SiteconfigID']
which just returns a null valued variable
Finally I tried
outputs('Parse-Sproc')?['Table1']?['value'][0]?['SiteConfigID']
Which STILL gives me a null-valued variable. It's the worst.
In that last expression, I also switched the variable type in the return to pva action to a string instead of a number, no dice.
Also, changed 'outputs' in that expression for 'body' .. also no dice
Here is a screenie of the setup:
To be clear: the end result i'm looking for is for the system to just return "SiteConfigID" as a string or an int so that I can pipe that into a virtual agent.
I believe this is what you need as an expression ...
body('Parse-Sproc')?['ResultSets']['Table1'][0]?['SiteConfigID']
You can see I'm just traversing down to the object and through the array to get the value.
Naturally, I don't have your exact flow but if I use your JSON and load it up into Parse JSON step to get the schema, I am able to get the result. I do get a different schema to you though so will be interesting to see if it directly translates.

use match statement when using neo4j driver, the returned result.record is nil

match statement:
result, errRet = session.Run("MATCH (n) return n", nil)
log.Printf("hello here: %+v", result)
result:
&{err:<nil> iter:0xc00017c600 stream:0xc00072b020 cypher:MATCH (n) return n params:map[] allReceived:false unconsumed:{root:{next:<nil> prev:<nil> list:<nil> Value:<nil>} len:0} record:<nil> summary:<nil>}
actual data in db:
As i searched and couldn't find the answer. Plz show me which part i'm wrong, and very appreciated for it.
btw, create statement really works fine for me.
Initially, the result.record field points to a position before the first record, so it is nil. You need to call record.Next() to move it to the first record. Usually it's done in a loop:
for result.Next() {
log.Printf("The current record is: %+v", result.Record())
}
See parsing result values

Accessing fields in a GO structure

I am new to the Golang world and trying to parse a json response returned by AWS API.
I've tried parsing the result by dot notation and seem to get success in the higher levels. Below is what my experimentation resulted to.
For brevity I excluded other fields
Test 1
fmt.Println(result)
returns
{
DBClusterSnapshots: [{
Status: "available"
}]
}
Test 2
fmt.Println(result.DBClusterSnapshots[0])
returns
{
Status: "available"
}
Test 3
fmt.Println(result.DBClusterSnapshots[0].Status)
returns what seem to be a reference to an object
0xc0001e74c8
Given the last example (Test 3) how do I parse it properly to get the value of Status which is "available"
As pointed out by #mkopriva
Status is a pointer and therefore need to be dereference when intending to extract the string.
so to achieve extracting the value of status we can dereference it like this.
s := *result.DBClusterSnapshots[0].Status
fmt.Println(s)

Kubernetes go client: list events

I am trying to get a list of events in the namespace, but with or without FieldSelector I get an empty list. Is this the right way to do it?
eventListOptions := metav1.ListOptions{FieldSelector: fields.OneTermEqualSelector("involvedObject.name", job.Name).String()}
jobEvents, _ := clientset.EventsV1beta1().Events(GetNamespace()).List(eventListOptions)
If you print error return by List, you should get error something like "involvedObject.name" is not a known field selector: only "metadata.name", "metadata.namespace"
use CoreV1 instead of EventsV1beta1
The line will be something like below:
jobEvents, _ := clientset.CoreV1().Events(GetNamespace()).List(eventListOptions)
"involvedObject.name", job.Name isn't supported by EventsV1beta1
Hope it'll help.

Resources