This commit is contained in:
Jay
2018-04-30 10:13:01 +08:00
parent 1b8416dba3
commit e33c51727a
4 changed files with 106 additions and 1 deletions
+40 -1
View File
@@ -1,6 +1,10 @@
package models
import "time"
import (
"time"
"git.trj.tw/golang/utils/dbtool"
)
// Photo model
type Photo struct {
@@ -11,3 +15,38 @@ type Photo struct {
Ctime time.Time `sql:"ctime" cc:"ctime"`
Mtime time.Time `sql:"mtime" cc:"mtime"`
}
// GetPhotos -
func GetPhotos(album string) (photo []Photo, err error) {
rows, err := x.Query(`select "id", "album", "name", "thumbnail", "ctime", "mtime" from "storage"."photo" where "album" = $1`, album)
if err != nil {
return nil, err
}
err = dbtool.ScanToStructAll(rows, &photo)
if err != nil {
return nil, err
}
return
}
// GetPhoto -
func GetPhoto(id string) (photo *Photo, err error) {
rows, err := x.Query(`select "id", "album", "name", "thumbnail", "ctime", "mtime" from "storage"."photo" where "id" = $1`, id)
if err != nil {
return nil, err
}
photo = &Photo{}
ok, err := dbtool.ScanToStruct(rows, photo)
if err != nil {
return nil, err
}
if !ok {
return nil, nil
}
return
}