mgorm

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 6 Imported by: 2

README

mgorm

帮助你简单管理 gorm 连接,多数据库连接,Sass 多数据库切换

go mod init github.com/qq1060656096/mgorm
# 代码静态检查发现可能的bug或者可疑的构造
go vet .

# 竞态检测
go build -race -v .

# 开启本地官网
go get -v -u golang.org/x/tools/cmd/godoc
godoc -http=:8080 
# 运行所有单元测试
# 在当前目录运行所有测试,并且每个测试函数都会执行一次,同时输出详细的测试信息。这对于调试和查看测试详细输出很有用。
go test -count=1 -v . 

# 运行所有单元测试,并查看测试覆盖率
go test -count=1 -v -cover .

# 运行所有单元测试,并查看测试覆盖率,竞态检测
go test -count=1 -v -cover -race .

# 并发测试正确
go test -count=1 -v -race -run=TestConcurrent_DbInsertOk . 
# 并发测试错误
go test -count=1 -v -race -run=TestConcurrent_DbSelectErr . 

单元测试 sql
# mysql
CREATE TABLE `test` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `nickname` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
  
# sqlite3
CREATE TABLE "test" (
  "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  "nickname" text NOT NULL DEFAULT ''
);

Documentation

Index

Constants

View Source
const (
	DriverNameMySql     = "mysql"
	DriverNamePostgres  = "postgres"
	DriverNameSqlite3   = "sqlite3"
	DriverNameSqlServer = "sqlserver"
)

Variables

This section is empty.

Functions

func Open

func Open(conf Config) gorm.Dialector

Types

type Config

type Config struct {
	DriverName string
	Dns        string
}

type Connection

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

func NewConnection

func NewConnection(config Config) *Connection

func (*Connection) Connect

func (c *Connection) Connect() error

Connect 连接数据库

func (*Connection) Disconnect

func (c *Connection) Disconnect() error

Disconnect 断开连接

func (*Connection) GetDB

func (c *Connection) GetDB() (*gorm.DB, error)

type ConnectionManager

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

ConnectionManager 连接管理器

func DefaultConnectionManager

func DefaultConnectionManager() *ConnectionManager

DefaultConnectionManager 默认连接管理器

func NewConnectionManager

func NewConnectionManager() *ConnectionManager

NewConnectionManager 创建连接管理器

func (*ConnectionManager) Add

func (m *ConnectionManager) Add(name string, con *Connection)

Add 添加连接

func (*ConnectionManager) Delete

func (m *ConnectionManager) Delete(name string)

Delete 删除连接

func (*ConnectionManager) Exist

func (m *ConnectionManager) Exist(name string) bool

Exist 判断连接是否存在

func (*ConnectionManager) Get

func (m *ConnectionManager) Get(name string) *Connection

Get 获取连接

Jump to

Keyboard shortcuts

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