refactor mysql query methods
Merge branch 'db-write'