Fix some db minors and add api interface