Documentation
¶
Index ¶
- Constants
- Variables
- func Connect(dsn string) (*bun.DB, error)
- func CreateMessage(ctx context.Context, db bun.IDB, message *Message) error
- func GetTotalSentMessagesCount(ctx context.Context, db bun.IDB) (int, error)
- func UpdateMessageStatus(ctx context.Context, db bun.IDB, messageID int64, status MessageStatus, ...) error
- type Message
- type MessageStatus
Constants ¶
View Source
const ( MessageStatusPending MessageStatus = "pending" MessageStatusSending MessageStatus = "sending" MessageStatusSent MessageStatus = "sent" MessageStatusFailed MessageStatus = "failed" MaxMessageLength int = 160 )
Variables ¶
View Source
var (
ErrMessageTooLong = errors.New("message content exceeds maximum length")
)
Functions ¶
func CreateMessage ¶
CreateMessage inserts a new message into the database
func GetTotalSentMessagesCount ¶
GetTotalSentMessagesCount returns the total count of sent messages
Types ¶
type Message ¶
type Message struct {
bun.BaseModel `bun:"table:messages"`
ID int64 `bun:"id,pk,autoincrement" json:"id"`
To string `bun:"to,notnull" json:"to"`
Content string `bun:"content,notnull" json:"content"`
Status MessageStatus `bun:"status,notnull,default:'pending'" json:"status"`
SentAt *time.Time `bun:"sent_at,nullzero" json:"sent_at,omitempty"`
MessageID *string `bun:"message_id,nullzero" json:"message_id,omitempty"`
WebhookResponse *string `bun:"webhook_response,type:jsonb,nullzero" json:"webhook_response,omitempty"`
CreatedAt time.Time `bun:"created_at,notnull,default:current_timestamp" json:"created_at"`
UpdatedAt time.Time `bun:"updated_at,notnull,default:current_timestamp" json:"updated_at"`
}
func ClaimNextMessage ¶
ClaimNextMessage atomically claims the next available message for processing
func GetMessageByID ¶
GetMessageByID retrieves a single message by its ID
type MessageStatus ¶
type MessageStatus string
Click to show internal directories.
Click to hide internal directories.