implement some db functions