Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .cog/templates/go/extra/cog/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,15 @@ func ConvertDataqueryToCode(dataquery variants.Dataquery) string {
return NewRuntime().ConvertDataqueryToGo(dataquery)
}

func ConvertDataQueryKindToCode(dataqueryKind any, group string) string {
config, found := NewRuntime().dataqueryVariants[group]
if found && config.GoV2Converter != nil {
return config.GoV2Converter(dataqueryKind)
}

return "/* could not convert dataquerykind to go */"
}

func Dump(root any) string {
return dumpValue(reflect.ValueOf(root))
}
Expand Down
3 changes: 2 additions & 1 deletion .cog/templates/go/extra/cog/variants/variants.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ type DataqueryConfig struct {
Identifier string
DataqueryUnmarshaler func(raw []byte) (Dataquery, error)
StrictDataqueryUnmarshaler func(raw []byte) (Dataquery, error)
GoConverter func(inputPanel any) string
GoConverter func(dataquery any) string
GoV2Converter func(dataquery any) string
}

type Dataquery interface {
Expand Down
12 changes: 11 additions & 1 deletion .cog/templates/go/overrides/schema_variant_dataquery.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,17 @@ func VariantConfig() variants.DataqueryConfig {
return {{ .Schema.EntryPoint|formatObjectName }}Converter(dataquery)
{{- end }}
},
{{- if objectExists "dashboardv2beta1" "DataQueryKind" }}
{{- $dashboardv2beta1 := importPkg "dashboardv2beta1" }}
GoV2Converter: func(input any) string {
if cast, ok := input.(*dashboardv2beta1.DataQueryKind); ok {
return QueryConverter(*cast)
}

return QueryConverter(input.(dashboardv2beta1.DataQueryKind))
},
{{- end }}
{{- end }}
}
}
{{ end }}
{{ end }}