v2

package
v0.0.0-...-9146478 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidTransaction = errors.New("invalid transaction, it is already committed or roll backed")

ErrInvalidTransaction means the transaction is alread committed or roll backed

Functions

This section is empty.

Types

type Column

type Column interface {
	WhereColumn
	OrderColumn
	SetColumn
}

Column is an interface for shortcut of WhereColumn, OrderColumn, SetColumn

func Col

func Col(col string) Column

Col returns a Column interface

type Interface

type Interface interface {
	// DB returns the raw *gorm.DB.
	DB() *gorm.DB
	// Q returns the CRUD APIs without a transaction.
	Q() *TX
	// Begin returns the CRUD APIs with a transaction.
	Begin() *TX
}

Interface .

type Option

type Option func(db *gorm.DB) *gorm.DB

Option is the function processes *gorm.DB

func OrderBy

func OrderBy(col string, order Order) Option

OrderBy returns an Option for selecting order by some column

func Paging

func Paging(size, no int) Option

Paging returns an Option for selecting by paging

func Where

func Where(format string, args ...interface{}) Option

Where is the option for conditions

func Wheres

func Wheres(m interface{}) Option

Wheres is the option for conditions. the m can be a map or a struct.

type Order

type Order string

Order .

var (
	// DESC means select by DESC
	DESC Order = "DESC"
	// ASC means select by ASC
	ASC Order = "ASC"
)

type OrderColumn

type OrderColumn interface {
	DESC() Option
	ASC() Option
}

OrderColumn contains order by options

type SetColumn

type SetColumn interface {
	Set(value interface{}) Option
}

SetColumn is used in update statements

type TX

type TX struct {
	Error error
	// contains filtered or unexported fields
}

TX contains the CRUS APIs

func NewTx

func NewTx(db *gorm.DB) *TX

NewTx returns a *TX

func (*TX) Commit

func (tx *TX) Commit() error

Commit commits the transaction.

func (*TX) CommitOrRollback

func (tx *TX) CommitOrRollback()

CommitOrRollback commits the transaction if db.Error is nil, or rollbacks if the db.Error is not nil.

func (*TX) Create

func (tx *TX) Create(i interface{}) error

Create inserts a row

func (*TX) CreateInBatches

func (tx *TX) CreateInBatches(i interface{}, size int) error

CreateInBatches inserts multi rows

func (*TX) DB

func (tx *TX) DB() *gorm.DB

DB returns the raw *gorm.DB

func (*TX) Delete

func (tx *TX) Delete(i interface{}, options ...Option) (int64, error)

Delete deletes rows with conditions

func (*TX) Get

func (tx *TX) Get(i interface{}, options ...Option) (bool, error)

Get gets the first record.

func (*TX) List

func (tx *TX) List(i interface{}, options ...Option) (int64, error)

List lists records.

func (*TX) Rollback

func (tx *TX) Rollback() error

Rollback rollbacks the transaction.

func (*TX) SetColumns

func (tx *TX) SetColumns(i interface{}, options ...Option) error

SetColumns is used to set columns. At least one SetColumn Option in the options.

func (*TX) Updates

func (tx *TX) Updates(i, v interface{}, options ...Option) error

Updates updates the model i with the given value. v can be a map or a model struct. options is conditions.

type WhereColumn

type WhereColumn interface {
	Is(value interface{}) Option
	In(values []interface{}) Option
	InMap(values map[interface{}]struct{}) Option
	Like(value interface{}) Option
	GreaterThan(value interface{}) Option
	EqGreaterThan(value interface{}) Option
	LessThan(value interface{}) Option
	EqLessThan(value interface{}) Option
}

WhereColumn contains options for conditions

type WhereValue

type WhereValue interface {
	In(cols ...string) Option
}

WhereValue contains the option presents where the value in

func Value

func Value(value interface{}) WhereValue

Value .

Directories

Path Synopsis
plugins

Jump to

Keyboard shortcuts

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