xorm_ext

package module
v0.0.0-...-863773a Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2016 License: Apache-2.0 Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

XORM Ext

Make the biz logic Mockable, Data Repository Mockable, transaction session could around the biz logic

Usage
package main

import (
    "fmt"

    "github.com/go-xorm/xorm"

    "github.com/gogap/xorm_ext"
)

type User struct {
    UserName string
    Password string
}

type UserRepo interface {
    GetUser() string
}

type DBUserRepo struct {
    xorm_ext.DBRepo
}

func NewUserRepo(ormEngines map[string]*xorm.Engine) *DBUserRepo {
    repo := new(DBUserRepo)
    repo.SetEngines(ormEngines)
    return repo
}

func (p *DBUserRepo) GetUser() string {
    //p.Session().Query(sqlStr, ...)
    return "unknown"
}

func main() {

    engines := map[string]*xorm.Engine{xorm_ext.REPO_DEFAULT_ENGINE: new(xorm.Engine)}

    userRepo := NewUserRepo(engines)

    dbTXCommitter := new(xorm_ext.DBTXCommiter)

    logicFunc := func(repos []interface{}) (err error) {
        fmt.Println("enter logic")

        var uRepo UserRepo
        for _, repo := range repos {
            switch repo := repo.(type) {
            case UserRepo:
                {
                    //this userRepo is a new instance of DBUserRepo
                    fmt.Println("get new user repo")
                    uRepo = repo
                }
            }
        }

        userName := uRepo.GetUser()
        fmt.Println(userName)

        return
    }

    err := dbTXCommitter.Transaction(logicFunc, userRepo)
    //Or
    //err := dbTXCommitter.TransactionUsing("xormEngineName", userRepo, logicFunc)
    if err != nil {
        fmt.Println(err)
    }
}

Documentation

Index

Constants

View Source
const (
	Logic       int = 0
	BeforeLogic int = 1
	AfterLogic  int = 2
	OnError     int = 3
	AfterCommit int = 4
)
View Source
const (
	REPO_DEFAULT_ENGINE               = "default"
	REPO_ERR_DEFAULT_ENGINE_NOT_FOUND = "`default` xorm engine not found"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DBRepo

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

func (*DBRepo) DefaultEngine

func (p *DBRepo) DefaultEngine() *xorm.Engine

func (*DBRepo) Engines

func (p *DBRepo) Engines() map[string]*xorm.Engine

func (*DBRepo) IsTransaction

func (p *DBRepo) IsTransaction() bool

func (*DBRepo) NewSession

func (p *DBRepo) NewSession() *xorm.Session

func (*DBRepo) Session

func (p *DBRepo) Session() *xorm.Session

func (*DBRepo) SessionUsing

func (p *DBRepo) SessionUsing(engineName string) *xorm.Session

func (*DBRepo) SetEngines

func (p *DBRepo) SetEngines(ormEngines map[string]*xorm.Engine)

type DBTXCommiter

type DBTXCommiter struct {
}

func (*DBTXCommiter) NoTransaction

func (p *DBTXCommiter) NoTransaction(txFunc interface{}, originRepos ...interface{}) (err error)

func (*DBTXCommiter) NoTransactionUsing

func (p *DBTXCommiter) NoTransactionUsing(txFunc interface{}, name string, originRepos ...interface{}) (err error)

func (*DBTXCommiter) Transaction

func (p *DBTXCommiter) Transaction(txFunc interface{}, originRepos ...interface{}) (err error)

func (*DBTXCommiter) TransactionUsing

func (p *DBTXCommiter) TransactionUsing(txFunc interface{}, name string, originRepos ...interface{}) (err error)

type Deriver

type Deriver interface {
	Derive() (v interface{}, err error)
}

type Inheriter

type Inheriter interface {
	Inherit(originalRepo interface{}) (err error)
}

type TXFunc

type TXFunc func(repos []interface{}) (err error)

type TransactionCommiter

type TransactionCommiter interface {
	Transaction(txFunc interface{}, repos ...interface{}) (err error)
	TransactionUsing(txFunc interface{}, name string, repos ...interface{}) (err error)
	NoTransaction(txFunc interface{}, repos ...interface{}) (err error)
	NoTransactionUsing(txFunc interface{}, name string, repos ...interface{}) (err error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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