Removed raw SQL queries

 * added `count` property in TagRecord,
 * using SQLAlchemy Query instead of raw SQL in views.