Reputation: 353
I need to select all agents from couchbase bucket. I am using https://github.com/couchbase/gocb package to work with couchbase.
My current query looks like:
SELECT a.* FROM `agents` a WHERE a.type=$1
But I feel I need to replace bucket name with some placeholder, or parameter that will be set before sending query to couchbase.
Can anyone tell me how to do that (without Sprintf
:) )?
For now I am using this helper function:
import (
"strings"
"gopkg.in/couchbase/gocb.v1"
)
const bucketPlaceholder = "{{bucket}}"
func PrepareQuery(b *gocb.Bucket, q string) string {
return strings.ReplaceAll(q, bucketPlaceholder, b.Name())
}
Upvotes: 0
Views: 114