sqltypes

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2019 License: MIT Imports: 6 Imported by: 0

README

sqltypes GoDoc

Package sqltypes extends database/sql.Null types, and types that implement sql.Scanner and driver.Value.

Documentation

Overview

Package sqltypes extends database/sql.Null* types, and types that implement sql.Scanner and driver.Value.

// NullJSON example
type Point struct {
	X, Y int
}

// insert
_, err := db.Exec(`insert into doc(point) values ($1)`, NullJSON{&Point{1, 2}})

// select
var dest Point
err := db.QueryRow(`select point from doc limit 1`).Scan(&NullJSON{&dest})
fmt.Printf("%+v", dest) // {X:1 Y:2}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NullJSON

type NullJSON struct {
	Interface interface{}
}

NullJSON represents a JSON serializable interface that may be null.

func (*NullJSON) Scan

func (a *NullJSON) Scan(value interface{}) error

Scan implements the sql.Scanner interface. It casts value to a byte slice and unmarshals the slice using a.Interface. Errors are returned when the byte case or unmarshal fail.

func (NullJSON) Value

func (a NullJSON) Value() (driver.Value, error)

Value implements the drive.Valuer interface. It will marshal a.Interface to JSON and return the serialized value as a string.

type PgDateRange

type PgDateRange struct {
	Start, End time.Time
}

PgDateRange defines a PostgreSQL daterange type.

func (*PgDateRange) Scan

func (a *PgDateRange) Scan(value interface{}) error

Scan reads a value as a PostgreSQL daterange and populates a PgDateRange.

func (PgDateRange) Value

func (a PgDateRange) Value() (driver.Value, error)

Value returns a driver.Value formated as a PostgreSQL daterange.

Jump to

Keyboard shortcuts

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