session

package
v0.0.0-...-bce3628 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2020 License: MIT Imports: 9 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)
}

CommonDB is a minimal function set of db

type Session

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

func New

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

func (*Session) Begin

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

Begin a transaction

func (*Session) CallMethod

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

CallMethod calls the registered hooks

func (*Session) Clear

func (s *Session) Clear()

func (*Session) Commit

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

Commit a transaction

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

DB returns tx if a tx begins. otherwise return *sql.DB

func (*Session) Delete

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

Delete records with where clause

func (*Session) DropTable

func (s *Session) DropTable() error

func (*Session) Exec

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

Exec raw sql with sqlVars

func (*Session) Find

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

func (*Session) First

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

First gets the 1st row

func (*Session) HasTable

func (s *Session) HasTable() bool

func (*Session) Insert

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

Insert one or more records in database

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 confition to clause

func (*Session) QueryRow

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

QueryRow gets a record from db

func (*Session) QueryRows

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

QueryRows gets a list of records from db

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)

Rollback a transaction

func (*Session) Update

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

Update records with where clause 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