MCPcopy Create free account
hub / github.com/ByteStorage/FlyDB / Put

Method Put

engine/grpc/client/string.go:11–43  ·  view source on GitHub ↗

Put puts a key-value pair into the db by client api

(key string, value interface{})

Source from the content-addressed store, hash-verified

9
10// Put puts a key-value pair into the db by client api
11func (c *Client) Put(key string, value interface{}) error {
12 client, err := newGrpcClient(c.Addr)
13 if err != nil {
14 return errors.New("new grpc client error: " + err.Error())
15 }
16 req := &gstring.SetRequest{Key: key}
17 switch v := value.(type) {
18 case string:
19 req.Value = &gstring.SetRequest_StringValue{StringValue: v}
20 case int32:
21 req.Value = &gstring.SetRequest_Int32Value{Int32Value: v}
22 case int64:
23 req.Value = &gstring.SetRequest_Int64Value{Int64Value: v}
24 case float32:
25 req.Value = &gstring.SetRequest_Float32Value{Float32Value: v}
26 case float64:
27 req.Value = &gstring.SetRequest_Float64Value{Float64Value: v}
28 case bool:
29 req.Value = &gstring.SetRequest_BoolValue{BoolValue: v}
30 case []byte:
31 req.Value = &gstring.SetRequest_BytesValue{BytesValue: v}
32 default:
33 return errors.New("unknown value type")
34 }
35 put, err := client.Put(context.Background(), req)
36 if err != nil {
37 return errors.New("client put failed: " + err.Error())
38 }
39 if !put.Ok {
40 return errors.New("put failed")
41 }
42 return nil
43}
44
45// Get gets a value by key from the db by client api
46func (c *Client) Get(key string) (interface{}, error) {

Callers

nothing calls this directly

Calls 2

newGrpcClientFunction · 0.85
PutMethod · 0.65

Tested by

no test coverage detected