dbopt

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNoRecordErr

func IsNoRecordErr(err error) bool

IsNoRecordErr 是否是没有记录错误

Types

type DSN

type DSN struct {
	Username string
	Password string
	URL      string
	Port     string
	DBName   string
	SkipTran bool
	PreStmt  bool
	LogLevel int
}

DSN 连接数据库路由参数

func (DSN) MySQL

func (d DSN) MySQL() string

MySQL 生成MySQL的dsn

func (DSN) Postgres

func (d DSN) Postgres() string

Postgres 生成Postgres的dsn

type IGormOpt

type IGormOpt interface {
	Close()
	IsConflictErr(err error) bool
	CreateTable(dst any) error
	ExecSQL(sql string, values ...any) (int64, error)
	Query(dest any, stmt string, values ...any) error
	Insert(value any, conds ...clause.Expression) error
	InsertTb(tb string, value any, conds ...clause.Expression) error
	BatchInsert(value any, batchSize int, conds ...clause.Expression) error
	BatchInsertTb(tb string, value any, batchSize int, conds ...clause.Expression) error
	QueryRows(hand func(*gorm.DB, *sql.Rows) error, sql string, values ...any) error
	QueryRow(hand func(*gorm.DB, *sql.Row) error, sql string, values ...any) error
	GetGormDB() *gorm.DB
}

IGormOpt Gorm操作接口

func MustOpen

func MustOpen(dial gorm.Dialector, d DSN) IGormOpt

MustOpen 无错的连接数据库并返回*GormDB

func MustOpenMySQL

func MustOpenMySQL(d DSN) IGormOpt

MustOpenMySQL 无错的连接MySQL返回*gorm.DB

func MustOpenPostgres

func MustOpenPostgres(d DSN) IGormOpt

MustOpenPostgres 无错的连接Postgres返回*gorm.DB

type StmtDB

type StmtDB struct {
	*sqlx.DB
	// contains filtered or unexported fields
}

StmtDB 嵌入sqlx.DB,加了statement缓存

func NewStmtDB

func NewStmtDB(db *sqlx.DB) *StmtDB

NewStmtDB 创建StmtDB

func (*StmtDB) CloseDB

func (s *StmtDB) CloseDB()

CloseDB 关闭StmtDB

func (*StmtDB) DeferLock

func (s *StmtDB) DeferLock() func()

DeferLock 合并锁的使用 example: defer s.DeferLock()()

func (*StmtDB) Lock

func (s *StmtDB) Lock()

Lock 使用锁

func (*StmtDB) NStmt

func (s *StmtDB) NStmt(sqlStr string) (stmt *sqlx.NamedStmt, err error)

NStmt 懒加载的方式缓存sqlx.NamedStmt

func (*StmtDB) Stmt

func (s *StmtDB) Stmt(sqlStr string) (stmt *sqlx.Stmt, err error)

Stmt 懒加载的方式缓存sqlx.Stmt

func (*StmtDB) Unlock

func (s *StmtDB) Unlock()

Unlock 释放锁

Jump to

Keyboard shortcuts

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