mirror of
https://github.com/miniflux/v2.git
synced 2025-08-06 17:41:00 +00:00
Improve storage module
This commit is contained in:
parent
e38333e272
commit
d3883126bf
13 changed files with 505 additions and 317 deletions
|
@ -12,14 +12,24 @@ import (
|
|||
|
||||
// GetEnclosures returns all attachments for the given entry.
|
||||
func (s *Storage) GetEnclosures(entryID int64) (model.EnclosureList, error) {
|
||||
query := `SELECT
|
||||
id, user_id, entry_id, url, size, mime_type
|
||||
FROM enclosures
|
||||
WHERE entry_id = $1 ORDER BY id ASC`
|
||||
query := `
|
||||
SELECT
|
||||
id,
|
||||
user_id,
|
||||
entry_id,
|
||||
url,
|
||||
size,
|
||||
mime_type
|
||||
FROM
|
||||
enclosures
|
||||
WHERE
|
||||
entry_id = $1
|
||||
ORDER BY id ASC
|
||||
`
|
||||
|
||||
rows, err := s.db.Query(query, entryID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to get enclosures: %v", err)
|
||||
return nil, fmt.Errorf(`store: unable to fetch enclosures: %v`, err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
|
@ -36,7 +46,7 @@ func (s *Storage) GetEnclosures(entryID int64) (model.EnclosureList, error) {
|
|||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to fetch enclosure row: %v", err)
|
||||
return nil, fmt.Errorf(`store: unable to fetch enclosure row: %v`, err)
|
||||
}
|
||||
|
||||
enclosures = append(enclosures, &enclosure)
|
||||
|
@ -49,10 +59,11 @@ func (s *Storage) GetEnclosures(entryID int64) (model.EnclosureList, error) {
|
|||
func (s *Storage) CreateEnclosure(enclosure *model.Enclosure) error {
|
||||
query := `
|
||||
INSERT INTO enclosures
|
||||
(url, size, mime_type, entry_id, user_id)
|
||||
(url, size, mime_type, entry_id, user_id)
|
||||
VALUES
|
||||
($1, $2, $3, $4, $5)
|
||||
RETURNING id
|
||||
($1, $2, $3, $4, $5)
|
||||
RETURNING
|
||||
id
|
||||
`
|
||||
err := s.db.QueryRow(
|
||||
query,
|
||||
|
@ -64,7 +75,7 @@ func (s *Storage) CreateEnclosure(enclosure *model.Enclosure) error {
|
|||
).Scan(&enclosure.ID)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to create enclosure %q: %v", enclosure.URL, err)
|
||||
return fmt.Errorf(`store: unable to create enclosure %q: %v`, enclosure.URL, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue