conn

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 11, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

README



用于获取数据库连接对象
可或取master DB 或slave 连接
针对列表报表等 一委从slave 库中查询,多个slave 时用uid进行hash后查询

Documentation

Index

Constants

View Source
const CONF_CURRDB = "currdb"
View Source
const CONF_DBNAME = "database"
View Source
const CONF_DBPASSWORD = "password"
View Source
const CONF_DBPORT = "port"
View Source
const CONF_DBSERVER = "server"
View Source
const CONF_DBUSERNAME = "username"
View Source
const CONF_SEC_GLOBAL = "global"
View Source
const DBTYPE_MYSQL = "mysql"
View Source
const DBTYPE_OCR = "ocrdb"
View Source
const DBTYPE_SQLSERVER = "mssql"

Variables

View Source
var DBType string
View Source
var EngineMap map[string]*xorm.Engine

采用单例

Functions

func GetConnStr

func GetConnStr() string

GetConnStr 获取当前连接字符串

func GetConnection

func GetConnection(userid string, ismasterdb bool) (db *xorm.Engine, err error)

获取数据库连接对象,主从方式获取,根据传递的userid 确定从数据库连接 Engine调用一个SQL都会创建新的Session,完毕又会关闭Session, 多个SQL语句场景,非常消耗性能 多个SQL语句场景,建议使用 GetSession 获取Session ,注意需要手动关闭 建议使用该方法关闭:defer session.Close()

func GetDB

func GetDB() (db *xorm.Engine, err error)

GetConnection 获取连接对象

func GetEasyTraDb

func GetEasyTraDb() (db *xorm.Engine, err error)

GetDBConnection 获取连接对象

func GetOcrDB

func GetOcrDB() (db *xorm.Engine, err error)

GetDBConnection 获取连接对象

func GetSession

func GetSession(ismasterdb bool) (db *xorm.Session)

GetDBConnection 获取连接对象

func InitConnections

func InitConnections()

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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