2024-04-22 15:42:18 +08:00
|
|
|
package schema
|
|
|
|
|
|
|
|
import "github.com/seaweedfs/seaweedfs/weed/pb/schema_pb"
|
|
|
|
|
|
|
|
// RecordValueBuilder helps in constructing RecordValue protobuf messages
|
|
|
|
type RecordValueBuilder struct {
|
|
|
|
recordValue *schema_pb.RecordValue
|
|
|
|
}
|
|
|
|
|
2024-04-29 04:42:45 +08:00
|
|
|
// RecordBegin creates a new RecordValueBuilder instance
|
|
|
|
func RecordBegin() *RecordValueBuilder {
|
2024-04-22 15:42:18 +08:00
|
|
|
return &RecordValueBuilder{recordValue: &schema_pb.RecordValue{Fields: make(map[string]*schema_pb.Value)}}
|
|
|
|
}
|
|
|
|
|
2024-04-29 04:42:45 +08:00
|
|
|
// RecordEnd returns the constructed RecordValue message
|
|
|
|
func (rvb *RecordValueBuilder) RecordEnd() *schema_pb.RecordValue {
|
2024-04-22 15:42:18 +08:00
|
|
|
return rvb.recordValue
|
|
|
|
}
|
|
|
|
|
2024-04-29 04:42:45 +08:00
|
|
|
func (rvb *RecordValueBuilder) SetBool(key string, value bool) *RecordValueBuilder {
|
2024-04-22 15:42:18 +08:00
|
|
|
rvb.recordValue.Fields[key] = &schema_pb.Value{Kind: &schema_pb.Value_BoolValue{BoolValue: value}}
|
|
|
|
return rvb
|
|
|
|
}
|
2024-05-02 23:52:10 +08:00
|
|
|
func (rvb *RecordValueBuilder) SetInt32(key string, value int32) *RecordValueBuilder {
|
2024-04-22 15:42:18 +08:00
|
|
|
rvb.recordValue.Fields[key] = &schema_pb.Value{Kind: &schema_pb.Value_Int32Value{Int32Value: value}}
|
|
|
|
return rvb
|
|
|
|
}
|
2024-05-02 23:52:10 +08:00
|
|
|
func (rvb *RecordValueBuilder) SetInt64(key string, value int64) *RecordValueBuilder {
|
2024-04-22 15:42:18 +08:00
|
|
|
rvb.recordValue.Fields[key] = &schema_pb.Value{Kind: &schema_pb.Value_Int64Value{Int64Value: value}}
|
|
|
|
return rvb
|
|
|
|
}
|
2024-05-02 23:52:10 +08:00
|
|
|
func (rvb *RecordValueBuilder) SetFloat32(key string, value float32) *RecordValueBuilder {
|
2024-04-22 15:42:18 +08:00
|
|
|
rvb.recordValue.Fields[key] = &schema_pb.Value{Kind: &schema_pb.Value_FloatValue{FloatValue: value}}
|
|
|
|
return rvb
|
|
|
|
}
|
2024-05-02 23:52:10 +08:00
|
|
|
func (rvb *RecordValueBuilder) SetFloat64(key string, value float64) *RecordValueBuilder {
|
2024-04-22 15:42:18 +08:00
|
|
|
rvb.recordValue.Fields[key] = &schema_pb.Value{Kind: &schema_pb.Value_DoubleValue{DoubleValue: value}}
|
|
|
|
return rvb
|
|
|
|
}
|
2024-04-29 04:42:45 +08:00
|
|
|
func (rvb *RecordValueBuilder) SetBytes(key string, value []byte) *RecordValueBuilder {
|
2024-04-22 15:42:18 +08:00
|
|
|
rvb.recordValue.Fields[key] = &schema_pb.Value{Kind: &schema_pb.Value_BytesValue{BytesValue: value}}
|
|
|
|
return rvb
|
|
|
|
}
|
2024-04-29 04:42:45 +08:00
|
|
|
func (rvb *RecordValueBuilder) SetString(key string, value string) *RecordValueBuilder {
|
2024-04-22 15:42:18 +08:00
|
|
|
rvb.recordValue.Fields[key] = &schema_pb.Value{Kind: &schema_pb.Value_StringValue{StringValue: value}}
|
|
|
|
return rvb
|
|
|
|
}
|
2024-04-29 04:42:45 +08:00
|
|
|
func (rvb *RecordValueBuilder) SetRecord(key string, value *schema_pb.RecordValue) *RecordValueBuilder {
|
|
|
|
rvb.recordValue.Fields[key] = &schema_pb.Value{Kind: &schema_pb.Value_RecordValue{RecordValue: value}}
|
2024-04-22 15:42:18 +08:00
|
|
|
return rvb
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rvb *RecordValueBuilder) addListValue(key string, values []*schema_pb.Value) *RecordValueBuilder {
|
|
|
|
rvb.recordValue.Fields[key] = &schema_pb.Value{Kind: &schema_pb.Value_ListValue{ListValue: &schema_pb.ListValue{Values: values}}}
|
|
|
|
return rvb
|
|
|
|
}
|
|
|
|
|
2024-04-29 04:42:45 +08:00
|
|
|
func (rvb *RecordValueBuilder) SetBoolList(key string, values ...bool) *RecordValueBuilder {
|
2024-04-22 15:42:18 +08:00
|
|
|
var listValues []*schema_pb.Value
|
|
|
|
for _, v := range values {
|
|
|
|
listValues = append(listValues, &schema_pb.Value{Kind: &schema_pb.Value_BoolValue{BoolValue: v}})
|
|
|
|
}
|
|
|
|
return rvb.addListValue(key, listValues)
|
|
|
|
}
|
2024-05-02 23:52:10 +08:00
|
|
|
func (rvb *RecordValueBuilder) SetInt32List(key string, values ...int32) *RecordValueBuilder {
|
2024-04-22 15:42:18 +08:00
|
|
|
var listValues []*schema_pb.Value
|
|
|
|
for _, v := range values {
|
|
|
|
listValues = append(listValues, &schema_pb.Value{Kind: &schema_pb.Value_Int32Value{Int32Value: v}})
|
|
|
|
}
|
|
|
|
return rvb.addListValue(key, listValues)
|
|
|
|
}
|
2024-05-02 23:52:10 +08:00
|
|
|
func (rvb *RecordValueBuilder) SetInt64List(key string, values ...int64) *RecordValueBuilder {
|
2024-04-22 15:42:18 +08:00
|
|
|
var listValues []*schema_pb.Value
|
|
|
|
for _, v := range values {
|
|
|
|
listValues = append(listValues, &schema_pb.Value{Kind: &schema_pb.Value_Int64Value{Int64Value: v}})
|
|
|
|
}
|
|
|
|
return rvb.addListValue(key, listValues)
|
|
|
|
}
|
2024-05-02 23:52:10 +08:00
|
|
|
func (rvb *RecordValueBuilder) SetFloat32List(key string, values ...float32) *RecordValueBuilder {
|
2024-04-22 15:42:18 +08:00
|
|
|
var listValues []*schema_pb.Value
|
|
|
|
for _, v := range values {
|
|
|
|
listValues = append(listValues, &schema_pb.Value{Kind: &schema_pb.Value_FloatValue{FloatValue: v}})
|
|
|
|
}
|
|
|
|
return rvb.addListValue(key, listValues)
|
|
|
|
}
|
2024-05-02 23:52:10 +08:00
|
|
|
func (rvb *RecordValueBuilder) SetFloat64List(key string, values ...float64) *RecordValueBuilder {
|
2024-04-22 15:42:18 +08:00
|
|
|
var listValues []*schema_pb.Value
|
|
|
|
for _, v := range values {
|
|
|
|
listValues = append(listValues, &schema_pb.Value{Kind: &schema_pb.Value_DoubleValue{DoubleValue: v}})
|
|
|
|
}
|
|
|
|
return rvb.addListValue(key, listValues)
|
|
|
|
}
|
2024-04-29 04:42:45 +08:00
|
|
|
func (rvb *RecordValueBuilder) SetBytesList(key string, values ...[]byte) *RecordValueBuilder {
|
2024-04-22 15:42:18 +08:00
|
|
|
var listValues []*schema_pb.Value
|
|
|
|
for _, v := range values {
|
|
|
|
listValues = append(listValues, &schema_pb.Value{Kind: &schema_pb.Value_BytesValue{BytesValue: v}})
|
|
|
|
}
|
|
|
|
return rvb.addListValue(key, listValues)
|
|
|
|
}
|
2024-04-29 04:42:45 +08:00
|
|
|
func (rvb *RecordValueBuilder) SetStringList(key string, values ...string) *RecordValueBuilder {
|
2024-04-22 15:42:18 +08:00
|
|
|
var listValues []*schema_pb.Value
|
|
|
|
for _, v := range values {
|
|
|
|
listValues = append(listValues, &schema_pb.Value{Kind: &schema_pb.Value_StringValue{StringValue: v}})
|
|
|
|
}
|
|
|
|
return rvb.addListValue(key, listValues)
|
|
|
|
}
|
2024-04-29 04:42:45 +08:00
|
|
|
func (rvb *RecordValueBuilder) SetRecordList(key string, values ...*schema_pb.RecordValue) *RecordValueBuilder {
|
2024-04-22 15:42:18 +08:00
|
|
|
var listValues []*schema_pb.Value
|
|
|
|
for _, v := range values {
|
2024-04-29 04:42:45 +08:00
|
|
|
listValues = append(listValues, &schema_pb.Value{Kind: &schema_pb.Value_RecordValue{RecordValue: v}})
|
2024-04-22 15:42:18 +08:00
|
|
|
}
|
|
|
|
return rvb.addListValue(key, listValues)
|
|
|
|
}
|