Database api refactor