refactor code

change sql flow
use json as config file format