31 lines
738 B
Go
31 lines
738 B
Go
package store
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/jackc/pgx/v5"
|
|
)
|
|
|
|
func (s *Store) IsMigrated(ctx context.Context, accountID int64, key string) (bool, error) {
|
|
var one int
|
|
err := s.Pool.QueryRow(ctx,
|
|
`SELECT 1 FROM migrated_messages WHERE account_id=$1 AND message_key=$2`,
|
|
accountID, key).Scan(&one)
|
|
if errors.Is(err, pgx.ErrNoRows) {
|
|
return false, nil
|
|
}
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
return true, nil
|
|
}
|
|
|
|
func (s *Store) MarkMigrated(ctx context.Context, accountID int64, folder, key string) error {
|
|
_, err := s.Pool.Exec(ctx,
|
|
`INSERT INTO migrated_messages (account_id, folder, message_key)
|
|
VALUES ($1,$2,$3) ON CONFLICT (account_id, message_key) DO NOTHING`,
|
|
accountID, folder, key)
|
|
return err
|
|
}
|