commit method

Future<void> commit(
  1. List<Map<SqlType, String>> sqlList, {
  2. bool noResult = false,
  3. bool continueOnError = false,
})

noResult 不关心结果并担心大批量的性能 continueOnError 即使一个操作失败,也会运行并提交每个成功的操作 sqlList key-value的列表,key是语句类型,value是sql语句。List本身有序,所以不用担心顺序问题

Implementation

Future<void> commit(
  List<Map<SqlType, String>> sqlList, {
  bool noResult = false,
  bool continueOnError = false,
}) async {
  if (_db == null) {
    return;
  }
  Batch batch = _db!.batch();
  for (Map<SqlType, String> map in sqlList) {
    map.forEach((key, sql) async {
      print("key: $key, sql: $sql");
      switch (key) {
        case SqlType.insert:
          batch.rawInsert(sql);
          break;
        case SqlType.update:
          batch.rawUpdate(sql);
          break;
        case SqlType.delete:
          batch.rawDelete(sql);
          break;
        default:
          break;
      }
    });
  }
  List<Object?> results = await batch.commit(
      noResult: noResult, continueOnError: continueOnError);
  print("commit--${results.toString()}");
}