pqjson

package module
v0.0.0-...-ee2fc3a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2019 License: MIT Imports: 3 Imported by: 1

README

pqjson

A couple handy Go types for working with JSON data and Postgres.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RawMessage

type RawMessage json.RawMessage

RawMessage wraps json.RawMessage as a type to use for fragments of JSON metadata. Use this type if you need to represent all possible JSON values (including arrays, int literals, etc.). It's fine for passing data through from an API to Postgres without needing to touch it in Go, but not great if you need to access the data inside Go code. If you need to access the data in Go, and you're OK with being restricted to a map[string]interface{}, consider using pqjson.StringMap instead.

func (RawMessage) Empty

func (rm RawMessage) Empty() bool

Empty returns true if the RawMessage's underlying byte slice is empty, false otherwise.

func (*RawMessage) Scan

func (rm *RawMessage) Scan(src interface{}) error

Scan converts raw db bytes into a RawMessage.

func (RawMessage) Value

func (rm RawMessage) Value() (driver.Value, error)

Value returns the raw byte array for JSON fragment or nil if the JSON raw message is empty.

type StringMap

type StringMap map[string]interface{}

A StringMap is the Go representation of a JSON object, as stored in a Postgres JSONB field.

func (StringMap) Empty

func (sm StringMap) Empty() bool

Empty returns true if the StringMap's underlying map is empty, false otherwise.

func (*StringMap) Scan

func (sm *StringMap) Scan(src interface{}) error

Scan converts raw db bytes into a StringMap.

func (StringMap) Value

func (sm StringMap) Value() (driver.Value, error)

Value marshals the map to JSON. If the map is empty, it is marshaled as "{}".

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL