db

package
v0.0.0-...-a114734 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2017 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrDup contains the errcode of a unique constraint violation
	ErrDup = "23505"
)
View Source
const ISO8601 = "2006-01-02T15:04:05-0700"

ISO8601 is a time.Time layout for the ISO8601 format

Variables

This section is empty.

Functions

func Get

func Get(dest interface{}, query string, args ...interface{}) error

Get is the same as sqlx.Get() but do not returns an error on empty results

func IsDup

func IsDup(err error) bool

IsDup check if an SQL error has been triggered by a duplicated data

func IsNotFound

func IsNotFound(err error) bool

IsNotFound checks if an error is triggered by an empty result

func NamedSelect

func NamedSelect(dest interface{}, query string, args interface{}) error

NamedSelect is the same as sqlx.Select() but with named params

func Setup

func Setup(uri string) error

Setup setup the database connection and init the Writer

Types

type Queryable

type Queryable interface {
	sqlx.Execer
	sqlx.Queryer
	sqlx.Preparer
	BindNamed(query string, arg interface{}) (string, []interface{}, error)
	DriverName() string
	Get(dest interface{}, query string, args ...interface{}) error
	MustExec(query string, args ...interface{}) sql.Result
	NamedExec(query string, arg interface{}) (sql.Result, error)
	NamedQuery(query string, arg interface{}) (*sqlx.Rows, error)
	PrepareNamed(query string) (*sqlx.NamedStmt, error)
	Preparex(query string) (*sqlx.Stmt, error)
	Rebind(query string) string
	Select(dest interface{}, query string, args ...interface{}) error
}

Queryable represent a global interface for transactions, prepared statement, etc.

var Writer Queryable

Writer represents an open connection to the database

type Time

type Time struct {
	time.Time
}

Time represents a time.Time that uses ISO8601 for json input/output instead of RFC3339

func Now

func Now() *Time

Now returns the current local time.

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface

func (*Time) Scan

func (t *Time) Scan(value interface{}) error

Scan - Implement the database/sql scanner interface

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements the json.Unmarshaler interface

func (*Time) Value

func (t *Time) Value() (driver.Value, error)

Value - Implementation of valuer for database/sql

Jump to

Keyboard shortcuts

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