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"
|
|
|
|
|
2019-11-19 13:54:01 +00:00
|
|
|
"github.com/jackc/pgx/v4/pgxpool"
|
2019-11-18 14:28:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var UserDaoType = reflect.TypeOf((*UserDao)(nil))
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
di.RegisterType(UserDaoType)
|
|
|
|
}
|
|
|
|
|
|
|
|
type UserDao struct {
|
|
|
|
annotation.TypeAnnotation `annotation:"@web:Dao(\"name\": \"/userDao\")"`
|
|
|
|
|
2019-11-19 13:54:01 +00:00
|
|
|
Pool *pgxpool.Pool `annotation:"@Resource(\"name\": \"dbConnPool\")"`
|
2019-11-18 14:28:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ud *UserDao) FindAll() {
|
|
|
|
log.Printf("UserDao FindAll")
|
2019-11-19 13:54:01 +00:00
|
|
|
|
|
|
|
conn, err := ud.Pool.Acquire(context.Background())
|
|
|
|
if nil != err {
|
|
|
|
log.Printf("%v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer conn.Release()
|
|
|
|
|
|
|
|
row, err := conn.Query(context.Background(), "select count(*) from users")
|
2019-11-18 14:28:56 +00:00
|
|
|
if nil != err {
|
|
|
|
log.Printf("%v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if row.Next() {
|
2019-11-19 13:54:01 +00:00
|
|
|
var date int64
|
2019-11-18 14:28:56 +00:00
|
|
|
row.Scan(&date)
|
2019-11-19 13:54:01 +00:00
|
|
|
log.Printf("%d", date)
|
2019-11-18 14:28:56 +00:00
|
|
|
}
|
|
|
|
}
|