gorm outbox

This commit is contained in:
merdan 2024-08-30 11:46:15 +05:00
parent f6471f9e67
commit fe3766e38f
2 changed files with 10 additions and 2 deletions

4
go.mod
View File

@ -3,15 +3,15 @@ module smpp-transmitter
go 1.23rc1
require (
github.com/joho/godotenv v1.5.1
github.com/streadway/amqp v1.1.0
gorm.io/driver/mysql v1.5.7
gorm.io/gorm v1.25.11
)
require (
github.com/go-sql-driver/mysql v1.7.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/joho/godotenv v1.5.1
golang.org/x/text v0.14.0 // indirect
gorm.io/gorm v1.25.11 // indirect
)

View File

@ -3,14 +3,17 @@ package data
import (
"context"
"encoding/json"
"time"
"gorm.io/gorm"
)
type Message struct {
ID uint `gorm:"primarykey"`
Src string `json:"src"`
Dst string `json:"dst"`
Msg string `json:"msg"`
Ts int `json:"ts"`
}
func (m *Message) Convert(msgBody []byte) error {
@ -21,8 +24,13 @@ func (m *Message) Convert(msgBody []byte) error {
}
func (m *Message) Insert(ctx context.Context, db *gorm.DB) error {
m.Ts = int(time.Now().Unix())
if err := db.WithContext(ctx).Create(&m).Error; err != nil {
return err
}
return nil
}
func (m *Message) TableName() string {
return "outbox"
}