bulkCreate method

  1. @override
FutureOr<void> bulkCreate(
  1. List<HouseholdModel> entities
)
override

Implementation

@override
FutureOr<void> bulkCreate(
  List<HouseholdModel> entities,
) async {
  return retryLocalCallOperation(() async {
    final householdCompanions = entities.map((e) => e.companion).toList();

    await sql.batch((batch) async {
      final addressCompanions = entities.map((e) {
        if (e.address != null) {
          return e.address!
              .copyWith(
                relatedClientReferenceId: e.clientReferenceId,
                clientAuditDetails: e.clientAuditDetails,
                auditDetails: e.auditDetails,
              )
              .companion;
        }
      }).toList();

      if (addressCompanions.isNotEmpty) {
        batch.insertAll(
          sql.address,
          addressCompanions.whereNotNull().toList(),
          mode: InsertMode.insertOrReplace,
        );
      }

      batch.insertAll(
        sql.household,
        householdCompanions,
        mode: InsertMode.insertOrReplace,
      );
    });
  });
}