Exercise: Customize Your Repo Module
Practice how to add custom behavior to your Repo in this challenge.
We'll cover the following
Problem statement
We’d like to have an easy way to get the newest record in each of our database tables. The tables in our sample database all have an inserted_at
column that contains a timestamp of when the records are inserted. We’d like to make it easy to get the newest timestamp of any given table.
Coding challenge
Write a function called newest
for the Repo
module that takes a table name as an argument and returns the :inserted_at
value for the most recently-added record of the table.
Get hands-on with 1400+ tech skills courses.