index.js
function DbEntity(table, entity, opts, pool, logger){
  LOGGER = logger;
  this.pool = pool;
  this.table = table;
  this.entity = entity;

  if(_.isNil(opts)||_.isNil(opts.plural)){
    if(_.endsWith(entity,'y')){
      this.plural = entity.substr(0, entity.lastIndexOf('y')) + 'ies';
    } else if (_.endsWith(entity,'s')) {
      this.plural = entity.substr(0, entity.lastIndexOf('s')) + 'es';
    } else {
      this.plural = entity + 's';
    }
  } else {
    this.plural = opts.plural;
  }

  this.options = (opts || {
    created_timestamp_column: 'created',
    updated_timestamp_column: 'updated',
    version_number_column: 'version',
    log_category: 'db'
  });

  if(logger && LOGGER.info){
    LOGGER = logger;
  } else {
    //use winston
    LOGGER = {error: console.log, warn: console.log, info: function(){}, debug: function(){}, silly: function(){} }
  }

  this.metadata = null;//initialized to empty.
}
function DbEntity(table, entity, opts, pool, logger){
  LOGGER = logger;
  this.pool = pool;
  this.table = table;
  this.entity = entity;

  if(_.isNil(opts)||_.isNil(opts.plural)){
    if(_.endsWith(entity,'y')){
      this.plural = entity.substr(0, entity.lastIndexOf('y')) + 'ies';
    } else if (_.endsWith(entity,'s')) {
      this.plural = entity.substr(0, entity.lastIndexOf('s')) + 'es';
    } else {
      this.plural = entity + 's';
    }
  } else {
    this.plural = opts.plural;
  }

  this.options = (opts || {
    created_timestamp_column: 'created',
    updated_timestamp_column: 'updated',
    version_number_column: 'version',
    log_category: 'db'
  });

  if(logger && LOGGER.info){
    LOGGER = logger;
  } else {
    //use winston
    LOGGER = {error: console.log, warn: console.log, info: function(){}, debug: function(){}, silly: function(){} }
  }

  this.metadata = null;//initialized to empty.
}
function DbEntity ( table , entity , opts , pool , logger ) { LOGGER = logger ; this . pool = pool ; this . table = table ; this . entity = entity ; if ( _ . isNil ( opts ) || _ . isNil ( opts . plural ) ) { if ( _ . endsWith ( entity , 'y' ) ) { this . plural = entity . substr ( 0 , entity . lastIndexOf ( 'y' ) ) + 'ies' ; } else if ( _ . endsWith ( entity , 's' ) ) { this . plural = entity . substr ( 0 , entity . lastIndexOf ( 's' ) ) + 'es' ; } else { this . plural = entity + 's' ; } } else { this . plural = opts . plural ; } this . options = ( opts || { created_timestamp_column : 'created' , updated_timestamp_column : 'updated' , version_number_column : 'version' , log_category : 'db' } ) ; if ( logger && LOGGER . info ) { LOGGER = logger ; } else { //use winston LOGGER = { error : console . log , warn : console . log , info : function ( ) { } , debug : function ( ) { } , silly : function ( ) { } } } this . metadata = null ; //initialized to empty. }
Class to provide basic SQL persistence operations.
@version 2.2.0
@param {string} table required db table name
@param {string} entity required logical entity name (singular form)
@param {object} opts optional options settings to override defaults, shown below
@example <caption>Default options</caption>
{
plural: 'string (derived from English plural rules)',
created_timestamp_column: 'created',
updated_timestamp_column: 'updated',
version_number_column: 'version',
log_category: 'db'
}
@param {object} pool required mysql db pool reference.
@param {object} logger optional logger instance.
@return an object to be used for model persistence.
@example <caption>Note, internal metadata is stored in the the form</caption>
[{
column: 'column name',
sql_type: 'string'
is_pk: true|false whether a primary key column,
is_autoincrement: true|false whether it is an autoincrement id
is_created_timestamp: true|false,
is_updated_timestamp: true|false,
is_version: true|false
}]
Class to provide basic SQL persistence operations .