upsert<_Model extends _RepositoryModel> method

  1. @override
Future<_Model> upsert<_Model extends _RepositoryModel>(
  1. _Model instance, {
  2. Query? query,
})

Send a model to remoteProvider and hydrate.

Implementation

@override
Future<_Model> upsert<_Model extends _RepositoryModel>(
  _Model instance, {
  Query? query,
}) async {
  if (query?.action == null) {
    query = (query ?? Query()).copyWith(action: QueryAction.upsert);
  }
  logger.finest('#upsert: $query $instance');

  final modelId = await sqliteProvider.upsert<_Model>(
    instance,
    query: query,
    repository: this,
  );
  instance.primaryKey = modelId;
  memoryCacheProvider.upsert<_Model>(instance, query: query);

  try {
    await remoteProvider.upsert<_Model>(instance, query: query, repository: this);
  } on ClientException catch (e) {
    logger.warning('#upsert client failure: $e');
  } on SocketException catch (e) {
    logger.warning('#upsert socket failure: $e');
  }

  // ignore: unawaited_futures
  if (autoHydrate) hydrate<_Model>(query: query);

  return instance;
}