May 2019
Beginner to intermediate
466 pages
10h 44m
English
We said that when an article is fetched and parsed, we want to store its data in the database. Thus, before fetching an article, we'll first want to check our database. If the article was previously persisted, we'll retrieve it. If not, we'll perform the original fetch-and-parse workflow. We use the url property to uniquely identify articles.
Let's start by adding the Articles.save(a::Article) method for persisting an article object:
function save(a::Article) sql = "INSERT IGNORE INTO articles (title, content, links, image, url) VALUES (?, ?, ?, ?, ?)" stmt = MySQL.Stmt(CONN, sql) result = MySQL.execute!(stmt, [a.title, a.content, JSON.json(a.links), a.image, a.url]) end
Here, we use MySQL.Stmt ...
Read now
Unlock full access