use pointers for optional update fields to distinguish empty from unset

This commit is contained in:
2026-03-27 02:41:27 +01:00
parent 81fb9af5e2
commit 74cc7c104a
3 changed files with 19 additions and 11 deletions

View File

@@ -41,7 +41,7 @@ type CreateParams struct {
Rels map[models.RelType][]string
}
type UpdateParams struct {
Title, Content, DueDate string
Title, Content, DueDate *string
ClearDue bool
AddTags, RemoveTags []string
AddRels, RemoveRels map[models.RelType][]string
@@ -97,19 +97,18 @@ func (db *DB) UpdateNode(id string, p UpdateParams) error {
_, err := tx.Exec("UPDATE nodes SET "+col+" = ? WHERE id = ?", val, id)
return err
}
//TODO: does it make sense to check for emtpy sting? should it be possible to set the content to ""?
if p.Title != "" {
if err := upd("title", p.Title); err != nil {
if p.Title != nil {
if err := upd("title", *p.Title); err != nil {
return err
}
}
if p.Content != "" {
if err := upd("content", p.Content); err != nil {
if p.Content != nil {
if err := upd("content", *p.Content); err != nil {
return err
}
}
if p.DueDate != "" {
if err := upd("due_date", p.DueDate); err != nil {
if p.DueDate != nil {
if err := upd("due_date", *p.DueDate); err != nil {
return err
}
}
@@ -143,7 +142,6 @@ func (db *DB) UpdateNode(id string, p UpdateParams) error {
}
func (db *DB) DeleteNode(id string) error {
//TODO: check if this delete propagates?
_, err := db.Exec("DELETE FROM nodes WHERE id = ?", id)
return err
}