如何在JSdoc中的方法中记录嵌套函数

时间:2019-02-19 22:10:06

标签: javascript jsdoc

在javascript中,我有一个内部具有函数的方法,当尝试使用JSdocs程序对其进行记录时,我认为它会必须看起来像这样:

 /**
  * @memberof dataBase#query
  * @inner
  * @function makeArray
  * @description ..
*/

或类似的

/**
  * @function dataBase#query~makeArray
  * @description ..
*/

但是由于某种原因它没有显示。

问题:我有什么办法可以记录这种功能?

编辑:

您可能会注意到我的代码中的某些位置,该位置继续在线至下一行,这仅仅是因为stackoverflow问题框所提供的空间有限,而不是我的源代码的一部分。

这是我要记录的代码(特别是查询方法内部的makeArray函数):

exports.dataBase = class dataBase {
  constructor(connection, X64) {
    this.connectString = connection
    this.X64 = X64
    this.connection = adodb.open(connection, X64)
    this._this = this
    this.shortcuts = require('./shortcuts')
  }

  async close() {
    await this.connection.close()
    return
  }

  async reopen() {
    this.connection = adodb.open(this.connectString, this.X64)
    return
  }

  async shortcut(type, data) {
    await this.shortcuts.data[type](data, this._this)
    return 
  }

  async runSQL(sql) {
    let type
    if(sql.match('SELECT')) {
      type = 'query'
    } else {
      type = 'execute'
    }
    let data
    let self = this
    await new Promise((resolve, reject) => {
      self.connection[type](sql).then(result => {
        data = result
        resolve()
      }).catch(err => {
        console.log(err)
      })
    }).catch(err => {
      console.log(err)
    })
    return data
  }

  async query(table, columns = '*' || [], rows = '*' || [], options = '*'             
|| []) {
    function makeArray(str) {
      if(typeof str === 'string' && str !== '*') {
        return [str]
      }
    }

    makeArray(columns)
    makeArray(rows)
    makeArray(options)

    function processData(table, columns, rows, options) {
      function processColumns(columns) {
        let retval = ''
        for(let i in columns) {
          if(i != columns.length - 1) {
            retval += `${columns[i]},`
          } else {
            retval += `${columns[i]}`
            return retval
          }
        }

      }

      function processRows(rows) {
        let retval = ''
        for(let i in rows) {
          if(i != rows.length - 1) {
            retval += `ID=${rows[i]} AND `
          } else {
            retval += `ID=${rows[i]}`
          }
        }
        return retval
      }

      function processOptions(options) {
        let retval = ''
        for(let i in rows) {
            retval += ` AND ${options[i]}`
        }
        return retval
      }

      let SQLcolumns = processColumns(columns)
      let SQLrows = processRows(rows)
      let SQLoptions = processOptions(options)

      if(rows === '*' && options === '*') {
        return `SELECT ${SQLcolumns} FROM [${table}];`
      } else if(options === '*') {
        return `SELECT ${SQLcolumns} FROM [${table}] WHERE ${SQLrows};`
      } else if(rows === '*') {
        return `SELECT ${SQLcolumns} FROM [${table}] WHERE ${SQLoptions};`
      } else {
        return `SELECT ${SQLcolumns} FROM [${table}] WHERE     
 ${SQLrows}${SQLoptions};`
      }
    }

    let data
    await this.runSQL(processData(table, columns, rows,     
options)).then((result) => {
      data = result
    }).catch(err => {
      console.log(err)
    })
    return data
  }

  async createTable(name, columns, rows = null) {
    function processColumns(columns) {
      let retval = ''
      for(let i of Object.keys(columns)) {
        if(i !== Object.keys(columns)[columns.size() - 1]) {
          retval += `${i} ${columns[i]},\n`
        } else {
          retval += `${i} ${columns[i]}`
        }
      }
      return retval
    }
    let data
    let SQLcolumns = processColumns(columns)

    await this.runSQL(`CREATE TABLE ${name}     
(\n${SQLcolumns}\n);`).then((result) => {
      data = result
    })  

    if(rows !== null) {
      this.addRecords(name, rows)
    }
  }

  async addRecords(table, values) {
    let data = []
    function processValues(values) {
      let retval = ''
      for(let i of Object.keys(values)) {
        if(i !== Object.keys(values)[values.size() - 1]) {
          retval += `${values[i]}, `
        } else {
          retval += values[i]
        }
      }
      return retval
    }

    for(let i of values) {
      let SQLvalues
      SQLvalues = processValues(i)
      await this.runSQL(`INSERT INTO [${table}] VALUES 
(${SQLvalues});`).then((result) => {
        data.push(result)
      })
    }

    return data
  }
}

0 个答案:

没有答案