mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-31 03:18:43 -06:00
Ref Values now have a TargetRef() method that returns the ref.Ref of the target the Value is referencing. Note: This is a breaking change. In old code the Ref() of the Value was the Ref of the underlying target. Fixes #464
50 lines
1.2 KiB
Cheetah
50 lines
1.2 KiB
Cheetah
{{$typesPackage := .TypesPackage}}
|
|
|
|
// {{.Name}}
|
|
|
|
type {{.Name}} struct {
|
|
target ref.Ref
|
|
ref *ref.Ref
|
|
}
|
|
|
|
func New{{.Name}}(target ref.Ref) {{.Name}} {
|
|
return {{.Name}}{target, &ref.Ref{}}
|
|
}
|
|
|
|
func (r {{.Name}}) TargetRef() ref.Ref {
|
|
return r.target
|
|
}
|
|
|
|
func (r {{.Name}}) Ref() ref.Ref {
|
|
return {{$typesPackage}}EnsureRef(r.ref, r)
|
|
}
|
|
|
|
func (r {{.Name}}) Equals(other {{$typesPackage}}Value) bool {
|
|
if other, ok := other.({{.Name}}); ok {
|
|
return r.Ref() == other.Ref()
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (r {{.Name}}) Chunks() []{{$typesPackage}}Future {
|
|
return r.TypeRef().Chunks()
|
|
}
|
|
|
|
func {{.Name}}FromVal(val {{$typesPackage}}Value) {{.Name}} {
|
|
// TODO: Do we still need FromVal?
|
|
if val, ok := val.({{.Name}}); ok {
|
|
return val
|
|
}
|
|
return New{{.Name}}(val.({{$typesPackage}}Ref).TargetRef())
|
|
}
|
|
|
|
{{template "type_ref.tmpl" .}}
|
|
|
|
func (r {{.Name}}) TargetValue(cs chunks.ChunkSource) {{userType .ElemType}} {
|
|
return {{valueToUser (printf "%sReadValue(r.target, cs)" $typesPackage) .ElemType}}
|
|
}
|
|
|
|
func (r {{.Name}}) SetTargetValue(val {{userType .ElemType}}, cs chunks.ChunkSink) {{.Name}} {
|
|
return New{{.Name}}({{$typesPackage}}WriteValue({{userToValue "val" .ElemType}}, cs))
|
|
}
|