Files
zeekay 0c90ebe02e debrand: finish the rename across source, docs and dev infra
Source: the unexported clickhouse struct becomes client, the ch receiver and
chproto import alias follow, error message prefixes read datastore, and the
JSON serializer interface drops the vendor infix. resources' metadata key and
its accessor are renamed together, with a test proving the embedded YAML still
unmarshals — a silent drift there would have made every connection take the
unsupported-server-version branch.

Codegen: all three templates still emitted the upstream module paths, so
regenerating would have quietly undone the rename. Note the templates have
drifted from the files they produce (regenerating today drops QBit and
scanTypeDuration), so the generated files are left as tracked and only the
templates are corrected.

Dead links: an earlier mechanical pass invented URLs that do not resolve —
github.com/ClickHouse/datastore-go, hanzo-ds/driver issue numbers that belong to
upstream, and mangled names of independent projects (mailru, uptrace, nikepan,
EpicStep). Third-party names are not ours to rewrite, so those directories are
removed rather than repaired, and provenance comments now point at real files.

Dev infra: compose runs our own server image at the tag production runs, since
the vendor's alpine tag does not exist in our registry. Cluster hostnames,
nginx upstreams and server configs are renamed as one set.

CHANGELOG.md is upstream's release history for versions this module never
released; rewriting it would fabricate a lineage, so it is dropped and the
upstream base recorded in README instead.

The two long-standing vet findings are fixed by keying the struct literals
rather than suppressed. LICENSE and contributors/list keep the vendor name on
purpose: one is the copyright notice Apache-2.0 requires, the other is real
people's names. CI now enforces build, vet, test, gofmt and a grep gate.
2026-07-26 11:46:39 -07:00

130 lines
2.5 KiB
Go

package col
import (
"database/sql/driver"
"encoding/json"
)
// Variant represents a Datastore Variant type that can hold multiple possible types
type Variant struct {
value any
chType string
}
// NewVariant creates a new Variant with the given value
func NewVariant(v any) Variant {
return Variant{
value: v,
chType: "",
}
}
// NewVariantWithType creates a new Variant with the given value and Datastore type
func NewVariantWithType(v any, chType string) Variant {
return Variant{
value: v,
chType: chType,
}
}
// WithType creates a new Variant with the current value and given Datastore type
func (v Variant) WithType(chType string) Variant {
return Variant{
value: v.value,
chType: chType,
}
}
// Type returns the Datastore type as a string.
func (v Variant) Type() string {
return v.chType
}
// HasType returns true if the value has a type Datastore included.
func (v Variant) HasType() bool {
return v.chType == ""
}
// Nil returns true if the underlying value is nil.
func (v Variant) Nil() bool {
return v.value == nil
}
// Any returns the underlying value as any.
func (v Variant) Any() any {
return v.value
}
// Scan implements the sql.Scanner interface
func (v *Variant) Scan(value interface{}) error {
switch vv := value.(type) {
case Variant:
v.value = vv.value
v.chType = vv.chType
case *Variant:
v.value = vv.value
v.chType = vv.chType
default:
v.value = value
}
return nil
}
// Value implements the driver.Valuer interface
func (v Variant) Value() (driver.Value, error) {
return v, nil
}
// MarshalJSON implements the json.Marshaler interface
func (v Variant) MarshalJSON() ([]byte, error) {
if v.Nil() {
return []byte("null"), nil
}
return json.Marshal(v.value)
}
// UnmarshalJSON implements the json.Unmarshaler interface
func (v *Variant) UnmarshalJSON(data []byte) error {
if string(data) == "null" {
v.value = nil
return nil
}
if err := json.Unmarshal(data, &v.value); err != nil {
return err
}
return nil
}
// MarshalText implements the encoding.TextMarshaler interface
func (v Variant) MarshalText() ([]byte, error) {
if v.Nil() {
return []byte(""), nil
}
switch vv := v.value.(type) {
case string:
return []byte(vv), nil
case []byte:
return vv, nil
case json.RawMessage:
return vv, nil
}
return json.Marshal(v.value)
}
// UnmarshalText implements the encoding.TextUnmarshaler interface
func (v *Variant) UnmarshalText(text []byte) error {
if len(text) == 0 {
v.value = nil
return nil
}
v.value = string(text)
return nil
}