Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"program": "${fileDirname}"

}
]
],
"go.testFlags":["-v"]
}
95 changes: 95 additions & 0 deletions db/message.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package db

import (
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)

type Message struct {
MsgId int `gorm:"column:msgId;primary_key" json:"msgId"`
MsgSvrId int `gorm:"column:msgSvrId" json:"msgSvrId"`
Type int `gorm:"column:type" json:"type"`
Status int `gorm:"column:status" json:"status"`
IsSend int `gorm:"column:isSend" json:"isSend"`
IsShowTimer int `gorm:"column:isShowTimer" json:"isShowTimer"`
CreateTime int `gorm:"column:createTime" json:"createTime"`
Talker string `gorm:"column:talker" json:"talker"`
Content string `gorm:"column:content" json:"content"`
ImgPath string `gorm:"column:imgPath" json:"imgPath"`
Reserved string `gorm:"column:reserved" json:"reserved"`
Lvbuffer string `gorm:"column:lvbuffer" json:"lvbuffer"`
TransContent string `gorm:"column:transContent" json:"transContent"`
TransBrandWording string `gorm:"column:transBrandWording" json:"transBrandWording"`
TalkerId int `gorm:"column:talkerId" json:"talkerId"`
BizClientMsgId string `gorm:"column:bizClientMsgId" json:"bizClientMsgId"`
BizChatId int `gorm:"column:bizChatId" json:"bizChatId"`
BizChatUserId string `gorm:"column:bizChatUserId" json:"bizChatUserId"`
MsgSeq int `gorm:"column:msgSeq" json:"msgSeq"`
Flag int `gorm:"column:flag" json:"flag"`
SolitaireFoldInfo string `gorm:"column:solitaireFoldInfo" json:"solitaireFoldInfo"`
HistoryId string `gorm:"column:historyId" json:"historyId"`
}

func (Message) TableName() string {
return "message"
}

type Rcontact struct {
Username string `gorm:"column:username;primary_key" json:"username"`
Alias string `gorm:"column:alias" json:"alias"`
ConRemark string `gorm:"column:conRemark" json:"conRemark"`
DomainList string `gorm:"column:domainList" json:"domainList"`
Nickname string `gorm:"column:nickname" json:"nickname"`
PyInitial string `gorm:"column:pyInitial" json:"pyInitial"`
QuanPin string `gorm:"column:quanPin" json:"quanPin"`
ShowHead int `gorm:"column:showHead;default:0" json:"showHead"`
Type int `gorm:"column:type;default:0" json:"type"`
UiType int `gorm:"column:uiType;default:0" json:"uiType"`
WeiboFlag int `gorm:"column:weiboFlag;default:0" json:"weiboFlag"`
WeiboNickname string `gorm:"column:weiboNickname" json:"weiboNickname"`
ConRemarkPYFull string `gorm:"column:conRemarkPYFull" json:"conRemarkPYFull"`
ConRemarkPYShort string `gorm:"column:conRemarkPYShort" json:"conRemarkPYShort"`
Lvbuff string `gorm:"column:lvbuff" json:"lvbuff"`
VerifyFlag int `gorm:"column:verifyFlag;default:0" json:"verifyFlag"`
EncryptUsername string `gorm:"column:encryptUsername" json:"encryptUsername"`
ChatroomFlag int `gorm:"column:chatroomFlag" json:"chatroomFlag"`
DeleteFlag int `gorm:"column:deleteFlag;default:0" json:"deleteFlag"`
ContactLabelIds string `gorm:"column:contactLabelIds" json:"contactLabelIds"`
DescWordingId string `gorm:"column:descWordingId" json:"descWordingId"`
OpenImAppid string `gorm:"column:openImAppid" json:"openImAppid"`
SourceExtInfo string `gorm:"column:sourceExtInfo" json:"sourceExtInfo"`
Ticket string `gorm:"column:ticket" json:"ticket"`
UsernameFlag int `gorm:"column:usernameFlag;default:0" json:"usernameFlag"`
}

func (Rcontact) TableName() string {
return "rcontact"
}

type ChatListResult struct {
MsgCount int64 `gorm:"column:msgCount"`
Alias string `gorm:"column:alias"`
Talker string `gorm:"column:talker"`
NickName string `gorm:"column:nickname"`
ConRemark string `gorm:"column:conRemark"`
Reserved1 string `gorm:"column:reserved1"`
Reserved2 string `gorm:"column:reserved2"`
CreateTime int64 `gorm:"column:createTime"`
}

func GetChatList() (list []ChatListResult, err error) {
db, err := gorm.Open(sqlite.Open("/home/zheng/coding/wechatbak/dest/79b23ef49a3016d8c52a787fc4ab59e4/EnMicroMsg_plain.db"), &gorm.Config{})
if err != nil {
return nil, err
}

db.Table("message msg").
Select("count(*) as msgCount,rc.alias,msg.talker,rc.nickname,rc.conRemark,imf.reserved1,imf.reserved2,msg.createTime").
Joins("left join rcontact rc on msg.talker=rc.username").
Joins("left join img_flag imf on msg.talker=imf.username").
Group("msg.talker").
Order("msg.createTime desc").
Limit(5).Scan(&list)

return
}
13 changes: 13 additions & 0 deletions db/message_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package db

import (
"encoding/json"
"testing"
)

func TestQuery(t *testing.T) {
res, _ := GetChatList()

str, _ := json.Marshal(res)
t.Log(string(str))
}
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ go 1.17

require (
github.com/gin-gonic/gin v1.8.2
github.com/mattn/go-sqlite3 v1.14.13
golang.org/x/sync v0.1.0
github.com/mattn/go-sqlite3 v1.14.15
gorm.io/driver/sqlite v1.4.4
gorm.io/gorm v1.24.4
)

require (
Expand All @@ -14,6 +15,8 @@ require (
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.11.2 // indirect
github.com/goccy/go-json v0.10.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
Expand Down
16 changes: 12 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
Expand All @@ -40,8 +45,8 @@ github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ic
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-sqlite3 v1.14.13 h1:1tj15ngiFfcZzii7yd82foL+ks+ouQcj8j/TPq3fk1I=
github.com/mattn/go-sqlite3 v1.14.13/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/mattn/go-sqlite3 v1.14.15 h1:vfoHhTN1af61xCRSWzFIWzx2YskyMTwHLrExkBOjvxI=
github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand Down Expand Up @@ -86,8 +91,6 @@ golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw=
golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down Expand Up @@ -131,3 +134,8 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/sqlite v1.4.4 h1:gIufGoR0dQzjkyqDyYSCvsYR6fba1Gw5YKDqKeChxFc=
gorm.io/driver/sqlite v1.4.4/go.mod h1:0Aq3iPO+v9ZKbcdiz8gLWRw5VOPcBOPUQJFLq5e2ecI=
gorm.io/gorm v1.24.0/go.mod h1:DVrVomtaYTbqs7gB/x2uVvqnXzv0nqjB396B8cG4dBA=
gorm.io/gorm v1.24.4 h1:Z6E28cuEnBw4/lcglUTM3XF6fkKQEbNyccdI00yiwGw=
gorm.io/gorm v1.24.4/go.mod h1:DVrVomtaYTbqs7gB/x2uVvqnXzv0nqjB396B8cG4dBA=