 
 # Runs the queries against MySQL
 runMysqlQueries = (config, queries) ->
+  # Extract only those fields which are of interest to MySQL
   myCfg =
     host: config.host
     port: config.port

runScript = ->
  program
    .usage('[options] <query_file>')
    .option '-s, --scheme <scheme>', 'scheme for the connection can be "postgres" or "mysql" (default is postgres)'
    .option '-D, --database <database>', 'database (default is postgres)'
    .option '-h, --host <host>', "the Postgres server'shostname (default is localhost)"
    .option '-p, --port <port>', "the Postgres server's port (default is 5432)", parseInt
    .option '-P, --password <password>', 'user password (default is empty)'
    .option '-q, --quiet', 'Silence non-error output (default is false)'
    .option '-u, --username <username>', 'user name (default is postgres)'
    .parse(process.argv)

  queriesFile = _(program.args).first()

  config =
    scheme: program.scheme ? 'postgres'
    host: program.host ? 'localhost'
    port: program.port ? 5432
    user: program.username ? 'postgres'
    password: program.password ? 'postgres'
    database: program.database ? 'postgres'
    quiet: program.quiet ? false
  
  readQueriesFile queriesFile
  .then (queries) ->
    runQueries config, queries
  .catch (error) ->
    console.log "Error reading queries from file '#{queriesFile}' : #{error}\nStack:\n#{error.stack}"



# Runs the queries against PostgreSQL
runPgQueries = (config, queries) ->
  {user, password, host, port, database}
  uri = "postgres://#{user}:#{password}@#{host}:#{port}/#{database}"
  console.log "Connecting to URI '#{uri}'"

  pgConnect uri, config
