server/pkg/modules/user/user-dao.go

40 lines
680 B
Go
Raw Normal View History

2019-11-18 14:28:56 +00:00
package user
import (
"context"
"log"
"reflect"
"git.loafle.net/loafer/annotation-go"
"git.loafle.net/loafer/di-go"
"github.com/jackc/pgx/v4"
)
var UserDaoType = reflect.TypeOf((*UserDao)(nil))
func init() {
di.RegisterType(UserDaoType)
}
type UserDao struct {
annotation.TypeAnnotation `annotation:"@web:Dao(\"name\": \"/userDao\")"`
Conn *pgx.Conn `annotation:"@Resource(\"name\": \"dbConn\")"`
}
func (ud *UserDao) FindAll() {
log.Printf("UserDao FindAll")
row, err := ud.Conn.Query(context.Background(), "SELECT NOW()")
if nil != err {
log.Printf("%v", err)
return
}
if row.Next() {
var date string
row.Scan(&date)
log.Printf("%s", date)
}
}