move some SQL to the ::DB module