update
This commit is contained in:
+40
-1
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user