database

package module
v0.0.0-...-32eaf10 Latest Latest
Warning

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

Go to latest
Published: May 10, 2024 License: Apache-2.0 Imports: 7 Imported by: 6

README

db

支持的数据库:

  • postgresql
  • mysql
  • clickhouse
  • sqlite

toml 配置示例:

[DB]
# 连接地址
Host = "localhost"
# 连接端口
Port = 5432
# 用户名
User = "root"
# 密码
Password = "123456"
# 数据库
DBName = "test"
# SSL模式
SSLMode = "disable"
# 是否开启调试模式
Debug = true
# 数据库类型(目前支持的数据库类型:postgres, mysql, sqlite)
DBType = "postgres"
# 设置连接可以重用的最长时间(单位:秒)
MaxLifetime = 7200
# 设置数据库的最大打开连接数
MaxOpenConns = 150
# 设置空闲连接池中的最大连接数
MaxIdleConns = 50
# 数据库表名前缀
TablePrefix = "s_"
# 是否启用自动映射数据库表结构
EnableAutoMigrate = true

Documentation

Overview

Package database Date: 2023/4/4 13:57 Author: Amu Description:

Package database Date: 2023/12/6 15:46 Author: Amu Description:

Package database Date: 2023/12/6 17:27 Author: Amu Description:

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	*gorm.DB
}

func NewDB

func NewDB(opts ...Option) (*DB, error)

func OptionDB

func OptionDB(db *DB, options ...QueryOption) *DB

func (*DB) AutoMigrate

func (db *DB) AutoMigrate(models ...interface{}) error

func (*DB) Close

func (db *DB) Close()

func (*DB) RunInTransaction

func (db *DB) RunInTransaction(fn func(tx *gorm.DB) error) error

type Option

type Option func(*option)

func WithDBName

func WithDBName(name string) Option

func WithDebug

func WithDebug(debug bool) Option

func WithHost

func WithHost(host string) Option

func WithMaxIdleConns

func WithMaxIdleConns(maxIdle int) Option

func WithMaxLifetime

func WithMaxLifetime(lifetime int) Option

func WithMaxOpenConns

func WithMaxOpenConns(maxOpen int) Option

func WithPassword

func WithPassword(password string) Option

func WithPort

func WithPort(port string) Option

func WithType

func WithType(t string) Option

func WithUsername

func WithUsername(username string) Option

type QueryOption

type QueryOption func(db *DB) *DB

func OrderBy

func OrderBy(value interface{}) QueryOption

func WithById

func WithById(id string) QueryOption

func WithInIds

func WithInIds(ids ...string) QueryOption

func WithLimit

func WithLimit(limit int) QueryOption

func WithOffset

func WithOffset(offset int) QueryOption

func WithTable

func WithTable(tableName string) QueryOption

Jump to

Keyboard shortcuts

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