orm

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TagKey          = "bear"
	TagChildKeyName = "name"
	TagItemSep      = ","
	TagKVSep        = "="
)

Variables

View Source
var (
	ErrNotFoundDialect = errorf("not found dialect")
	ErrInvalidDialect  = errorf("invalid dialect")
)

Functions

func EnableDebug

func EnableDebug(b bool)

func GetStructFieldNames

func GetStructFieldNames(i interface{}) []string

func RegisterDefaultDialect

func RegisterDefaultDialect(name string, dialect Dialect)

func RegisterDialect

func RegisterDialect(name string, dialect Dialect)

func SetDefaultDialect

func SetDefaultDialect(name string) bool

func SetLogger

func SetLogger(l Logger)

Types

type Action

type Action string

type Builder

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

func NewBuilder

func NewBuilder(options ...BuilderOptionFunc) *Builder

func (*Builder) Apply

func (b *Builder) Apply(options ...BuilderOptionFunc) *Builder

func (*Builder) Build

func (b *Builder) Build() Template

func (*Builder) Delete

func (b *Builder) Delete(table string) *Builder

func (*Builder) Dialect

func (b *Builder) Dialect(d string) *Builder

func (*Builder) Exec

func (b *Builder) Exec(ctx context.Context, db DB) (sql.Result, error)

func (*Builder) GroupBy

func (b *Builder) GroupBy(fields ...string) *Builder

func (*Builder) Having

func (b *Builder) Having(format string, values ...interface{}) *Builder

func (*Builder) Insert

func (b *Builder) Insert(table string, columns map[string]interface{}) *Builder

func (*Builder) InsertStruct

func (b *Builder) InsertStruct(table string, i interface{}, ignoreZeroValue bool, ignoreFields ...string) *Builder

func (*Builder) OrderBy

func (b *Builder) OrderBy(fields ...string) *Builder

func (*Builder) Paging

func (b *Builder) Paging(page, size int) *Builder

func (*Builder) Query

func (b *Builder) Query(ctx context.Context, db DB, i interface{}) error

func (*Builder) Select

func (b *Builder) Select(table string, columns ...string) *Builder

func (*Builder) SelectStruct

func (b *Builder) SelectStruct(table string, i interface{}, ignoreFields ...string) *Builder

func (*Builder) Update

func (b *Builder) Update(table string, columns map[string]interface{}) *Builder

func (*Builder) UpdateStruct

func (b *Builder) UpdateStruct(table string, i interface{}, ignoreZeroValue bool, ignoreFields ...string) *Builder

func (*Builder) Where

func (b *Builder) Where(format string, values ...interface{}) *Builder

func (*Builder) WhereIn

func (b *Builder) WhereIn(column string, values ...interface{}) *Builder

type BuilderOptionFunc

type BuilderOptionFunc func(b *Builder)

func Delete

func Delete(table string) BuilderOptionFunc

func GroupBy

func GroupBy(fields ...string) BuilderOptionFunc

func Having

func Having(format string, values ...interface{}) BuilderOptionFunc

func Insert

func Insert(table string, columns map[string]interface{}) BuilderOptionFunc

func OrderBy

func OrderBy(fields ...string) BuilderOptionFunc

func Paging

func Paging(page, size int) BuilderOptionFunc

func Select

func Select(table string, columns ...string) BuilderOptionFunc

func SelectStruct

func SelectStruct(table string, i interface{}, ignoreColumns ...string) BuilderOptionFunc

func Update

func Update(table string, columns map[string]interface{}) BuilderOptionFunc

func Where

func Where(format string, values ...interface{}) BuilderOptionFunc

func WhereIn

func WhereIn(column string, values ...interface{}) BuilderOptionFunc

func WithDialect

func WithDialect(d string) BuilderOptionFunc

type BulkInsertBuilder

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

func NewBulkInsertBuilder

func NewBulkInsertBuilder() *BulkInsertBuilder

func (*BulkInsertBuilder) Append

func (b *BulkInsertBuilder) Append(values ...[]interface{}) *BulkInsertBuilder

func (*BulkInsertBuilder) AppendMap

func (b *BulkInsertBuilder) AppendMap(mm ...map[string]interface{}) *BulkInsertBuilder

func (*BulkInsertBuilder) AppendStruct

func (b *BulkInsertBuilder) AppendStruct(ii ...interface{}) *BulkInsertBuilder

func (*BulkInsertBuilder) Build

func (b *BulkInsertBuilder) Build() (Template, error)

func (*BulkInsertBuilder) Columns

func (b *BulkInsertBuilder) Columns(cc ...string) *BulkInsertBuilder

func (*BulkInsertBuilder) Dialect

func (b *BulkInsertBuilder) Dialect(name string) *BulkInsertBuilder

func (*BulkInsertBuilder) Table

func (b *BulkInsertBuilder) Table(name string) *BulkInsertBuilder

type Column

type Column struct {
	Name   string
	Type   string
	Suffix string
}

type Condition

type Condition []Template

func NewCondition

func NewCondition(tt ...Template) Condition

func (Condition) Append

func (c Condition) Append(others ...Template) Condition

func (Condition) AppendIn

func (c Condition) AppendIn(column string, values ...interface{}) Condition

func (Condition) AppendMap

func (c Condition) AppendMap(m map[string]interface{}) Condition

func (Condition) AppendStruct

func (c Condition) AppendStruct(i interface{}, ignoreZeroValue bool) Condition

func (Condition) Appendf

func (c Condition) Appendf(format string, values ...interface{}) Condition

func (Condition) Join

func (c Condition) Join(sep string, right, left string) Template

func (Condition) JoinAnd

func (c Condition) JoinAnd() Template

func (Condition) JoinOr

func (c Condition) JoinOr() Template

type DB

type DB interface {
	Query(ctx context.Context, t Template, i interface{}) error
	Exec(ctx context.Context, t Template) (sql.Result, error)
	Tx(ctx context.Context, fn func(ctx context.Context, tx DB) error) (err error)
	BeginTx(ctx context.Context) (DB, error)
	Rollback() error
	Commit() error
}

func NewDB

func NewDB(r Raw) DB

func OpenDB

func OpenDB(driverName string, dataSourceName string) (DB, error)

type DDLBuilder

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

func NewDDLBuilder

func NewDDLBuilder(dialect ...string) *DDLBuilder

func (*DDLBuilder) Build

func (b *DDLBuilder) Build() Template

func (*DDLBuilder) Compact

func (b *DDLBuilder) Compact() *DDLBuilder

func (*DDLBuilder) CreateTable

func (b *DDLBuilder) CreateTable(table Table, checkExists bool) *DDLBuilder

func (*DDLBuilder) Dialect

func (b *DDLBuilder) Dialect(name string) *DDLBuilder

func (*DDLBuilder) DropTable

func (b *DDLBuilder) DropTable(table string, checkExists bool) *DDLBuilder

func (*DDLBuilder) Pretty

func (b *DDLBuilder) Pretty(prefix string, indent string) *DDLBuilder

type Dialect

type Dialect interface {
	MappingType(rt reflect.Type) string
	Quote(s string) string
}

func GetDefaultDialect

func GetDefaultDialect() Dialect

func GetDialect

func GetDialect(name string) Dialect

func LookupDialect

func LookupDialect(name string) Dialect

type Logger

type Logger interface {
	Printf(format string, args ...interface{})
}

type Raw

type Raw interface {
	QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
}

type Rows

type Rows struct {
	Raw *sql.Rows
}

func WrapRows

func WrapRows(rows *sql.Rows) *Rows

func (*Rows) Bind

func (r *Rows) Bind(i interface{}) error

func (*Rows) Map

func (r *Rows) Map() (map[string]interface{}, error)

func (*Rows) MapSlice

func (r *Rows) MapSlice() ([]map[string]interface{}, error)

func (*Rows) Scalar

func (r *Rows) Scalar(value interface{}) error

func (*Rows) ScalarSlice

func (r *Rows) ScalarSlice(slice interface{}) error

func (*Rows) Scan

func (r *Rows) Scan(callback func(scan func(...interface{}) error, abort func()) error) error

func (*Rows) Struct

func (r *Rows) Struct(i interface{}) error

func (*Rows) StructSlice

func (r *Rows) StructSlice(i interface{}) error

type Table

type Table struct {
	Name    string
	Columns []Column
}

type Template

type Template struct {
	Format string
	Values []interface{}
}

func NewTemplate

func NewTemplate(format string, values ...interface{}) Template

func (Template) Append

func (t Template) Append(others ...Template) Template

func (Template) AppendValues

func (t Template) AppendValues(values ...interface{}) Template

func (Template) Appendf

func (t Template) Appendf(format string, values ...interface{}) Template

func (Template) Bracket

func (t Template) Bracket() Template

func (Template) Empty

func (t Template) Empty() bool

func (Template) FirstValue

func (t Template) FirstValue() interface{}

func (Template) String

func (t Template) String() string

func (Template) Wrap

func (t Template) Wrap(left string, right string) Template

type Templates

type Templates []Template

func NewPlainTemplates

func NewPlainTemplates(ss ...string) Templates

func NewTemplates

func NewTemplates(tt ...Template) Templates

func (Templates) Append

func (tt Templates) Append(others ...Template) Templates

func (Templates) Appendf

func (tt Templates) Appendf(format string, values ...interface{}) Templates

func (Templates) Formats

func (tt Templates) Formats() []string

func (Templates) Join

func (tt Templates) Join(sep string, right, left string) Template

func (Templates) Values

func (tt Templates) Values() []interface{}

Directories

Path Synopsis
dialect
examples
ddl
internal

Jump to

Keyboard shortcuts

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