Setting up our Article module
The next step is to add a few more functions to the Article module to enable database persistence and retrieval functionality. Since it will need access to our DB connection object, let's give it access to the Database module. We'll also want to use MySQL functions. So, under the export Article line, add using..Database, MySQL.
Next, we'll add a createtable method. This will be a one-off function that will create the corresponding database table. We use this instead of just typing CREATE TABLE queries in the MySQL client, in order to have a consistent and reproducible way of (re)creating the table. In general, I prefer the use of a fully fledged database migration library, but for now, better to keep things simple ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access