2024-04-13 13:31:28 +08:00
|
|
|
package schema
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/schema_pb"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Schema struct {
|
|
|
|
RecordType *schema_pb.RecordType
|
2024-05-21 02:03:56 +08:00
|
|
|
fieldMap map[string]*schema_pb.Field
|
2024-04-13 13:31:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewSchema(recordType *schema_pb.RecordType) (*Schema, error) {
|
2024-05-21 02:03:56 +08:00
|
|
|
fieldMap := make(map[string]*schema_pb.Field)
|
2024-04-13 13:31:28 +08:00
|
|
|
for _, field := range recordType.Fields {
|
2024-04-18 14:49:21 +08:00
|
|
|
fieldMap[field.Name] = field
|
2024-04-13 13:31:28 +08:00
|
|
|
}
|
|
|
|
return &Schema{
|
|
|
|
RecordType: recordType,
|
2024-05-21 02:03:56 +08:00
|
|
|
fieldMap: fieldMap,
|
2024-04-13 13:31:28 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2024-04-18 14:49:21 +08:00
|
|
|
|
|
|
|
func (s *Schema) GetField(name string) (*schema_pb.Field, bool) {
|
|
|
|
field, ok := s.fieldMap[name]
|
|
|
|
return field, ok
|
|
|
|
}
|