lib/qpm_media.js
function addMeta(params, config, conn) {

  params = params || {}

  // validate
  if (!params.uri || params.uri === '') {
    return 'You must enter a valid uri'
  }

  // defaults
  config = config || require('../config/config.js')

  debug(params)

  // main
  // main
  return new Promise((resolve, reject) => {

    if (!conn) {
      var conn = wc_db.getConnection(config.db)
    }

    if (!params.subtitlesURI) {
      params.subtitlesURI = null
    }

    if (!params.charenc) {
      params.charenc = null
    }

    var sql = 'INSERT into Meta select a.id, :length, :subtitlesURI, :charenc from Media a where a.uri = :uri ;'
    debug('addMeta', sql, params)

    conn.query(sql, { replacements: { "length" : params.length, "subtitlesURI": params.subtitlesURI, "uri" : params.uri, "charenc" : params.charenc } }).then(function(ret){
      return resolve({"ret" : ret, "conn" : conn})
    }).catch(function(err) {
      return reject({"err" : err, "conn" : conn})
    })

  })

}
function addMeta(params, config, conn) {

  params = params || {}

  // validate
  if (!params.uri || params.uri === '') {
    return 'You must enter a valid uri'
  }

  // defaults
  config = config || require('../config/config.js')

  debug(params)

  // main
  // main
  return new Promise((resolve, reject) => {

    if (!conn) {
      var conn = wc_db.getConnection(config.db)
    }

    if (!params.subtitlesURI) {
      params.subtitlesURI = null
    }

    if (!params.charenc) {
      params.charenc = null
    }

    var sql = 'INSERT into Meta select a.id, :length, :subtitlesURI, :charenc from Media a where a.uri = :uri ;'
    debug('addMeta', sql, params)

    conn.query(sql, { replacements: { "length" : params.length, "subtitlesURI": params.subtitlesURI, "uri" : params.uri, "charenc" : params.charenc } }).then(function(ret){
      return resolve({"ret" : ret, "conn" : conn})
    }).catch(function(err) {
      return reject({"err" : err, "conn" : conn})
    })

  })

}
function addMeta ( params , config , conn ) { params = params || { } // validate if ( ! params . uri || params . uri === '' ) { return 'You must enter a valid uri' } // defaults config = config || require ( '../config/config.js' ) debug ( params ) // main // main return new Promise ( ( resolve , reject ) => { if ( ! conn ) { var conn = wc_db . getConnection ( config . db ) } if ( ! params . subtitlesURI ) { params . subtitlesURI = null } if ( ! params . charenc ) { params . charenc = null } var sql = 'INSERT into Meta select a.id, :length, :subtitlesURI, :charenc from Media a where a.uri = :uri ;' debug ( 'addMeta' , sql , params ) conn . query ( sql , { replacements : { "length" : params . length , "subtitlesURI" : params . subtitlesURI , "uri" : params . uri , "charenc" : params . charenc } } ) . then ( function ( ret ) { return resolve ( { "ret" : ret , "conn" : conn } ) } ) . catch ( function ( err ) { return reject ( { "err" : err , "conn" : conn } ) } ) } ) }
Adds a meta record to the database
@param {Object} params  The meta info.
@param {Object} config  The optional config.
@param {Object} conn    The optional db connection.
@return {Object} Promise with success or fail.
Adds a meta record to the database