apple / apple/foundationdb

Need more examples on go api

Open
#216 8 comments 2 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
16.7k
Forks
1.6k
Avg merge
1d 20h
Merged PRs (30d)
126

Description

need some go examples

see the code comments below
```go
package main

import (
"fmt"
"log"

"github.com/apple/foundationdb/bindings/go/src/fdb"
"github.com/apple/foundationdb/bindings/go/src/fdb/directory"
"github.com/apple/foundationdb/bindings/go/src/fdb/tuple"
)

func main() {
fdb.MustAPIVersion(510)
db := fdb.MustOpenDefault()

nmqDir, err := directory.CreateOrOpen(db, []string{"nmqtest"}, nil)
if err != nil {
log.Fatal(err)
}

testApp := nmqDir.Sub("testapp")
testTopic := "testtopic"

// store messages
_, err = db.Transact(func(tr fdb.Transaction) (ret interface{}, err error) {
for i := 1; i < 70; i++ {
SCKey := testApp.Pack(tuple.Tuple{testTopic, fmt.Sprintf("%02d", i), fmt.Sprintf("%02d", i-1)})
tr.Set(SCKey, []byte("11111"))
}
return
})

// query messages
var keys []string
_, err = db.Transact(func(tr fdb.Transaction) (ret interface{}, err error) {
// I want to query 5 messages from the testTopic from a specify position
// so, is there any solutions for this, may like the python code:
// tr.get_range(begin, fdb.KeySelector.first_greater_than(begin) + 5)
pr, _ := fdb.PrefixRange([]byte("testapp"))
pr.Begin = testApp.Pack(tuple.Tuple{testTopic, fmt.Sprintf("%02d", 4)})
pr.End = testApp.Pack(tuple.Tuple{testTopic, fmt.Sprintf("%02d", 69)})
ir := tr.GetRange(pr, fdb.RangeOptions{Limit: 5}).Iterator()
for ir.Advance() {
k := ir.MustGet().Key
keys = append(keys, string(k))
}
return
})

fmt.Println(keys)

// clear all messages
_, err = db.Transact(func(tr fdb.Transaction) (ret interface{}, err error) {
tr.ClearRange(testApp.Sub(testTopic))
return
})
}
```

so, please add more examples of tuples range and offset ,thans very much : )

Contributor guide

Open the contributing guide

Research direction

Start with the Go API comments and the tuple, directory, and range usage shown in the issue; no repository file or test is identified. Review the Go bindings' existing examples and documentation, then add examples covering tuple ranges and offset-based reads, with the new examples serving as the completion check.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.