Data Base Calls Inside The Widget View?

I need to create a widget which gets data from the DB,

I found below tutorial, but I can see it has DB calls from the view . Is this good practice?

Widget is for only presentation layer… dont write your database access there :)

Pleas refer this link