create method

  1. @override
FutureOr<void> create(
  1. ServiceDefinitionModel entity, {
  2. bool createOpLog = false,
  3. DataOperation dataOperation = DataOperation.create,
})
override

The create method creates a new entity.

Implementation

@override
FutureOr<void> create(
  ServiceDefinitionModel entity, {
  bool createOpLog = false,
  DataOperation dataOperation = DataOperation.create,
}) async {
  return retryLocalCallOperation(() async {
    final serviceDefinitionCompanion = entity.companion;
    final attributes = entity.attributes;
    await sql.batch((batch) {
      batch.insert(
        sql.serviceDefinition,
        serviceDefinitionCompanion,
        mode: InsertMode.insertOrReplace,
      );
      if (attributes != null) {
        final attributesCompanions = attributes.map((e) {
          return e.companion;
        }).toList();

        batch.insertAll(
          sql.attributes,
          attributesCompanions,
          mode: InsertMode.insertOrReplace,
        );
      }
    });

    await super.create(entity, createOpLog: false);
  });
}