v0.1.14 Latest Latest

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

Go to latest
Published: May 26, 2021 License: BSD-2-Clause Imports: 21 Imported by: 28




View Source
const (
	InvalidRelation = iota


This section is empty.


func Append

func Append(fmter Formatter, b []byte, v interface{}) []byte

func AppendBoolValue added in v0.1.6

func AppendBoolValue(fmter Formatter, b []byte, v reflect.Value) []byte

func AppendFloat32Value added in v0.1.6

func AppendFloat32Value(fmter Formatter, b []byte, v reflect.Value) []byte

func AppendFloat64Value added in v0.1.6

func AppendFloat64Value(fmter Formatter, b []byte, v reflect.Value) []byte

func AppendIntValue

func AppendIntValue(fmter Formatter, b []byte, v reflect.Value) []byte

func AppendQueryAppender

func AppendQueryAppender(fmter Formatter, b []byte, app QueryAppender) []byte

func AppendUintValue

func AppendUintValue(fmter Formatter, b []byte, v reflect.Value) []byte

func SetTableNameInflector

func SetTableNameInflector(fn func(string) string)

SetTableNameInflector overrides the default func that pluralizes model name to get table name, e.g. my_article becomes my_articles.


type AfterDeleteHook

type AfterDeleteHook interface {
	AfterDelete(context.Context) error

type AfterInsertHook

type AfterInsertHook interface {
	AfterInsert(context.Context) error

type AfterScanHook

type AfterScanHook interface {
	AfterScan(context.Context) error

type AfterSelectHook

type AfterSelectHook interface {
	AfterSelect(context.Context) error

type AfterUpdateHook

type AfterUpdateHook interface {
	AfterUpdate(context.Context) error

type AppenderFunc

type AppenderFunc func(fmter Formatter, b []byte, v reflect.Value) []byte

func Appender

func Appender(typ reflect.Type) AppenderFunc

func FieldAppender

func FieldAppender(dialect Dialect, field *Field) AppenderFunc

type ArgAppender

type ArgAppender interface {
	AppendArg(fmter Formatter, b []byte, name string) ([]byte, bool)

type BeforeDeleteHook

type BeforeDeleteHook interface {
	BeforeDelete(context.Context) error

type BeforeInsertHook

type BeforeInsertHook interface {
	BeforeInsert(context.Context) error

type BeforeScanHook

type BeforeScanHook interface {
	BeforeScan(context.Context) error

type BeforeUpdateHook

type BeforeUpdateHook interface {
	BeforeUpdate(context.Context) error

type ColumnsAppender

type ColumnsAppender interface {
	AppendColumns(fmter Formatter, b []byte) ([]byte, error)

type Dialect

type Dialect interface {
	Name() string
	Features() feature.Feature

	Tables() *Tables
	OnTable(table *Table)

	IdentQuote() byte
	Append(fmter Formatter, b []byte, v interface{}) []byte
	Appender(typ reflect.Type) AppenderFunc
	Scanner(typ reflect.Type) ScannerFunc

type Field

type Field struct {
	StructField reflect.StructField

	Tag   tagparser.Tag
	Type  reflect.Type
	Index []int

	Name    string // SQL name, .e.g. id
	SQLName Safe   // escaped SQL name, e.g. "id"
	GoName  string // struct field name, e.g. Id

	DiscoveredSQLType  string
	UserSQLType        string
	CreateTableSQLType string
	SQLDefault         string

	OnDelete string
	OnUpdate string

	IsPK          bool
	NotNull       bool
	NullZero      bool
	AutoIncrement bool

	Append AppenderFunc
	Scan   ScannerFunc
	IsZero IsZeroerFunc

func (*Field) AppendValue

func (f *Field) AppendValue(fmter Formatter, b []byte, strct reflect.Value) []byte

func (*Field) Clone

func (f *Field) Clone() *Field

func (*Field) HasZeroValue

func (f *Field) HasZeroValue(v reflect.Value) bool

func (*Field) ScanValue

func (f *Field) ScanValue(strct reflect.Value, src interface{}) error

func (*Field) ScanWithCheck

func (f *Field) ScanWithCheck(fv reflect.Value, src interface{}) error

func (*Field) String

func (f *Field) String() string

func (*Field) Value

func (f *Field) Value(strct reflect.Value) reflect.Value

type Formatter

type Formatter struct {
	// contains filtered or unexported fields

func NewFormatter

func NewFormatter(dialect Dialect) Formatter

func NewNopFormatter

func NewNopFormatter() Formatter

func (Formatter) AppendIdent

func (f Formatter) AppendIdent(b []byte, ident string) []byte

func (Formatter) AppendQuery

func (f Formatter) AppendQuery(dst []byte, query string, args ...interface{}) []byte

func (Formatter) AppendValue

func (f Formatter) AppendValue(b []byte, v reflect.Value) []byte

func (Formatter) Arg

func (f Formatter) Arg(name string) interface{}

func (Formatter) Dialect

func (f Formatter) Dialect() Dialect

func (Formatter) FormatQuery

func (f Formatter) FormatQuery(query string, args ...interface{}) string

func (Formatter) HasFeature

func (f Formatter) HasFeature(feature feature.Feature) bool

func (Formatter) IdentQuote

func (f Formatter) IdentQuote() byte

func (Formatter) IsNop

func (f Formatter) IsNop() bool

func (Formatter) String

func (f Formatter) String() string

func (Formatter) WithArg

func (f Formatter) WithArg(name string, value interface{}) Formatter

func (Formatter) WithModel

func (f Formatter) WithModel(model ArgAppender) Formatter

type Ident

type Ident string

Ident represents a SQL identifier, for example, table or column name.

func (Ident) AppendQuery

func (s Ident) AppendQuery(fmter Formatter, b []byte) ([]byte, error)

type IsZeroerFunc

type IsZeroerFunc func(reflect.Value) bool

func FieldZeroChecker

func FieldZeroChecker(field *Field) IsZeroerFunc

type QueryAppender

type QueryAppender interface {
	AppendQuery(fmter Formatter, b []byte) ([]byte, error)

type QueryWithArgs

type QueryWithArgs struct {
	Query string
	Args  []interface{}

func SafeQuery

func SafeQuery(query string, args []interface{}) QueryWithArgs

func UnsafeIdent

func UnsafeIdent(ident string) QueryWithArgs

func (QueryWithArgs) AppendQuery

func (q QueryWithArgs) AppendQuery(fmter Formatter, b []byte) ([]byte, error)

func (QueryWithArgs) IsZero

func (q QueryWithArgs) IsZero() bool

type QueryWithSep

type QueryWithSep struct {
	Sep string

func SafeQueryWithSep

func SafeQueryWithSep(query string, args []interface{}, sep string) QueryWithSep

type Relation

type Relation struct {
	Type       int
	Field      *Field
	JoinTable  *Table
	BaseFields []*Field
	JoinFields []*Field

	PolymorphicField *Field
	PolymorphicValue string

	M2MTable      *Table
	M2MBaseFields []*Field
	M2MJoinFields []*Field

func (*Relation) String

func (r *Relation) String() string

type Safe

type Safe string

Safe represents a safe SQL query.

func (Safe) AppendQuery

func (s Safe) AppendQuery(fmter Formatter, b []byte) ([]byte, error)

type ScannerFunc

type ScannerFunc func(dest reflect.Value, src interface{}) error

func FieldScanner

func FieldScanner(dialect Dialect, field *Field) ScannerFunc

func Scanner

func Scanner(typ reflect.Type) ScannerFunc

type Table

type Table struct {
	Type      reflect.Type
	ZeroValue reflect.Value // reflect.Struct
	ZeroIface interface{}   // struct pointer

	TypeName  string
	ModelName string

	Name              string
	SQLName           Safe
	SQLNameForSelects Safe
	Alias             string
	SQLAlias          Safe

	Fields     []*Field // PKs + DataFields
	PKs        []*Field
	DataFields []*Field

	FieldMap map[string]*Field

	Relations map[string]*Relation
	Unique    map[string][]*Field

	SoftDeleteField       *Field
	UpdateSoftDeleteField func(fv reflect.Value) error
	// contains filtered or unexported fields

Table represents a SQL table created from Go struct.

func (*Table) CheckPKs

func (t *Table) CheckPKs() error

func (*Table) Dialect

func (t *Table) Dialect() Dialect

func (*Table) Field

func (t *Table) Field(name string) (*Field, error)

func (*Table) HasAfterDeleteHook

func (t *Table) HasAfterDeleteHook() bool

func (*Table) HasAfterInsertHook

func (t *Table) HasAfterInsertHook() bool

func (*Table) HasAfterScanHook

func (t *Table) HasAfterScanHook() bool

func (*Table) HasAfterSelectHook

func (t *Table) HasAfterSelectHook() bool

func (*Table) HasAfterUpdateHook

func (t *Table) HasAfterUpdateHook() bool

func (*Table) HasBeforeDeleteHook

func (t *Table) HasBeforeDeleteHook() bool

func (*Table) HasBeforeInsertHook

func (t *Table) HasBeforeInsertHook() bool

func (*Table) HasBeforeScanHook

func (t *Table) HasBeforeScanHook() bool

func (*Table) HasBeforeUpdateHook

func (t *Table) HasBeforeUpdateHook() bool

func (*Table) HasField

func (t *Table) HasField(name string) bool

func (*Table) String

func (t *Table) String() string

type Tables

type Tables struct {
	// contains filtered or unexported fields

func NewTables

func NewTables(dialect Dialect) *Tables

func (*Tables) ByModel

func (t *Tables) ByModel(name string) *Table

func (*Tables) ByName

func (t *Tables) ByName(name string) *Table

func (*Tables) Get

func (t *Tables) Get(typ reflect.Type) *Table

func (*Tables) Ref

func (t *Tables) Ref(typ reflect.Type) *Table

func (*Tables) Register

func (t *Tables) Register(models ...interface{})

Jump to

Keyboard shortcuts

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