pgparser

package module
v0.0.0-...-40d5ce5 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2015 License: BSD-3-Clause Imports: 5 Imported by: 0

README

pgparser

GoDoc

Overview

This package can unpack complex types from Postgres into structs, slices, and primitive values.

Example

Also see example_test.go in this directory.

import (
  "fmt"

  "fknsrs.biz/p/pgparser"
)

func ExampleParse() {
  var s = `(a,{x,y,z},5)`

  var v struct{
    A string
    B []string
    C int
  }

  if err := pgparser.Unmarshal(s, &v); err != nil {
    panic(err)
  }

  fmt.Printf("%#v\n", v)

  // Output:
  // struct { A string; B []string; C int }{A:"a", B:[]string{"x", "y", "z"}, C:5}
}

License

3-clause BSD. A copy is included with the source.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Unmarshal

func Unmarshal(s string, v interface{}) error

Unmarshal takes a string representation of a complex type from Postgres and unpacks it into value v. Since the serialised data doesn't include field names or even types, values must match perfectly to be decoded. This means that structs must have their fields in the same order as they are in the database, and those fields must be the same types.

Types

This section is empty.

Jump to

Keyboard shortcuts

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