code: function getTaggedFragment(params, config, conn) {
  
    if (!params.q && !params.tag) {
      return 'You must enter a valid query or tag'
    }
  
    // defaults
    config = config || require('../config/config.js')
  
    // main
    return new Promise((resolve, reject) => {
  
      if (!conn) {
        var conn = wc_db.getConnection(config.db)
      }
  
      var safeClause = ''
      if (params.safe !== undefined && params.safe !== null) {
        if (parseInt(params.safe) === 0) {
          safeClause = ''
        } else {
          safeClause = ' and a.safe = :safe '
        }
      } else {
        safeClause = ' and a.safe = 1 '
      }
  
      var sql = "select a.uri, a.id, max(f.end) end, a.contentType, max(f.rating) mrat, m.subtitlesURI, m.charenc from Media a, Fragment f, Meta m, Tag t, MediaTag mt where a.id = f.id and m.id = a.id and t.tag = :tag and t.id = mt.tag_id and a.id = mt.media_id and contentType = 'video' and m.length > end " + safeClause + " group by f.id order by RAND() limit 1"
  
      conn.query(sql, { replacements: { "tag" : params.tag } }).then(function(ret){
        return resolve({"ret" : ret, "conn" : conn})
      }).catch(function(err) {
        return reject({"err" : err, "conn" : conn})
      })
  
    })
  
  }
docs: Get get a random rated fragment
  @param {Object} rating  The rating to add.
  @param {Object} config  The optional config.
  @param {Object} conn    The optional db connection.
  @return {Object} Promise with success or fail.