moving SQL into application code

Ultimately move to Haskell