dbopt

package module
v0.0.0-...-6c6e44b Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BatchInsert

func BatchInsert(gdb *gorm.DB, value any, batchSize int, conds ...clause.Expression) error

BatchInsert 批量插入数据

func CloseDB

func CloseDB(gdb *gorm.DB)

CloseDB 关闭数据库连接

func CreateTable

func CreateTable(gdb *gorm.DB, dst any) error

CreateTable 不存在的话创建表

func Insert

func Insert(gdb *gorm.DB, value any, conds ...clause.Expression) error

Insert 插入数据

func IsConflictErr

func IsConflictErr(err error) bool

IsConflictErr 是否是主键冲突错误

func IsNoRecordErr

func IsNoRecordErr(err error) bool

IsNoRecordErr 是否是没有记录错误

func MustOpen

func MustOpen(dial gorm.Dialector, d DSN) *gorm.DB

MustOpen 无错的连接数据库并返回 *gorm.DB

func MustOpenMySQL

func MustOpenMySQL(d DSN) *gorm.DB

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

func MustOpenPostgres

func MustOpenPostgres(d DSN) *gorm.DB

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

func QueryRows

func QueryRows(gdb *gorm.DB, hand func(*gorm.DB, *sql.Rows) error, sql string, values ...any) (err error)

QueryRows 批量查询使用rows行扫描处理

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

func (DSN) Sqlite

func (d DSN) Sqlite() string

Sqlite 生成Sqlite的dsn

Jump to

Keyboard shortcuts

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