-
Notifications
You must be signed in to change notification settings - Fork 2
/
imp_country.go
53 lines (44 loc) · 1013 Bytes
/
imp_country.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
package dao
import (
"database/sql"
"github.com/xfyun/xns/models"
"github.com/xfyun/xns/resource"
"strconv"
)
type countryDao struct {
*baseDao
}
func NewCountryDao(db *sql.DB)Country{
return &countryDao{
baseDao:newBaseDao(db,&models.Country{},ChannelCountry,TableCountry),
}
}
func (i *countryDao)GetByCode(code int)(res *models.Country,err error){
res = new(models.Country)
err = i.queryByCond(newCodeCond(code),res)
return
}
func (i *countryDao)GetList()(res []*models.Country,err error){
err = i.queryAll(&res)
return
}
func (i *countryDao)Create(c *models.Country)error{
createBase(&c.Base)
return i.insertAndSendEvent(c,c.Id)
}
func (i *countryDao)Delete(code int)error{
return i.deleteAndSendEvent(newCodeCond(code),strconv.Itoa(code))
}
func (i *countryDao)Init()error{
for _, country := range resource.Countries {
err := i.Create(&models.Country{
Base: models.Base{},
Code: country.Code,
Name: country.Name,
})
if err != nil{
return err
}
}
return nil
}