feat(persistence): note / tag repository

This commit is contained in:
Kristian Borgwarth 2026-03-24 21:36:17 +01:00
parent da4f5e2feb
commit 4708accc02
2 changed files with 28 additions and 1 deletions

View file

@ -10,3 +10,19 @@ type noteRepository struct {
db *sql.DB
}
func NewNoteRepository(db *sql.DB) NoteRepository {
return &noteRepository{db: db}
}
func (r *noteRepository) Upsert(title string, path string, slug string) error {
query := `
INSERT INTO notes (title, path, slug)
VALUES ($1, $2, $3)
ON CONFLICT (slug) DO UPDATE
SET title = EXCLUDED.title,
path = EXCLUDED.path;
`
_, err := r.db.Exec(query, title, path, slug)
return err
}

View file

@ -4,7 +4,7 @@ package repositories
import "database/sql"
type TagRepository interface {
Upsert(title string, path string, slug string) error
Upsert(title string, path string) error
}
type tagRepository struct {
@ -15,3 +15,14 @@ func NewTagRepository(db *sql.DB) TagRepository {
return &tagRepository{db: db}
}
func (r *tagRepository) Upsert(title string, path string) error {
query := `
INSERT INTO tags (title, path)
VALUES ($1, $2)
ON CONFLICT (slug) DO UPDATE
SET title = EXCLUDED.title,
path = EXCLUDED.path;
`
_, err := r.db.Exec(query, title, path)
return err
}