feat: add vote_flashcard MCP tool

This commit is contained in:
didier committed 2026-06-05 17:04:05 -04:00
1 parent cd8e872491
commit a40542f7b4
4 files changed
+143

No files matched your search

+32
View File
@@ -43,6 +43,11 @@ func newSqliteStore(path string) (*sqliteStore, error) {
return nil, fmt.Errorf("sqlite ping: %w", err)
}
if _, err := db.Exec("PRAGMA foreign_keys = ON"); err != nil {
db.Close()
return nil, fmt.Errorf("enable foreign keys: %w", err)
}
goose.SetBaseFS(embedMigrations)
if err := goose.SetDialect("sqlite3"); err != nil {
@@ -233,6 +238,33 @@ func (s *sqliteStore) getByPublicIDAndVersion(ctx context.Context, publicID int6
return &e, nil
}
func (s *sqliteStore) saveVote(ctx context.Context, flashcardID int64, value int, user, repo, message string) (*vote, error) {
_, err := s.db.ExecContext(ctx,
`INSERT INTO vote (flashcard_id, value, "user", repo, message)
VALUES (?, ?, ?, ?, ?)
ON CONFLICT(flashcard_id, "user", repo)
DO UPDATE SET value = excluded.value, message = excluded.message`,
flashcardID, value, user, repo, message,
)
if err != nil {
return nil, fmt.Errorf("upsert vote: %w", err)
}
row := s.db.QueryRowContext(ctx,
`SELECT _id, flashcard_id, value, "user", repo, message, created
FROM vote WHERE flashcard_id = ? AND "user" = ? AND repo = ?`,
flashcardID, user, repo,
)
var v vote
err = row.Scan(&v.ID, &v.FlashcardID, &v.Value, &v.User, &v.Repo, &v.Message, &v.Created)
if err != nil {
return nil, fmt.Errorf("read vote: %w", err)
}
return &v, nil
}
func (s *sqliteStore) tombstone(ctx context.Context, publicID int64, version int) (int64, error) {
result, err := s.db.ExecContext(ctx,
`INSERT INTO flashcard (public_id, version, note, delete_timestamp)