teach mig-export to use a sql query function instead of implementing the same lines...