session

package
v0.0.0-...-00c1370 Latest Latest
Warning

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

Go to latest
Published: May 11, 2024 License: GPL-3.0 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 ...any) (*sql.Rows, error)
	QueryRow(query string, args ...any) *sql.Row
	Exec(query string, args ...any) (sql.Result, error)
}

CommonDB is a minimal function set of db

type IAfterDelete

type IAfterDelete interface {
	AfterDelete(s *Session) error
}

type IAfterInsert

type IAfterInsert interface {
	AfterInsert(s *Session) error
}

type IAfterQuery

type IAfterQuery interface {
	AfterQuery(s *Session) error
}

type IAfterUpdate

type IAfterUpdate interface {
	AfterUpdate(s *Session) error
}

type IBeforeDelete

type IBeforeDelete interface {
	BeforeDelete(s *Session) error
}

type IBeforeInsert

type IBeforeInsert interface {
	BeforeInsert(s *Session) error
}

type IBeforeQuery

type IBeforeQuery interface {
	BeforeQuery(s *Session) error
}

type IBeforeUpdate

type IBeforeUpdate interface {
	BeforeUpdate(s *Session) error
}

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)

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)

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)

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 any) error

func (*Session) First

func (s *Session) First(value any) error

First only show the first record

func (*Session) HasTable

func (s *Session) HasTable() bool

func (*Session) Insert

func (s *Session) Insert(values ...any) (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 any) *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

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 ...any) *Session

func (*Session) RefTable

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

func (*Session) Rollback

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

func (*Session) Update

func (s *Session) Update(kv ...any) (int64, error)

Update records with where condition support map[string]any also support kv list: "Name", "Tom", "Age", 18, ...

func (*Session) Where

func (s *Session) Where(desc string, args ...any) *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