v2

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2024 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 added in v1.0.8

type Column interface {
	WhereColumn
	OrderColumn
	SetColumn
}

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

func Col added in v1.0.8

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 added in v1.0.8

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

Option is the function processes *gorm.DB

func OrderBy added in v1.0.8

func OrderBy(col string, order Order) Option

OrderBy returns an Option for selecting order by some column

func Paging added in v1.0.8

func Paging(size, no int) Option

Paging returns an Option for selecting by paging

func Where added in v1.0.8

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

Where is the option for conditions

func Wheres added in v1.0.8

func Wheres(m interface{}) Option

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

type Order added in v1.0.8

type Order string

Order .

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

type OrderColumn added in v1.0.8

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

OrderColumn contains order by options

type SetColumn added in v1.0.8

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

SetColumn is used in update statements

type TX added in v1.0.8

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

TX contains the CRUS APIs

func NewTx added in v1.0.8

func NewTx(db *gorm.DB) *TX

NewTx returns a *TX

func (*TX) Commit added in v1.0.8

func (tx *TX) Commit() error

Commit commits the transaction.

func (*TX) CommitOrRollback added in v1.0.8

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 added in v1.0.8

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

Create inserts a row

func (*TX) CreateInBatches added in v1.0.8

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

CreateInBatches inserts multi rows

func (*TX) DB added in v1.0.8

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

DB returns the raw *gorm.DB

func (*TX) Delete added in v1.0.8

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

Delete deletes rows with conditions

func (*TX) Get added in v1.0.8

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

Get gets the first record.

func (*TX) List added in v1.0.8

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

List lists records.

func (*TX) Rollback added in v1.0.8

func (tx *TX) Rollback() error

Rollback rollbacks the transaction.

func (*TX) SetColumns added in v1.0.8

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 added in v1.0.8

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 added in v1.0.8

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 added in v1.0.8

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

WhereValue contains the option presents where the value in

func Value added in v1.0.8

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