code: function search(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)
      }
  
      limit = params.limit || 1000
  
      if (params.q) {
        var sql = "SELECT * from Media m where uri like '%" + params.q + "%' order by rating desc LIMIT 1000"
      }
      if (params.tag) {
        var sql = 'SELECT uri from Media m left join MediaTag mt on m.id = mt.media_id left join Tag t on mt.tag_id = t.id  where t.tag = :tag order by t.tag LIMIT :limit '
      }
  
      conn.query(sql, { replacements: { "tag" : params.tag, "limit" : limit } }).then(function(ret){
        return resolve({"ret" : ret, "conn" : conn})
      }).catch(function(err) {
        return reject({"err" : err, "conn" : conn})
      })
  
    })
  
  }
docs: Search
  @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.