goorm

package module
v0.0.0-...-fbd325f Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2020 License: MIT Imports: 11 Imported by: 0

README

goorm

一个简单的数据库crud操作库
upper 这数据访问框架的二次封装

用法

	d := &DNA{}
	RegisterModel(d)//注册表结构
	RegisterDataBase("default", "mysql", "host", "database", "user", "pwd")//注册数据库连接对象
	o = NewOrm()
  id, err := o.Insert(&DNA{
		UserID:      12,
		OriginDNAID: 2,
		StyleName:   "xxx",
		Name:        "x",
		Thumbnail:   "x",
		StyleID:     1,
		Introduce:   "xx",
		Price:       12,
		GMTCreate:   123,
	})
 

具体crud可看orm_test.go

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoMoreRows = errors.New(`orm: no more rows in this result set`)
)

Error messages.

Functions

func RegisterDataBase

func RegisterDataBase(aliasName, driverName, host, database, user, pwd string, params ...int) error

func RegisterModel

func RegisterModel(models ...interface{})

RegisterModel register models

func SetLogging

func SetLogging(islogging bool)

SetLogging enables or disables logging.

func SetMaxIdleConns

func SetMaxIdleConns(aliasName string, maxIdleConns int)

SetMaxIdleConns Change the max idle conns for *sql.DB, use specify database alias name

func SetMaxOpenConns

func SetMaxOpenConns(aliasName string, maxOpenConns int)

SetMaxOpenConns Change the max open conns for *sql.DB, use specify database alias name

Types

type Commiter

type Commiter interface {
	// Commit commits the current transaction.
	Commit() error
}

type Cond

type Cond map[interface{}]interface{}

Cond is a map that defines conditions for a query and satisfies the Constraints and Compound interfaces.

type IOperateSet

type IOperateSet interface {
	Insert(model interface{}) (int64, error)
	Update(model interface{}, cols ...string) error
	Delete(model interface{}) (int64, error)
	Select(models interface{}, fields Cond, orderby ...interface{}) error
	SelectLimit(models interface{}, fields Cond, offset int64, limit int64, orderby ...interface{}) error
	One(model interface{}, fields Cond) error
	Count(model interface{}, fields Cond) (int64, error)
	Exec(sql string, args ...interface{}) (int64, error)
	Using(name string) error
	QuerySQL(dests interface{}, sql string, args ...interface{}) error
	ExecSQL(dest interface{}, sql string, args ...interface{}) error
}

type IOrm

type IOrm interface {
	IOperateSet
	ITransaction
}

func NewOrm

func NewOrm() IOrm

NewOrm create new orm

type ITransaction

type ITransaction interface {
	Tx(ctx context.Context, fn func(tx ITx) error) error
}

type ITx

type ITx interface {
	//goorm.OperateSet adds operation methods to the transaction.
	IOperateSet
	//Rollbacker add Rollback method to the transaction.
	Rollbacker
	//Commiter add Commiter method to the transaction.
	Commiter
}

type Rollbacker

type Rollbacker interface {
	// Rollback discards all the instructions on the current transaction.
	Rollback() error
}

type Transaction

type Transaction struct {
	Tx sqlbuilder.Tx
	// contains filtered or unexported fields
}

func (*Transaction) Commit

func (t *Transaction) Commit() error

func (*Transaction) Count

func (t *Transaction) Count(model interface{}, fields Cond) (int64, error)

func (*Transaction) Delete

func (t *Transaction) Delete(model interface{}) (int64, error)

func (*Transaction) Exec

func (t *Transaction) Exec(sql string, args ...interface{}) (int64, error)

func (*Transaction) ExecSQL

func (t *Transaction) ExecSQL(dest interface{}, sql string, args ...interface{}) error

func (*Transaction) Insert

func (t *Transaction) Insert(model interface{}) (int64, error)

func (*Transaction) One

func (t *Transaction) One(model interface{}, fields Cond) error

func (*Transaction) QuerySQL

func (t *Transaction) QuerySQL(dests interface{}, sql string, args ...interface{}) error

func (*Transaction) Rollback

func (t *Transaction) Rollback() error

func (*Transaction) Select

func (t *Transaction) Select(models interface{}, fields Cond, orderby ...interface{}) error

func (*Transaction) SelectLimit

func (t *Transaction) SelectLimit(models interface{}, fields Cond, offset int64, limit int64, orderby ...interface{}) error

func (*Transaction) Update

func (t *Transaction) Update(model interface{}, cols ...string) error

func (*Transaction) Using

func (t *Transaction) Using(name string) error

Jump to

Keyboard shortcuts

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