Documentation
¶
Overview ¶
Package jsondb implements some structures useful for marshaling data structures into and out of a database.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetJsonKeyMap ¶
GetJsonKeyMap will attempt to get the value of the key from the keymap in the form of the given type. Will fail if the given key is not registered, or if the key is registered to a different type.
func SetJsonKeyMap ¶
func SetJsonKeyMap[T any](km *KeyMap, reg *SchemaRegistry, key string, value T) error
SetJsonKeyMap will attempt to set the value of the key in the key map to the given value. Will fail if the given key is not registered in the schema registry, or if the key is registered to a different type.
Types ¶
type Json ¶
type Json []byte
Json holds a byte slice that contains already-Marshalled JSON. It implements json.Marshaler and json.Unmarhaler, so that it can be included in larger structures which will be marshalled to JSON.
func (Json) MarshalJSON ¶
func (*Json) UnmarshalJSON ¶
type KeyMap ¶
KeyMap is a structure designed to allow key-value pairs to be stored in a JSON field in a database; and speficially, to allow flexible recursive JSON structures if desired.
func (KeyMap) Get ¶
Get unmarshals the Json contained in km[key] into val. If km is nil, or the key does not exist, val is left empty and the bool is set to 'false'. Otherwise, the bool returns 'true', and error is the error value from marshalling.
type SchemaRegistry ¶
type SchemaRegistry struct {
// contains filtered or unexported fields
}
SchemaRegistry is used to enforce a schema on the content of JSON keys.
func NewSchemaRegistry ¶
func NewSchemaRegistry() *SchemaRegistry