move collection and extraction of articles into their own file; add custom response cache
This commit is contained in:
@@ -85,3 +85,25 @@ func (m *ArticleModel) Insert(a *model.Article) error {
|
||||
_, err = m.DB.Exec(stmt, lastId, a.Title, a.Author, a.Content)
|
||||
return err
|
||||
}
|
||||
|
||||
// TODO docstring
|
||||
func (m *ArticleModel) Update(a *model.Article) error {
|
||||
// begin transaction
|
||||
_, err := m.DB.Begin()
|
||||
if err != nil { return err }
|
||||
|
||||
// insert article
|
||||
stmt := `UPDATE articles
|
||||
SET title = ?, sourceUrl = ?, author = ?, content = ?, publishDate = ?, fetchDate = ?
|
||||
WHERE id = ?
|
||||
`
|
||||
_, err = m.DB.Exec(stmt, a.Title, a.SourceUrl, a.Author, a.Content, a.PublishDate, a.FetchDate, a.Identifier)
|
||||
if err != nil { return err }
|
||||
|
||||
// insert into fts_articles for full-text search
|
||||
stmt = `INSERT INTO fts_articles (id, content)
|
||||
VALUES (?, ? || '\n' || ? || '\n' || ?)
|
||||
`
|
||||
_, err = m.DB.Exec(stmt, a.Identifier, a.Title, a.Author, a.Content)
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user