Add support for saving metadata on queries.

I've started truncating and moving things to fixed plan of 4 space indents. I think I should do this as a separate pull request.