Home > Software engineering >  Aerospike query execution in golang
Aerospike query execution in golang

Time:01-24

Is there any way to implement below query in golang :

select * from test.demo in mapvalues where shopping_cart = "FL"

CodePudding user response:

You should be able to use the Aerospike client for Go. https://github.com/aerospike/aerospike-client-go

CodePudding user response:

Check out the examples in the sandbox: https://developer.aerospike.com/client/usage/queries/basic/secondary

Here is the sample code for a range query on the canonical ufodata set in the sandbox (you would first have to create the secondary index of course):

// Create new query policy
queryPolicy := aerospike.NewQueryPolicy()
queryPolicy.FilterExpression = aerospike.ExpGeoCompare(
    aerospike.ExpGeoBin("location"), 
    aerospike.ExpGeoVal(region))

// Create statement
stmt := aerospike.NewStatement("sandbox", "ufodata")

// Create index filter
stmt.SetFilter(aerospike.NewRangeFilter("occurred", 20210101, 20211231))

// Execute the query
recordSet, err := client.Query(queryPolicy, stmt)

// Get the results
for records := range recordSet.Results() {
    if records != nil { 
        // Do something
        fmt.Printf("Record: %v \n", records.Record.Bins)
    }
}

recordSet.Close()

// Close the connection to the server
client.Close()
  • Related