-
Notifications
You must be signed in to change notification settings - Fork 1
/
imp_pool.go
62 lines (49 loc) · 1.3 KB
/
imp_pool.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package dao
import (
"database/sql"
"github.com/xfyun/xns/models"
"github.com/xfyun/xns/tools/uid"
)
type impPool struct {
*baseDao
}
func NewPool(db *sql.DB)Pool{
return &impPool{
baseDao:newBaseDao(db,&models.Pool{},ChannelPool,TablePool),
}
}
func (p *impPool) GetById(id string) (pool *models.Pool, err error) {
pool = &models.Pool{}
err = p.queryByCond(newIdCond(id), pool)
return
}
func (p *impPool) GetByName(name string) (pool *models.Pool, err error) {
pool = &models.Pool{}
err = p.queryByCond(newNameCond(name), pool)
return
}
func (p *impPool) GetByIdOrName(idOrName string) (idc *models.Pool, err error) {
if uid.IsUUID(idOrName) {
return p.GetById(idOrName)
}
return p.GetByName(idOrName)
}
func (p *impPool) GetList() (srvs []*models.Pool, err error) {
err = p.queryAll(&srvs)
return
}
func (p *impPool) Create(srv *models.Pool) error {
createBase(&srv.Base)
return p.insertAndSendEvent(srv, srv.Id)
}
func (p *impPool) Update(id string, srv *models.Pool) error {
updateBase(&srv.Base)
return p.updateAndSendEvent(newIdCond(id), srv, id)
}
func (p *impPool) Delete(id string) error {
return p.deleteAndSendEvent(newIdCond(id), id)
}
func (p *impPool)Patch(id string ,pool map[string]interface{})error{
patchBase(pool)
return p.updateAndSendEvent(newIdCond(id),pool,id)
}