data is added

This commit is contained in:
병준 박 2019-11-19 23:58:46 +09:00
parent 3ceae1e399
commit 9a15843233
5 changed files with 60 additions and 12 deletions

24
pkg/loafer/data/column.go Normal file
View File

@ -0,0 +1,24 @@
package data
import (
"reflect"
"git.loafle.net/loafer/annotation-go"
)
var ColumnAnnotationType = reflect.TypeOf((*ColumnAnnotation)(nil))
func init() {
if err := annotation.Register(ColumnAnnotationType); nil != err {
panic(err)
}
}
type ColumnAnnotation struct {
annotation.TypeAnnotation `@annotation:"@data:Column"`
Type string `json:"type"`
Name string `json:"name"`
Length uint16 `json:"length"`
Nullable bool `json:"nullable"`
}

24
pkg/loafer/data/entity.go Normal file
View File

@ -0,0 +1,24 @@
package data
import (
"reflect"
"git.loafle.net/loafer/annotation-go"
)
var EntityAnnotationType = reflect.TypeOf((*EntityAnnotation)(nil))
func init() {
if err := annotation.Register(EntityAnnotationType); nil != err {
panic(err)
}
}
type EntityAnnotation struct {
annotation.TypeAnnotation `@annotation:"@data:Entity"`
Name string `json:"name"`
Engine string `json:"engine"`
Database string `json:"database"`
Schema string `json:"schema"`
}

View File

@ -6,16 +6,16 @@ import (
"git.loafle.net/loafer/annotation-go"
)
var DaoAnnotationType = reflect.TypeOf((*DaoAnnotation)(nil))
var RepositoryAnnotationType = reflect.TypeOf((*RepositoryAnnotation)(nil))
func init() {
if err := annotation.Register(DaoAnnotationType); nil != err {
if err := annotation.Register(RepositoryAnnotationType); nil != err {
panic(err)
}
}
type DaoAnnotation struct {
annotation.TypeAnnotation `@annotation:"@web:Dao"`
type RepositoryAnnotation struct {
annotation.TypeAnnotation `@annotation:"@web:Repository"`
Name string `json:"name"`
}

View File

@ -11,22 +11,22 @@ import (
"github.com/jackc/pgx/v4/pgxpool"
)
var UserDaoType = reflect.TypeOf((*UserDao)(nil))
var UserRepositoryType = reflect.TypeOf((*UserRepository)(nil))
func init() {
di.RegisterType(UserDaoType)
di.RegisterType(UserRepositoryType)
}
type UserDao struct {
annotation.TypeAnnotation `annotation:"@web:Dao(\"name\": \"/userDao\")"`
type UserRepository struct {
annotation.TypeAnnotation `annotation:"@web:Repository(\"name\": \"/userDao\")"`
Pool *pgxpool.Pool `annotation:"@Resource(\"name\": \"dbConnPool\")"`
}
func (ud *UserDao) FindAll() {
func (ur *UserRepository) FindAll() {
log.Printf("UserDao FindAll")
conn, err := ud.Pool.Acquire(context.Background())
conn, err := ur.Pool.Acquire(context.Background())
if nil != err {
log.Printf("%v", err)
return

View File

@ -19,11 +19,11 @@ func init() {
type UserService struct {
annotation.TypeAnnotation `annotation:"@web:Service(\"name\": \"/userService\")"`
UserDao *UserDao `annotation:"@Inject()"`
UserRepository *UserRepository `annotation:"@Inject()"`
}
func (us *UserService) FindAll() {
log.Printf("UserService FindAll")
us.UserDao.FindAll()
us.UserRepository.FindAll()
}