sqlutil

package module
v0.0.0-...-5bd039e Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2017 License: MIT Imports: 7 Imported by: 0

README

sqlutil

sqlutil is a golang package that facilitate the usage of https://golang.org/pkg/database/sql/

License

MIT

Documentation

Overview

Package reflect implements run-time reflection, allowing a program to manipulate objects with arbitrary types. The typical use is to take a value with static type interface{} and extract its dynamic type information by calling TypeOf, which returns a Type.

A call to ValueOf returns a Value representing the run-time data. Zero takes a Type and returns a Value representing a zero value for that type.

See "The Laws of Reflection" for an introduction to reflection in Go: https://golang.org/doc/articles/laws_of_reflection.html

Index

Constants

View Source
const (
	FieldCreatedAt = "created_at"
	FieldUpdatedAt = "updated_at"
)
View Source
const (
	TagColumnName         = "sql"
	TagIndexName          = "sqlindex"
	TagForeignKeyName     = "sqlforeignkey"
	TagFieldNameIndex     = 0
	TagFieldDataTypeIndex = 1
)
View Source
const Separator = ",\n"

Variables

This section is empty.

Functions

func CreateTable

func CreateTable(db *sql.DB, model interface{}) error

func Delete

func Delete(db *sql.DB, model interface{}) (int64, error)

func Insert

func Insert(db *sql.DB, model interface{}) (int64, error)

func QueryRow

func QueryRow(db *sql.DB, model interface{}) error

func Scan

func Scan(scanner Scanner, model interface{}) error

func Update

func Update(db *sql.DB, model interface{}, fields ...Fields) (int64, error)

Types

type Column

type Column struct {
	Name       string
	Index      int
	DataType   string
	PrimaryKey bool
	Constraint ColumnConstraint
}

type ColumnConstraint

type ColumnConstraint byte
const (
	ColumnConstraintUnique ColumnConstraint = 1 << iota
	ColumnConstraintNull
	ColumnConstraintNotNull
)

func (ColumnConstraint) String

func (c ColumnConstraint) String() string

type EntityContext

type EntityContext struct {
	// contains filtered or unexported fields
}

func NewEntityContext

func NewEntityContext(model interface{}) *EntityContext

func (*EntityContext) Delete

func (t *EntityContext) Delete(db *sql.DB) (int64, error)

func (*EntityContext) Insert

func (t *EntityContext) Insert(db *sql.DB) (int64, error)

func (*EntityContext) QueryRow

func (t *EntityContext) QueryRow(db *sql.DB) error

func (*EntityContext) Scan

func (t *EntityContext) Scan(scanner Scanner) error

func (*EntityContext) Update

func (t *EntityContext) Update(db *sql.DB, fields ...Fields) (int64, error)

type Fields

type Fields map[string]interface{}

type ForeignKey

type ForeignKey struct {
	Columns               []string
	ReferenceTable        string
	ReferenceTableColumns []string
}

type Index

type Index struct {
	Name    string
	Columns []string
}

type Metadata

type Metadata struct {
	// contains filtered or unexported fields
}

func (*Metadata) Schema

func (m *Metadata) Schema(t reflect.Type) (*Schema, error)

type RowScanner

type RowScanner struct {
	Row *sql.Row
}

func (*RowScanner) Columns

func (s *RowScanner) Columns() ([]string, error)

func (*RowScanner) Scan

func (s *RowScanner) Scan(dest ...interface{}) error

type Scanner

type Scanner interface {
	Scan(dest ...interface{}) error
	Columns() ([]string, error)
}

type Schema

type Schema struct {
	Table       string
	ForeignKeys []*ForeignKey
	Columns     []*Column
	Indexes     []*Index
}

type Tag

type Tag reflect.StructTag

A StructTag is the tag string in a struct field.

By convention, tag strings are a concatenation of optionally space-separated key:"value" pairs. Each key is a non-empty string consisting of non-control characters other than space (U+0020 ' '), quote (U+0022 '"'), and colon (U+003A ':'). Each value is quoted using U+0022 '"' characters and Go string literal syntax.

func (Tag) Get

func (tag Tag) Get(key string) []string

Get returns the value associated with key in the tag string. If there is no such key in the tag, Get returns the empty string. If the tag does not have the conventional format, the value returned by Get is unspecified. To determine whether a tag is explicitly set to the empty string, use Lookup.

func (Tag) Lookup

func (tag Tag) Lookup(key string) ([]string, bool)

Lookup returns the value associated with key in the tag string. If the key is present in the tag the value (which may be empty) is returned. Otherwise the returned value will be the empty string. The ok return value reports whether the value was explicitly set in the tag string. If the tag does not have the conventional format, the value returned by Lookup is unspecified.

Jump to

Keyboard shortcuts

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