Are you sure the db object is actually not null/undefined? Try using another function instead of transaction and see if it shows you the same error or, alternatively, try doing a console.log() of the db.