convert raw sql to orm