reorganize middleware, support sqlite, mysql, postgres, only sqlite tested so far