sql-util.js
/**
   * Inserts a record into a given table.
   * The keys of obj are column names
   * and their values are the values to insert.
   */
Inserts a record into a given table.
The keys of obj are column names
and their values are the values to insert.
Inserts a record into a given table . The keys of obj are column names and their values are the values to insert .
insert(tableName, obj) {
    const keys = Object.keys(obj);
    const values = keys.map(key => obj[key]);
    const cols = keys.join(', ');
    const placeholders = values.map((v, index) => '$' + (index + 1)).join(', ');
    const sql =
      `insert into ${tableName} (${cols}) values(${placeholders}) returning id`;
    this.log('insert: sql =', sql);
    return sql;
  }
insert ( tableName , obj ) { const keys = Object . keys ( obj ) ; const values = keys . map ( key => obj [ key ] ) ; const cols = keys . join ( ', ' ) ; const placeholders = values . map ( ( v , index ) => '$' + ( index + 1 ) ) . join ( ', ' ) ; const sql = ` ${ tableName } ${ cols } ${ placeholders } ` ; this . log ( 'insert: sql =' , sql ) ; return sql ; }
Inserts a record into a given table.
Inserts a record into a given table .