db

package module
v5.1.12 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2023 License: BSD-3-Clause Imports: 13 Imported by: 0

README

DB

XORM Plugin

Import
import (
    "github.com/fuyibing/db/v5"
)

Documentation

Overview

Package db database plugin based on xorm.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Transaction

func Transaction(ctx context.Context, handlers ...TransactionHandler) error

Transaction 创建事务.

func TransactionWithSession

func TransactionWithSession(ctx context.Context, sess *xorm.Session, handlers ...TransactionHandler) (err error)

TransactionWithSession 基于指定连接创建事务.

Types

type Configuration

type Configuration struct {
	// 数据源列表.
	Databases map[string]*Database `yaml:"databases"`
	// contains filtered or unexported fields
}

Configuration 配置参数.

var (
	// Config
	// 应用于IRIS的配置.
	Config *Configuration
)

func (*Configuration) GetDatabase

func (o *Configuration) GetDatabase(key string) *Database

GetDatabase 按Key名称读取数据源.

func (*Configuration) GetUndefined added in v5.1.1

func (o *Configuration) GetUndefined() *Database

GetUndefined 读取数据源.

func (*Configuration) SetDatabase

func (o *Configuration) SetDatabase(key string, database *Database)

SetDatabase 设置数据源.

type Connection

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

Connection 连接管理接口.

var (
	// Connector
	// 连接管理.
	Connector *Connection
)

func (*Connection) GetEngineGroup

func (o *Connection) GetEngineGroup(keys ...string) (engine *xorm.EngineGroup)

GetEngineGroup 读取XORM引擎组.

func (*Connection) GetMaster

func (o *Connection) GetMaster(keys ...string) *xorm.Session

GetMaster 从Master获取Session.

func (*Connection) GetMasterWithContext

func (o *Connection) GetMasterWithContext(ctx context.Context, keys ...string) *xorm.Session

GetMasterWithContext 基于Context从Master获取Session.

func (*Connection) GetSlave

func (o *Connection) GetSlave(keys ...string) *xorm.Session

GetSlave 从Slave获取Session.

func (*Connection) GetSlaveWithContext

func (o *Connection) GetSlaveWithContext(ctx context.Context, keys ...string) *xorm.Session

GetSlaveWithContext 基于Context从Slave获取Session.

type Database

type Database struct {
	Driver        string   `yaml:"driver"`
	Dsn           []string `yaml:"dsn"`
	EnableSession *bool    `yaml:"enable-session"`
	MaxIdle       int      `yaml:"max-idle"`
	MaxLifetime   int      `yaml:"max-lifetime"`
	MaxOpen       int      `yaml:"max-open"`
	Mapper        string   `yaml:"mapper"`
	ShowSQL       *bool    `yaml:"show-sql"`
	// contains filtered or unexported fields
}

Database 数据源定义.

func (*Database) GetDataName

func (o *Database) GetDataName() string

GetDataName 获取数据库名.

func (*Database) GetHost added in v5.1.1

func (o *Database) GetHost() string

GetHost 获取数据源地址.

func (*Database) GetMapper

func (o *Database) GetMapper() names.Mapper

GetMapper 获取映射名.

func (*Database) GetUsername

func (o *Database) GetUsername() string

GetUsername 获取用户名.

func (*Database) Internal added in v5.1.1

func (o *Database) Internal() bool

Internal 是否内部源.

type Service

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

Service 服务封装.

func (*Service) Master

func (o *Service) Master() *xorm.Session

Master 使用主库连接.

func (*Service) Slave

func (o *Service) Slave() *xorm.Session

Slave 使用从库连接.

func (*Service) Use

func (o *Service) Use(sessions ...*xorm.Session)

Use 绑定连接.

func (*Service) UseConnection

func (o *Service) UseConnection(connection string)

UseConnection 绑定连接名.

type TransactionHandler

type TransactionHandler func(ctx context.Context, sess *xorm.Session) error

TransactionHandler 事务Handler回调.

Jump to

Keyboard shortcuts

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