insertMap method

int? insertMap(
  1. TableName table,
  2. Map<String, dynamic> values
)

Insert a new record using a map values into a given table.

This returns the id of the inserted row.

Implementation

int? insertMap(TableName table, Map<String, dynamic> values) {
  List<dynamic> args = [];
  var keys;
  var questions;
  values.forEach((key, value) {
    if (keys == null) {
      keys = key;
      questions = "?";
    } else {
      keys = keys + "," + key;
      questions = questions + ",?";
    }
    args.add(value);
  });

  var pk = getPrimaryKey(table);
  var sql = "insert into ${table.fixedName} ( $keys ) values ( $questions );";
  return execute(sql, arguments: args, getLastInsertId: true, primaryKey: pk);
}