activity.go 664 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package store
  2. import (
  3. "context"
  4. )
  5. type Activity struct {
  6. ID int32
  7. // Standard fields
  8. CreatorID int32
  9. CreatedTs int64
  10. // Domain specific fields
  11. Type string
  12. Level string
  13. Payload string
  14. }
  15. func (s *Store) CreateActivity(ctx context.Context, create *Activity) (*Activity, error) {
  16. stmt := `
  17. INSERT INTO activity (
  18. creator_id,
  19. type,
  20. level,
  21. payload
  22. )
  23. VALUES (?, ?, ?, ?)
  24. RETURNING id, created_ts
  25. `
  26. if err := s.db.QueryRowContext(ctx, stmt, create.CreatorID, create.Type, create.Level, create.Payload).Scan(
  27. &create.ID,
  28. &create.CreatedTs,
  29. ); err != nil {
  30. return nil, err
  31. }
  32. activity := create
  33. return activity, nil
  34. }