Fit with the latest changes to gorm
Move most of the sql stuff into its own files, like gorm does.

Exception: I judged funlist.py to be harder to understand without the inline sql so I left it there.