async implementInsert (request) {
    let beforeId

    this._checkVars()

    await super.implementInsert(request)

    // This uses body.beforeId
    await this._calculatePosition(request)

    // Zap beforeId from body, so that the insertObject
    // is built properly without dealing with beforeId as a special case

    if (this.positioning) {
      beforeId = request.body[this.beforeIdField]
      if (typeof beforeId !== 'undefined') {
        delete request.body[this.beforeIdField]
      }
    }

    const insertObject = await this.manipulateInsertObject(request, {...request.body } ) // hook

    // Run the query
    const query = await this.implementInsertSql()

    // Perform the update
    // The ID will be in insertResult.insertId
    const insertResult = await this.connection.queryP(query, [insertObject])

    // Make up a bogus request (just with request.params using insertId)
    // to re-fetch the record and return it
    // NOTE: request.params is all implementFetch uses
    const requestWithId = this.copyRequest(request, { 
      options: {}, 
      params: { [this.idProperty]: insertResult.insertId }
    })

    request.record = await this.implementFetch(requestWithId)

    // It MUST be possible to refetch after insert
    if (!request.record) {
      throw new Error('Could not re-fetch record straight after insert')
    }

    // This could be useful to the 'after' hook
    request.insertObject = insertObject

    // After insert: post-processing of the record
    await this.afterInsert(request)

    // Re-add beforeId in case it was zapped in the first place.
    // The client might need this info to place the element in the
    // right spot in the DOM
    if (typeof beforeId !== 'undefined') {
      request.record.beforeId = beforeId
      request.body.beforeId = beforeId
    }

    // give a chance to mixins to "see" the record before sending it
    await this.beforeSend(request)

    // Return the record, including beforeId
    return request.record
  }
//   request.body[beforeIdField] (beforeId placed back into body so that client gets it)
request.body[beforeIdField] (beforeId placed back into body so that client gets it)
request . body [ beforeIdField ] ( beforeId placed back into body so that client gets it )
async implementInsert (request) {
    let beforeId
    this._checkVars()
    await super.implementInsert(request)
    await this._calculatePosition(request)
    if (this.positioning) {
      beforeId = request.body[this.beforeIdField]
      if (typeof beforeId !== 'undefined') {
        delete request.body[this.beforeIdField]
      }
    }
    const insertObject = await this.manipulateInsertObject(request, {...request.body } ) 
    const query = await this.implementInsertSql()
    const insertResult = await this.connection.queryP(query, [insertObject])
    const requestWithId = this.copyRequest(request, { 
      options: {}, 
      params: { [this.idProperty]: insertResult.insertId }
    })
    request.record = await this.implementFetch(requestWithId)
    if (!request.record) {
      throw new Error('Could not re-fetch record straight after insert')
    }
    request.insertObject = insertObject
    await this.afterInsert(request)
    if (typeof beforeId !== 'undefined') {
      request.record.beforeId = beforeId
      request.body.beforeId = beforeId
    }
    await this.beforeSend(request)
    return request.record
  }
async implementInsert ( request ) { let beforeId this . _checkVars ( ) await super . implementInsert ( request ) await this . _calculatePosition ( request ) if ( this . positioning ) { beforeId = request . body [ this . beforeIdField ] if ( typeof beforeId !== 'undefined' ) { delete request . body [ this . beforeIdField ] } } const insertObject = await this . manipulateInsertObject ( request , { ... request . body } ) const query = await this . implementInsertSql ( ) const insertResult = await this . connection . queryP ( query , [ insertObject ] ) const requestWithId = this . copyRequest ( request , { options : { } , params : { [ this . idProperty ] : insertResult . insertId } } ) request . record = await this . implementFetch ( requestWithId ) if ( ! request . record ) { throw new Error ( 'Could not re-fetch record straight after insert' ) } request . insertObject = insertObject await this . afterInsert ( request ) if ( typeof beforeId !== 'undefined' ) { request . record . beforeId = beforeId request . body . beforeId = beforeId } await this . beforeSend ( request ) return request . record }
request.body[beforeIdField] (beforeId placed back into body so that client gets it)
request . body [ beforeIdField ] ( beforeId placed back into body so that client gets it )
// This uses body.beforeId // Zap beforeId from body, so that the insertObject // is built properly without dealing with beforeId as a special case // hook // Run the query // Perform the update // The ID will be in insertResult.insertId // Make up a bogus request (just with request.params using insertId) // to re-fetch the record and return it // NOTE: request.params is all implementFetch uses // It MUST be possible to refetch after insert // This could be useful to the 'after' hook // After insert: post-processing of the record // Re-add beforeId in case it was zapped in the first place. // The client might need this info to place the element in the // right spot in the DOM // give a chance to mixins to "see" the record before sending it // Return the record, including beforeId