Add ToSql helper

Move string format code to an extension method.
Save viewer counts to database

Save viewer counts to database instead of file.