session

package
v0.0.0-...-803ac38 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2025 License: MIT Imports: 10 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

func ConvertToAny

func ConvertToAny[T any](vals ...T) []any

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 定义数据库操作的基本接口

type Session

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

Session 定义数据库连接会话的数据结构

func New

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

New 新建一个连接会话

func (*Session) Begin

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

Begin 开始事务

func (*Session) CallMethod

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

CallMethod calls the registered hooks

func (*Session) Commit

func (own *Session) Commit() error

Commit 提交事务

func (*Session) Count

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

Count 根据条件统计数据

func (*Session) CreateTable

func (own *Session) CreateTable(engine ...string) error

CreateTable 创建数据表

func (*Session) Delete

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

Delete 根据条件删除数据

func (*Session) DropTable

func (own *Session) DropTable() error

DropTable 删除数据表

func (*Session) Exec

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

Exec 执行 SQL 语句

func (*Session) GetDB

func (own *Session) GetDB() BaseDB

GetDB 返回 *sql.DB 或 *sql.TX

func (*Session) GetSchema

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

GetSchema 获取数据表信息

func (*Session) GroupBy

func (own *Session) GroupBy(columns ...string) *Session

GroupBy 添加 GROUP BY 子句

func (*Session) Insert

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

Insert 插入一条或多条数据到数据表

func (*Session) IsExistTable

func (own *Session) IsExistTable() bool

IsExistTable 检查数据表是否存在

func (*Session) Limit

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

Limit 添加 LIMIT 子句

func (*Session) OrderBy

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

OrderBy 添加 ORDER BY 子句

func (*Session) Query

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

Query 执行 SQL 查询语句,返回多条结果

func (*Session) QueryRow

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

QueryRow 执行 SQL 查询语句,返回单条结果

func (*Session) Reset

func (own *Session) Reset() *Session

Reset 重置 SQL 语句

func (*Session) Rollback

func (own *Session) Rollback() error

Rollback 回滚事务

func (*Session) Select

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

Select 根据条件查询第一个或所有数据

func (*Session) Update

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

Update 根据条件更新数据,支持 map[string]any 或键值对格式的列表,如:"Name","Tom","Age",18,....

func (*Session) Where

func (own *Session) Where(conds ...*where.Where) *Session

Where 添加 WHERE 子句

func (*Session) WithModel

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

WithModel 指定数据表模型

func (*Session) WithoutPrint

func (own *Session) WithoutPrint() *Session

Jump to

Keyboard shortcuts

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