const queryBuilder = require('./QueryBuilder')
let parameters = require('./Parameters')
let _table = ''

/**
 * [setModel description]
 * @param {String} table [Database table for that schema]
 */
module.exports.setTable = function (table) {
  if (table === 'string') {
    _table = table
    return this
  } else {
    throw new Error('The table is not set!')
  }
}

/**
 * [Add new record on database]
 * @param  {Object} params [All columns with their values]
 */
module.exports.add = (params) => {
  if (_table === '') {
    throw new Error('The table is not set!')
  }
  if (typeof params !== 'object') {
    throw new Error('The params is need to be object with key column and value value of column!')
  }

  queryBuilder.makeQuery()
    .table(_table).add(Object.keys(params))

  parameters.prepare()
  parameters.params = Object.valueOf(params)
}

/**
 * [Make query for can take the first record from table]
 */
module.exports.getFirst = (columns = '*') => {
  if (_table === '') {
    throw new Error('The table is not set!')
  }
  if (!columns) {
    throw new Error('The columns is not set!')
  }
  queryBuilder.makeQuery()
    .from(_table)
    .select(columns)
    .take(1)
  parameters.prepare()
}

/**
 * [Make query for can take the last record from table]
 */
module.exports.getLast = (columns = '*') => {
  if (_table === '') {
    throw new Error('The table is not set!')
  }
  if (!columns) {
    throw new Error('The columns is not set!')
  }
  queryBuilder.makeQuery()
    .from(_table)
    .select(columns)
    .orderBy('id', true)
    .take(1)
  parameters.prepare()
}

/**
 * [Make query for can take all records from table]
 */
module.exports.getAll = (columns = '*') => {
  if (_table === '') {
    throw new Error('The table is not set!')
  }
  if (!columns) {
    throw new Error('The columns is not set!')
  }
  queryBuilder.makeQuery()
    .from(_table)
    .select(columns)
  parameters.prepare()
}

/**
 * [findById description]
 * @return {[type]} [description]
 */
module.exports.findById = (columns = '*') => {

}

/**
 * [Find record on database by one state]
 * @param  {Object} column [Column on database. For example { id: '5'} means find element with id 5]
 * @return {Object}        [Record from database by current schema which is set before]
 */
module.exports.findByField = (columns = '*', column) => {

}

@@ -241,16 +241,23 @@
 %7B%0A  if (
+typeof 
 table ==
@@ -727,33 +727,16 @@
 yBuilder
-.makeQuery()%0A    
 .table(_
@@ -767,17 +767,16 @@
 arams))%0A
-%0A
   parame
@@ -1105,33 +1105,16 @@
 yBuilder
-.makeQuery()%0A    
 .from(_t
@@ -1444,33 +1444,16 @@
 yBuilder
-.makeQuery()%0A    
 .from(_t
@@ -1807,25 +1807,8 @@
 lder
-.makeQuery()%0A    
 .fro
@@ -1808,37 +1808,32 @@
 der.from(_table)
-%0A    
 .select(columns)
@@ -1885,24 +1885,120 @@
 escription%5D%0A
+ * @param  %7B%5Btype%5D%7D id            %5Bdescription%5D%0A * @param  %7BString%7D %5Bcolumns='*'%5D %5Bdescription%5D%0A
  * @return %7B
@@ -2004,16 +2004,30 @@
 %7B%5Btype%5D%7D
+              
  %5Bdescri
@@ -2060,24 +2060,28 @@
 findById = (
+id, 
 columns = '*
@@ -2088,16 +2088,314 @@
 ') =%3E %7B%0A
+  if (_table === '') %7B%0A    throw new Error('The table is not set!')%0A  %7D%0A  if (!columns) %7B%0A    throw new Error('The columns is not set!')%0A  %7D%0A  if (!id) %7B%0A    throw new Error('The id is not set!')%0A  %7D%0A%0A  queryBuilder.from(_table)%0A    .select(columns)%0A    .where('id', '=', id)%0A  parameters.prepare()
 %0A%7D%0A%0A/**%0A
@@ -2463,16 +2463,26 @@
  column 
+          
 %5BColumn 
@@ -2555,90 +2555,153 @@
  * @
-return %7BObject%7D        %5BRecord from database by current schema which is set before
+param %7BString%7D columns           %5B%5D%0A * @param  %7BString%7D %5BandOr='AND'%5D    %5BIf before has another where clause then is possible to choose AND or OR
 %5D%0A *
@@ -2728,20 +2728,29 @@
 dByField
+s
  = (
+column, 
 columns 
@@ -2760,20 +2760,521 @@
 *', 
-column) =%3E %7B%0A
+andOr = 'AND') =%3E %7B%0A  if (_table === '') %7B%0A    throw new Error('The table is not set!')%0A  %7D%0A  if (!columns) %7B%0A    throw new Error('The columns is not set!')%0A  %7D%0A  if (!column) %7B%0A    throw new Error('The id is not set!')%0A  %7D%0A%0A  let firstKey = Object.keys(column)%0A%0A  queryBuilder.from(_table)%0A    .select(columns)%0A    .where(firstKey, '=', column%5BfirstKey%5D)%0A%0A  delete column%5BfirstKey%5D%0A%0A  if (column) %7B%0A    for (let key in column) %7B%0A      queryBuilder.andWhere(key, '=', column%5Bkey%5D)%0A    %7D%0A  %7D%0A%0A  parameters.prepare()
 %0A%7D%0A

Make functionality for findByFields for many fields not only for one field from database