Add db code

Connect the parts to make the routing request to db work. The code
needs to be cleaned later.