Return true only when item added
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Peter Stuifzand 2021-05-13 22:51:36 +02:00
parent 9d81cc9a3a
commit 76edad3e8d
Signed by: peter
GPG Key ID: 374322D56E5209E8

View File

@ -204,7 +204,7 @@ func (p *postgresStream) AddItem(item microsub.Item) (bool, error) {
t = t2
}
_, err = conn.ExecContext(context.Background(), `
result, err := conn.ExecContext(context.Background(), `
INSERT INTO "items" ("channel_id", "uid", "data", "published_at", "created_at")
VALUES ($1, $2, $3, $4, DEFAULT)
ON CONFLICT ON CONSTRAINT "items_uid_key" DO UPDATE SET "updated_at" = now()
@ -212,7 +212,13 @@ ON CONFLICT ON CONSTRAINT "items_uid_key" DO UPDATE SET "updated_at" = now()
if err != nil {
return false, fmt.Errorf("while adding item: %w", err)
}
return true, nil
c, err := result.RowsAffected()
if err != nil {
return false, err
}
log.Printf("AddItem: rows affected %d\n", c)
return c > 0, nil
}
// MarkRead