moved the last sql function to db abstraction