Wired up simple SQLite queries for app

Can optimize some parts with joins and aggregation, but the ORM I'm using is quite basic so I'll KISS for now (n+1 shouldn't be too big an issue given it's localised to a mobile device)