暂存
This commit is contained in:
parent
924da6fdd8
commit
d373a401de
@ -6,9 +6,18 @@ import (
|
|||||||
"go_dreamfactory/lego/sys/redis"
|
"go_dreamfactory/lego/sys/redis"
|
||||||
"go_dreamfactory/sys/cache"
|
"go_dreamfactory/sys/cache"
|
||||||
|
|
||||||
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Action string
|
||||||
|
|
||||||
|
const (
|
||||||
|
INSERT Action = "insert"
|
||||||
|
UPDATE Action = "update"
|
||||||
|
DELETE Action = "delete"
|
||||||
|
)
|
||||||
|
|
||||||
type DBModel struct {
|
type DBModel struct {
|
||||||
*MComp_DBComp
|
*MComp_DBComp
|
||||||
pbData proto.Message
|
pbData proto.Message
|
||||||
@ -37,13 +46,21 @@ func (m *DBModel) SetTableName(tableName string) {
|
|||||||
m.tableName = tableName
|
m.tableName = tableName
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *DBModel) OnChange() {
|
func (m *DBModel) OnChange(key string) {
|
||||||
|
m.MComp_DBComp.InsertModelLogs(m.tableName, key, m.pbData)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *DBModel) Set(key string, val interface{}) {
|
func (m *DBModel) Set(key string, act Action) {
|
||||||
|
|
||||||
//调用写入mongo日志接口
|
//调用写入mongo日志接口
|
||||||
|
switch act {
|
||||||
|
case INSERT:
|
||||||
|
m.MComp_DBComp.InsertModelLogs(m.tableName, key, m.pbData)
|
||||||
|
case UPDATE:
|
||||||
|
m.MComp_DBComp.UpdateModelLogs(m.tableName, key, bson.M{"_id": key}, m.pbData)
|
||||||
|
case DELETE:
|
||||||
|
m.MComp_DBComp.DeleteModelLogs(m.tableName, key, bson.M{"_id": key})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取数据
|
//获取数据
|
||||||
|
@ -2,6 +2,8 @@ package user
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"go_dreamfactory/modules"
|
||||||
|
"go_dreamfactory/pb"
|
||||||
"go_dreamfactory/sys/cache"
|
"go_dreamfactory/sys/cache"
|
||||||
"go_dreamfactory/sys/db"
|
"go_dreamfactory/sys/db"
|
||||||
"os"
|
"os"
|
||||||
@ -23,7 +25,9 @@ func TestMain(m *testing.M) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGet(t *testing.T) {
|
func TestGet(t *testing.T) {
|
||||||
// userModel := NewUserModel()
|
userModel := NewUserModel()
|
||||||
|
userModel.SetData(&pb.DB_UserData{Name: "aaaaa"})
|
||||||
|
userModel.Set("1_62a729fc0e01ab2819553242", modules.INSERT)
|
||||||
// userModel.Set("1_62a729fc0e01ab2819553242",)
|
// userModel.Set("1_62a729fc0e01ab2819553242",)
|
||||||
// fmt.Printf("%v", userModel.GetData().(*pb.Cache_UserData))
|
// fmt.Printf("%v", userModel.GetData().(*pb.Cache_UserData))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user