Fix sqlalchemy query process, convert all query to sqlalchemy text