fix: max id issues
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"exporter/database/telegram_resource/public/model"
|
||||
"exporter/database/telegram_resource/public/table"
|
||||
|
||||
. "github.com/go-jet/jet/v2/postgres"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
@@ -77,3 +78,38 @@ func Test_Join(t *testing.T) {
|
||||
|
||||
t.Logf("%+v", msg)
|
||||
}
|
||||
|
||||
func Test_ExceptMax(t *testing.T) {
|
||||
dsn := "postgresql://postgres:xixi0202@10.1.1.3:5432/telegram_resource?sslmode=disable"
|
||||
if err := InitDB(dsn); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
tbl := table.ChannelMessages
|
||||
tblC := table.Channels
|
||||
|
||||
var result struct {
|
||||
MaxID int64
|
||||
}
|
||||
stmt := tbl.SELECT(MAX(tbl.ID).AS("maxID")).FROM(tbl)
|
||||
t.Log(stmt.DebugSql())
|
||||
|
||||
if err := stmt.QueryContext(context.Background(), db, &result); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
t.Log(result)
|
||||
|
||||
stmt = tbl.SELECT(tbl.AllColumns, tblC.Title).
|
||||
WHERE(tbl.Published.IS_FALSE().AND(tbl.ID.NOT_EQ(Int(result.MaxID)))).
|
||||
LIMIT(1).
|
||||
ORDER_BY(tbl.ID.DESC()).
|
||||
FROM(tbl.LEFT_JOIN(tblC, tbl.ChannelID.EQ(tblC.UUID)))
|
||||
t.Log(stmt.DebugSql())
|
||||
|
||||
var msg publishMsg
|
||||
if err := stmt.QueryContext(context.Background(), db, &msg); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
t.Log(msg.ChannelMessages.ID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user