2021-08-16 20:37:35 -07:00
|
|
|
package persistence
|
|
|
|
|
|
|
|
import (
|
2022-03-13 16:13:16 -07:00
|
|
|
"fmt"
|
|
|
|
|
2025-02-03 16:25:34 -08:00
|
|
|
. "gitlab.com/offline-twitter/twitter_offline_engine/pkg/scraper"
|
2021-08-16 20:37:35 -07:00
|
|
|
)
|
|
|
|
|
2023-08-03 00:46:10 -03:00
|
|
|
// Save a Retweet. Do nothing if it already exists, because none of its parameters are modifiable.
|
2025-02-03 16:25:34 -08:00
|
|
|
func (p Profile) SaveRetweet(r Retweet) error {
|
2023-06-27 21:56:29 -03:00
|
|
|
_, err := p.DB.NamedExec(`
|
2021-08-16 20:37:35 -07:00
|
|
|
insert into retweets (retweet_id, tweet_id, retweeted_by, retweeted_at)
|
2023-06-27 21:56:29 -03:00
|
|
|
values (:retweet_id, :tweet_id, :retweeted_by, :retweeted_at)
|
2021-08-16 20:37:35 -07:00
|
|
|
on conflict do nothing
|
|
|
|
`,
|
2023-06-27 21:56:29 -03:00
|
|
|
r,
|
2021-08-16 20:37:35 -07:00
|
|
|
)
|
2022-03-13 16:13:16 -07:00
|
|
|
if err != nil {
|
2022-11-25 15:51:21 -05:00
|
|
|
return fmt.Errorf("Error executing SaveRetweet(%#v):\n %w", r, err)
|
2022-03-13 16:13:16 -07:00
|
|
|
}
|
|
|
|
return nil
|
2021-08-16 20:37:35 -07:00
|
|
|
}
|
|
|
|
|
2023-08-03 00:46:10 -03:00
|
|
|
// Retrieve a Retweet by ID
|
2025-02-03 16:25:34 -08:00
|
|
|
func (p Profile) GetRetweetById(id TweetID) (Retweet, error) {
|
|
|
|
var r Retweet
|
2022-03-06 19:17:43 -08:00
|
|
|
err := p.DB.Get(&r, `
|
2021-08-16 20:37:35 -07:00
|
|
|
select retweet_id, tweet_id, retweeted_by, retweeted_at
|
|
|
|
from retweets
|
|
|
|
where retweet_id = ?
|
2022-03-06 19:17:43 -08:00
|
|
|
`, id)
|
2022-03-13 16:13:16 -07:00
|
|
|
if err != nil {
|
|
|
|
return r, fmt.Errorf("Error executing GetRetweetById(%d):\n %w", id, err)
|
|
|
|
}
|
|
|
|
return r, nil
|
2021-08-16 20:37:35 -07:00
|
|
|
}
|