core

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2019 License: MIT Imports: 11 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoColumn = Error("sqlgen: no column to update")
	ErrNoRows   = sql.ErrNoRows
)

Errors

Functions

func Now

func Now(t, now time.Time, update bool) time.Time

Now ...

func NowP

func NowP(t *time.Time, now time.Time, update bool) time.Time

NowP ...

func Ternary

func Ternary(cond bool, exp1, exp2 interface{}) interface{}

Ternary ...

func WriteCols

func WriteCols(w SQLWriter, prefix string, cols string)

Types

type Array

type Array struct {
	V interface{}
	Opts
}

Array ...

func ArrayScanner

func ArrayScanner(v interface{}) Array

func (Array) Scan

func (a Array) Scan(src interface{}) error

Scan implements the Scanner interface.

func (Array) Value

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

Value implements the driver Valuer interface.

type Bool

type Bool bool

Bool handles null as false

func (*Bool) Scan

func (b *Bool) Scan(src interface{}) error

Scan implements the Scanner interface.

func (Bool) Value

func (b Bool) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type CommonQuery

type CommonQuery interface {
	Get(obj IGet, preds ...interface{}) (bool, error)
	Find(objs IFind, preds ...interface{}) error
	Insert(objs ...IInsert) (int64, error)
	Update(objs ...IUpdate) (int64, error)
	UpdateMap(m map[string]interface{}) (int64, error)
	Delete(obj ITableName) (int64, error)
	Count(obj ITableName, preds ...interface{}) (uint64, error)

	Table(name string) Query
	Prefix(sql string, args ...interface{}) Query
	Select(cols ...string) Query
	From(table string) Query
	SQL(preds ...interface{}) Query
	Where(preds ...interface{}) Query
	OrderBy(orderBys ...string) Query
	GroupBy(groupBys ...string) Query
	Limit(limit uint64) Query
	Offset(offset uint64) Query
	Suffix(sql string, args ...interface{}) Query
	UpdateAll() Query
	In(column string, args ...interface{}) Query
	NotIn(column string, args ...interface{}) Query
	Exists(column string, exists bool) Query
	IsNull(column string, null bool) Query

	Preload(table string, preds ...interface{}) Query
	Apply(funcs ...func(CommonQuery)) Query
}

QueryInterface ...

type DBInterface

type DBInterface interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) Row
	QueryRowContext(ctx context.Context, query string, args ...interface{}) Row
}

DBInterface ...

type Error

type Error string

Error ...

func Errorf

func Errorf(format string, args ...interface{}) Error

Errorf ...

func (Error) Error

func (e Error) Error() string

type Float

type Float = Float64

Float is alias to Float64

type Float32

type Float32 float32

Float32 handles null as 0

func (*Float32) Scan

func (f *Float32) Scan(src interface{}) error

Scan implements the Scanner interface.

func (Float32) Value

func (f Float32) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Float64

type Float64 float64

Float64 handles null as 0

func (*Float64) Scan

func (f *Float64) Scan(src interface{}) error

Scan implements the Scanner interface.

func (Float64) Value

func (f Float64) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type IFind

type IFind interface {
	ITableName
	SQLSelect(SQLWriter) error
	SQLScan(Opts, *sql.Rows) error
}

IFind ...

type IGet

type IGet interface {
	ITableName
	SQLSelect(SQLWriter) error
	SQLScan(Opts, *sql.Row) error
}

IGet ...

type IInsert

type IInsert interface {
	ITableName
	SQLInsert(SQLWriter) error
}

IInsert ...

type IJoin

type IJoin interface {
	ITableName
	SQLJoin(SQLWriter, []JoinType) error
}

IJoin ...

type IPreload

type IPreload interface {
	SQLPreload(name string) *PreloadDesc
	SQLPopulate(items IFind) error
}

type IScan

type IScan interface {
	ITableName
	SQLScan(Opts, *sql.Rows) error
}

IScan ...

type IScanRow

type IScanRow interface {
	ITableName
	SQLScan(Opts, *sql.Row) error
}

IScanRow ...

type ISelect

type ISelect interface {
	ITableName
	SQLSelect(SQLWriter) error
}

ISelect ...

type ITableName

type ITableName interface {
	SQLTableName() string
}

ITableName ...

type IUpdate

type IUpdate interface {
	ITableName
	SQLUpdate(SQLWriter) error
	SQLUpdateAll(SQLWriter) error
}

IUpdate ...

type Int

type Int int

Int handles null as 0 and stores 0 as is.

func (*Int) Scan

func (i *Int) Scan(src interface{}) error

Scan implements the Scanner interface.

func (Int) Value

func (i Int) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Int16

type Int16 int16

Int16 ...

func (*Int16) Scan

func (i *Int16) Scan(src interface{}) error

Scan ...

func (Int16) Value

func (i Int16) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Int32

type Int32 int32

Int32 ...

func (*Int32) Scan

func (i *Int32) Scan(src interface{}) error

Scan ...

func (Int32) Value

func (i Int32) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Int64

type Int64 int64

Int64 handles null as 0 but stores 0 as null. It's because int64 is usually used for identifier.

func (*Int64) Scan

func (i *Int64) Scan(src interface{}) error

Scan implements the Scanner interface.

func (Int64) Value

func (i Int64) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Int8

type Int8 int8

Int8 ...

func (*Int8) Scan

func (i *Int8) Scan(src interface{}) error

Scan ...

func (Int8) Value

func (i Int8) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Interface

type Interface struct{ V interface{} }

func (Interface) Bool

func (i Interface) Bool() *bool

func (Interface) Int

func (i Interface) Int() *int

func (Interface) Int32

func (i Interface) Int32() *int32

func (Interface) Int64

func (i Interface) Int64() *int64

func (Interface) JSON

func (i Interface) JSON() json.RawMessage

func (Interface) Map

func (i Interface) Map() map[string]interface{}

func (Interface) String

func (i Interface) String() *string

func (Interface) Time

func (i Interface) Time() time.Time

func (Interface) Unmarshal

func (i Interface) Unmarshal(v interface{}) error

type InvalidArgumentError

type InvalidArgumentError string

InvalidArgumentError ...

func (InvalidArgumentError) Error

func (e InvalidArgumentError) Error() string

type JSON

type JSON struct {
	V interface{}
}

JSON ...

func (JSON) Scan

func (v JSON) Scan(src interface{}) error

Scan implements the Scanner interface.

func (JSON) Value

func (v JSON) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type JoinType

type JoinType string

JoinType ...

type Map

type Map struct {
	Table string
	M     map[string]interface{}
}

Map ...

func (Map) SQLTableName

func (m Map) SQLTableName() string

SQLTableName ...

func (Map) SQLUpdate

func (m Map) SQLUpdate(w SQLWriter) error

SQLUpdate ...

func (Map) SQLUpdateAll

func (m Map) SQLUpdateAll(w SQLWriter) error

SQLUpdateAll ...

type Opts

type Opts struct {
	UseArrayInsteadOfJSON bool
}

func (Opts) Array

func (opts Opts) Array(v interface{}) Array

func (Opts) JSON

func (opts Opts) JSON(v interface{}) JSON

type PreloadDesc

type PreloadDesc struct {
	Fkey  string
	IDs   interface{}
	Items IFind
}

type Query

type Query interface {
	CommonQuery

	Build(preds ...interface{}) (string, []interface{}, error)
	BuildGet(obj IGet, preds ...interface{}) (string, []interface{}, error)
	BuildFind(objs IFind, preds ...interface{}) (string, []interface{}, error)
	BuildInsert(obj IInsert) (string, []interface{}, error)
	BuildUpdate(obj IUpdate) (string, []interface{}, error)
	BuildDelete(obj ITableName) (string, []interface{}, error)
	BuildCount(obj ITableName, preds ...interface{}) (string, []interface{}, error)
	Clone() Query
	Exec() (sql.Result, error)
	Query() (*sql.Rows, error)
	QueryRow() (Row, error)
	Scan(dest ...interface{}) error
	WithContext(context.Context) Query
}

Query ...

type Row

type Row struct {
	Row *sql.Row
	Log func(err error) error
}

func (Row) Scan

func (r Row) Scan(dest ...interface{}) error

type SQLWriter

type SQLWriter interface {
	Len() int
	Opts() Opts
	TrimLast(n int)
	WriteArg(arg interface{})
	WriteArgs(args []interface{})
	WriteByte(b byte)
	WriteMarker()
	WriteMarkers(n int)
	WriteName(name string)
	WritePrefixedName(schema string, name string)
	WriteQuery(b []byte)
	WriteQueryName(name string)
	WriteQueryString(s string)
	WriteQueryStringWithPrefix(prefix string, s string)
	WriteRaw(b []byte)
	WriteRawString(s string)
	WriteScanArg(arg interface{})
	WriteScanArgs(args []interface{})
}

type String

type String string

String handles null as empty string

func (*String) Scan

func (s *String) Scan(src interface{}) error

Scan implements the Scanner interface.

func (String) String

func (s String) String() string

func (String) Value

func (s String) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Time

type Time time.Time

Time ...

func (*Time) Scan

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

Scan implements the Scanner interface.

func (Time) Value

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

Value implements the driver Valuer interface.

type Uint

type Uint uint

Uint handles null as 0 and stores 0 as is.

func (*Uint) Scan

func (i *Uint) Scan(src interface{}) error

Scan implements the Scanner interface.

func (Uint) Value

func (i Uint) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Uint16

type Uint16 uint16

Uint16 ...

func (*Uint16) Scan

func (i *Uint16) Scan(src interface{}) error

Scan ...

func (Uint16) Value

func (i Uint16) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Uint32

type Uint32 uint32

Uint32 ...

func (*Uint32) Scan

func (i *Uint32) Scan(src interface{}) error

Scan ...

func (Uint32) Value

func (i Uint32) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Uint64

type Uint64 uint64

Uint64 handles null as 0 but stores 0 as null. It's because uint64 is usually used for identifier.

func (*Uint64) Scan

func (i *Uint64) Scan(src interface{}) error

Scan implements the Scanner interface.

func (Uint64) Value

func (i Uint64) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Uint8

type Uint8 uint8

Uint8 ...

func (*Uint8) Scan

func (i *Uint8) Scan(src interface{}) error

Scan ...

func (Uint8) Value

func (i Uint8) Value() (driver.Value, error)

Value implements the driver Valuer interface.

Jump to

Keyboard shortcuts

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