adding comment to document repository

This commit is contained in:
2025-01-20 21:43:20 +01:00
parent 2f0a17763d
commit d6cf444def

View File

@@ -74,6 +74,9 @@ func (d *DocumentRepository) CountAll() (uint, error) {
return count, nil return count, nil
} }
// Update an document in the database. Will use the id that is set in the
// document object as an reference to the database row. This may throw an error
// if the connection to database fails.
func (m *DocumentRepository) Update(d *model.Document) error { func (m *DocumentRepository) Update(d *model.Document) error {
stmt := `UPDATE documents stmt := `UPDATE documents
SET content = $1, summary = $2 SET content = $1, summary = $2
@@ -83,6 +86,10 @@ func (m *DocumentRepository) Update(d *model.Document) error {
return err return err
} }
// Will transform every document in the database given a transformation
// function. Will load the document, parse it to the transform function and call
// update on the returned document. May throw an error if the connection to the
// database fails.
func (d *DocumentRepository) Map(transform func(*model.Document) *model.Document) (int, error) { func (d *DocumentRepository) Map(transform func(*model.Document) *model.Document) (int, error) {
processed := 0 processed := 0
@@ -100,7 +107,9 @@ func (d *DocumentRepository) Map(transform func(*model.Document) *model.Document
for _, doc := range docs { for _, doc := range docs {
new_doc := transform(doc) new_doc := transform(doc)
err = d.Update(new_doc) err = d.Update(new_doc)
if err != nil { return processed, err } if err != nil {
return processed, err
}
processed++ processed++
} }
} }