move db connection inside query functions