sdbc/scope.go
2023-09-16 20:21:42 +08:00

61 lines
937 B
Go

package sdbc
import (
"reflect"
"google.golang.org/protobuf/proto"
)
// model props for protobuf Message
type model struct {
Type proto.Message // model prototype
modelKind reflect.Type // model low level type
modelName string // model struct name
tableName string // model mapping table name
}
// ptr 基于类型获取实例指针
func (m *model) ptr() any {
return reflect.New(m.modelKind).Interface()
}
type scope struct {
*model
*Driver
}
func (s *scope) Insert() *_insert {
return &_insert{
scope: s,
sdbc: s.Driver,
}
}
func (s *scope) Find() *_find {
return &_find{
scope: s,
sdbc: s.Driver,
}
}
func (s *scope) Update() *_update {
return &_update{
scope: s,
sdbc: s.Driver,
}
}
func (s *scope) Delete() *_delete {
return &_delete{
scope: s,
sdbc: s.Driver,
}
}
type Operator interface {
Insert() *_insert
Find() *_find
Update() *_update
Delete() *_delete
}