2023-09-10 16:07:03 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-09-16 10:09:34 +00:00
|
|
|
// ptr 基于类型获取实例指针
|
|
|
|
func (m *model) ptr() any {
|
|
|
|
return reflect.New(m.modelKind).Interface()
|
|
|
|
}
|
|
|
|
|
2023-09-10 16:07:03 +00:00
|
|
|
type scope struct {
|
|
|
|
*model
|
|
|
|
*sdbc
|
|
|
|
}
|
|
|
|
|
2023-09-16 10:09:34 +00:00
|
|
|
func (s *scope) Insert() *_insert {
|
|
|
|
return &_insert{
|
2023-09-10 16:07:03 +00:00
|
|
|
scope: s,
|
|
|
|
sdbc: s.sdbc,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-16 10:09:34 +00:00
|
|
|
func (s *scope) Find() *_find {
|
|
|
|
return &_find{
|
|
|
|
scope: s,
|
|
|
|
sdbc: s.sdbc,
|
|
|
|
}
|
2023-09-10 16:07:03 +00:00
|
|
|
}
|
|
|
|
|
2023-09-16 10:09:34 +00:00
|
|
|
func (s *scope) Update() *_update {
|
|
|
|
return &_update{
|
|
|
|
scope: s,
|
|
|
|
sdbc: s.sdbc,
|
|
|
|
}
|
2023-09-10 16:07:03 +00:00
|
|
|
}
|
|
|
|
|
2023-09-16 10:09:34 +00:00
|
|
|
func (s *scope) Delete() *_delete {
|
|
|
|
return &_delete{
|
|
|
|
scope: s,
|
|
|
|
sdbc: s.sdbc,
|
|
|
|
}
|
2023-09-10 16:07:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Operator interface {
|
2023-09-16 10:09:34 +00:00
|
|
|
Insert() *_insert
|
|
|
|
Find() *_find
|
|
|
|
Update() *_update
|
|
|
|
Delete() *_delete
|
2023-09-10 16:07:03 +00:00
|
|
|
}
|