@@ -16,6 +16,7 @@ package coredata
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"time"
|
||||
@@ -41,8 +42,24 @@ type (
|
||||
}
|
||||
|
||||
Documents []*Document
|
||||
|
||||
ErrDocumentNotFound struct {
|
||||
Identifier string
|
||||
}
|
||||
|
||||
ErrDocumentAlreadyExists struct {
|
||||
message string
|
||||
}
|
||||
)
|
||||
|
||||
func (e ErrDocumentNotFound) Error() string {
|
||||
return fmt.Sprintf("document not found: %q", e.Identifier)
|
||||
}
|
||||
|
||||
func (e ErrDocumentAlreadyExists) Error() string {
|
||||
return e.message
|
||||
}
|
||||
|
||||
func (p Document) CursorKey(orderBy DocumentOrderField) page.CursorKey {
|
||||
switch orderBy {
|
||||
case DocumentOrderFieldCreatedAt:
|
||||
@@ -95,6 +112,10 @@ LIMIT 1;
|
||||
|
||||
document, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[Document])
|
||||
if err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return &ErrDocumentNotFound{Identifier: documentID.String()}
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect document: %w", err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user