Add function helpers

This facilitates writing SQL functions. This fixes #20. We should merge #19 first.