forked from fuyibing/db
-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.go
47 lines (41 loc) · 778 Bytes
/
service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// author: wsfuyibing <websearch@163.com>
// date: 2021-02-13
package db
import (
"xorm.io/xorm"
)
// Struct for anonymous in service.
//
// type ExampleService struct{
// xdb.Service
// }
//
// func NewExampleService(s ...*xorm.Session) *ExampleService {
// o := &ExampleService{}
// o.Use(s...)
// return o
// }
//
type Service struct {
sess *xorm.Session
}
// Read master connection.
func (o *Service) Master() *xorm.Session {
if o.sess == nil {
return Master()
}
return o.sess
}
// Return slave connection.
func (o *Service) Slave() *xorm.Session {
if o.sess == nil {
return Slave()
}
return o.sess
}
// Use specified connection.
func (o *Service) Use(s ...*xorm.Session) {
if s != nil && len(s) > 0 {
o.sess = s[0]
}
}