move SQL stuff to its own module