feat(persistence): note / tag repository
This commit is contained in:
parent
da4f5e2feb
commit
4708accc02
2 changed files with 28 additions and 1 deletions
|
|
@ -10,3 +10,19 @@ type noteRepository struct {
|
||||||
db *sql.DB
|
db *sql.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewNoteRepository(db *sql.DB) NoteRepository {
|
||||||
|
return ¬eRepository{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
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ package repositories
|
||||||
import "database/sql"
|
import "database/sql"
|
||||||
|
|
||||||
type TagRepository interface {
|
type TagRepository interface {
|
||||||
Upsert(title string, path string, slug string) error
|
Upsert(title string, path string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type tagRepository struct {
|
type tagRepository struct {
|
||||||
|
|
@ -15,3 +15,14 @@ func NewTagRepository(db *sql.DB) TagRepository {
|
||||||
return &tagRepository{db: db}
|
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
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue