Create your database tables
Let’s start by creating the Data Tables to store your news articles.
Step 1: Create an app
Log in to Anvil and click ‘New Blank App’. Choose the Material Design theme.
First, name the app. Click on the name at the top of the screen and give it a name.
Step 2: Add the Data Tables service
We’ll use Data Tables to store our news articles. Data Tables are an out-of-the-box option for data storage in Anvil, and they’re backed by PostgreSQL.
Step 3: Create an 'articles' table
Now set up your ‘articles’ table, with the following columns:
created(Date and Time column)
updated(Date and Time column)
Here’s how to do that:
Click ‘Add a table’ in the light blue box at the top, then ‘Create new table…’. You’ll be prompted to give your table a name - let’s call it ‘articles’.
Next, add a column for the article title, by clicking ‘+ New Column’ and choosing ‘Add text column…’. Call this column ‘title’.
Keep adding columns until your Data Table has the structure we described above. Column titles are case sensitive, so let’s stick to lower case.
Your Data Table should look something like this:
Step 4: Create a Categories table
We’re also going to put each article into a ‘category’. These categories are fixed, so we’ll create a second table called ‘categories’ to store the categories, and link the ‘articles’ table to the categories table.
Create your ‘categories’ table, with a single column:
Add these categories to the table:
Finally, create a column in your ‘Articles’ table to store a category for each news article. Click the ‘+’ to add a new column, then follow ‘Link to table…’, ‘categories’, and select ‘Single Row’. Call this ‘category’. This creates a link to the ‘categories’ table you just created.
Your Data Tables are set up and ready to use. Nice work!
In Chapter 2, we’ll build a User Interface to display the articles.