v0.7.0

utils Package

Last updated


This page lists the exported helpers of core/utils, which convert between command text and decoded JSON values and walk nested paths.

Functions


  1. import "github.com/pardnchiu/toriidb/core/utils"
  2. func WalkKeys(obj any, subKeys []string) (any, bool)
  3. func Atov(text string) any
  4. func Vtoa(value any) string
  5. func Vtof(value any) (float64, bool)

FunctionBehaviorUsed by
utils.WalkKeysFollows subKeys through decoded JSON: a map[string]any by field name, a []any by decimal index. Returns false for a missing field, a non-numeric, negative, or out-of-range index, or a scalar in the middle of the path. An empty subKeys returns obj itselfGetField, IncrField, filter.Cond
utils.AtovConverts command text to a JSON value: null → nil, true/false → bool, integer → int64, other number → float64, trimmed {...}/[...] that parses → object or array, anything else → stringSetField
utils.VtoaRenders a decoded value as text: nil → (nil), whole float64 without a decimal point, other float64 in shortest form, bool as true/false, objects and arrays as compact JSON, other types with %vGetField, Incr, Exec, filter.Cond
utils.VtofReturns a number as float64 for float64 and int64 inputs; any other type, including numeric strings, returns falseIncrField

Round-Trip Rules


  • Vtoa is what makes 1.0 compare equal to 1 in QUERY, because both render as 1.
  • Atov keeps integers as int64, but values decoded from stored JSON are float64; Vtof accepts both, so INCR on a JSON field works either way.
  • A value that looks like JSON but fails to parse stays a string.


中文