Drift freezing on large commit

47 Views Asked by At

This is using the Drift Dart package for database management.

 //receives verses in json format and inserts it into db
  Future<Either<Failure, Success>> insertVersesFromJson(
      String verseTable, List<Map<String, dynamic>> list) async {
    try {
      list.map((Map<String, dynamic> json) async {
        final String verseId = json['verse_id'].toString();
        final String bookId = json['book_id'].toString();
        final String verseChapter = json['verse_chapter'].toString();
        final String verseNumber = json['verse_number'].toString();
        final String verseText = json['verse_text'].toString();
        final int isRed = json['is_red'] == 1 ? 1 : 0;
        final String bookName = json['book_name'].toString();

        final String query = 'INSERT INTO $verseTable VALUES( '
            '"$verseId","$bookId","$verseChapter","$verseNumber","$verseText", '
            '"$isRed","$bookName")';

        print('GUMDUM query is $query');
        await batch((Batch batch) => customStatement(query));
        return <Map<String, dynamic>>[json];
      }).toList();
      return Right<Failure, Success>(Success());
    } catch (error) {
      errorLog(error.toString(), StackTrace.current);
      return Left<Failure, Success>(DatabaseFailure());
    }
  }

I am trying to commit 31,102 entries into a table. The program freezes. I'm not certain how to use batch commit in this scenario, as it works well with other smaller queries. Any help in making this query streamlined is greatly appreciated!

0

There are 0 best solutions below