session

package
v0.0.0-...-a98f5d9 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HOOK_AFTER_SELECT  = "CallAfterSelect"
	HOOK_AFTER_UPDATE  = "CallAfterUpdate"
	HOOK_AFTER_DELETE  = "CallAfterDelete"
	HOOK_AFTER_INSERT  = "CallAfterInsert"
	HOOK_BEFORE_SELECT = "CallBeforeSelect"
	HOOK_BEFORE_UPDATE = "CallBeforeUpdate"
	HOOK_BEFORE_DELETE = "CallBeforeDelete"
	HOOK_BEFORE_INSERT = "CallBeforeInsert"
)

Hooks constants

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseDB

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

BaseDB is a minimal function set of db.

type Session

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

Session keep a pointer to sql.DB and provides all execution of all kind of database operations.

func New

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

New creates a instance of Session.

func (*Session) Begin

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

Begin begins a transaction.

func (*Session) CallMethod

func (own *Session) CallMethod(method string, value any)

CallMethod calls the registered hooks

func (*Session) Clear

func (own *Session) Clear()

Clear initializes the state of a session.

func (*Session) Commit

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

Commit commits a transaction.

func (*Session) Count

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

Count counts records with where clause

func (*Session) CreateTable

func (own *Session) CreateTable() error

CreateTable creates a table in database with a data model

func (*Session) Delete

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

Delete records with where clause

func (*Session) DropTable

func (own *Session) DropTable() error

DropTable drops a table with the name of data model

func (*Session) Exec

func (own *Session) Exec(query string, args ...any) (result sql.Result, err error)

Exec executes a raw sql with variables.

func (*Session) GetDB

func (own *Session) GetDB() BaseDB

GetDB returns tx if a *sql.TX begins, otherwise returns *sql.DB.

func (*Session) GetSchema

func (own *Session) GetSchema() *schema.Schema

GetSchema returns a Schema instance that contains all parsed fields

func (*Session) GroupBy

func (own *Session) GroupBy(fields ...any) *Session

GroupBy adds a group clause to statement

func (*Session) Insert

func (own *Session) Insert(values ...any) (int64, error)

Insert inserts one or more records into database

func (*Session) IsExistTable

func (own *Session) IsExistTable() bool

IsExistTable returns true of the table exists

func (*Session) Limit

func (own *Session) Limit(limits ...any) *Session

Limit adds a limit clause to statement

func (*Session) OrderBy

func (own *Session) OrderBy(orders ...any) *Session

OrderBy adds a order clause to statement

func (*Session) Query

func (own *Session) Query(query string, args ...any) (rows *sql.Rows, err error)

Query gets a list of records from db.

func (*Session) QueryRow

func (own *Session) QueryRow(query string, args ...any) *sql.Row

QueryRow gets a record from db.

func (*Session) Rollback

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

Rollback rollbacks a transaction.

func (*Session) Select

func (own *Session) Select(values any) error

Select gets all eligible records

func (*Session) SelectFirst

func (own *Session) SelectFirst(value any) error

SelectFirst selects the 1st record

func (*Session) SetModel

func (own *Session) SetModel(model any) *Session

SetModel assigns a schema

func (*Session) Update

func (own *Session) Update(values ...any) (int64, error)

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

func (*Session) Where

func (own *Session) Where(conditions ...any) *Session

Where adds a where clause to statement

Jump to

Keyboard shortcuts

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