haosession

package
v1.0.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	BeforeQuery  = "BeforeQuery"
	AfterQuery   = "AfterQuery"
	BeforeUpdate = "BeforeUpdate"
	AfterUpdate  = "AfterUpdate"
	BeforeDelete = "BeforeDelete"
	AfterDelete  = "AfterDelete"
	BeforeInsert = "BeforeInsert"
	AfterInsert  = "AfterInsert"
)

Hooks constants

Variables

This section is empty.

Functions

This section is empty.

Types

type CommonDB

type CommonDB interface {
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row
	Exec(query string, args ...interface{}) (sql.Result, error)
}

type Session

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

和数据库交互的session对象

func New

func New(db *sql.DB, dialect dialect.Dialect, dbName string) *Session

func (*Session) Begin

func (s *Session) Begin() (err error)

开启事务方法

func (*Session) CallMethod

func (s *Session) CallMethod(method string, value interface{})

invoker 方法,类似于java的 动态代理

func (*Session) Clear

func (s *Session) Clear()

func (*Session) Commit

func (s *Session) Commit() (err error)

提交事务方法

func (*Session) Count

func (s *Session) Count() (int64, error)

Count records with where clause

func (*Session) CreateTable

func (s *Session) CreateTable() error

创建表

func (*Session) DB

func (s *Session) DB() CommonDB

func (*Session) Delete

func (s *Session) Delete() (int64, error)

删除方法

func (*Session) DropTable

func (s *Session) DropTable() error

删除表

func (*Session) Exec

func (s *Session) Exec() (result sql.Result, err error)

执行一般的语句

func (*Session) HasTable

func (s *Session) HasTable() bool

判断对应的表是否存在

func (*Session) Insert

func (s *Session) Insert(values ...interface{}) (int64, error)

插入数据执行语句

func (*Session) Limit

func (s *Session) Limit(num int) *Session

Limit adds limit condition to clause

func (*Session) Model

func (s *Session) Model(value interface{}) *Session

func (*Session) OrderBy

func (s *Session) OrderBy(desc string) *Session

OrderBy adds order by condition to clause

func (*Session) QueryRow

func (s *Session) QueryRow() *sql.Row

查询单条数据

func (*Session) QueryRows

func (s *Session) QueryRows() (rows *sql.Rows, err error)

查询多条数据

func (*Session) Raw

func (s *Session) Raw(sql string, values ...interface{}) *Session

func (*Session) RefTable

func (s *Session) RefTable() *schema.Schema

func (*Session) Rollback

func (s *Session) Rollback() (err error)

回滚事务方法

func (*Session) Select

func (s *Session) Select(values interface{}) error

查询的入口方法,各种语句得前置操作

func (*Session) SelectOne

func (s *Session) SelectOne(value interface{}) error

func (*Session) Update

func (s *Session) Update(kv ...interface{}) (int64, error)

support map[string]interface{} also support kv list: "Name", "Tom", "Age", 18, ....

func (*Session) Where

func (s *Session) Where(desc string, args ...interface{}) *Session

Where adds limit condition to clause

Jump to

Keyboard shortcuts

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