Amber sql

Hi Alex and Shuang,

I've done everything i don't like with this pull request: 

   It's huge 
   It contains commented code (sql mostly). 

It's mostly to get it onto master so subsequent pull requests can be more orderly. I promise to clean it up