save method

  1. @override
Future<Map?> save(
  1. covariant Map entity, {
  2. bool isUpsert = false,
})
override

If the variable isUpsert = true, then it calls the upsert method. Else if the object contains an objectId, the update method is called, which updates an already existing object. Otherwise, the create method will be called, which creates a new object in the table.

Implementation

@override
Future<Map?> save(covariant Map entity, {bool isUpsert = false}) async {
  String methodName = '/data/$tableName';

  if (isUpsert) {
    methodName += '/upsert';
  } else if (entity.containsKey('objectId')) {
    methodName += '/${entity['objectId']}';
  } else {
    return await Invoker.post(methodName, entity);
  }

  return await Invoker.put(methodName, entity);
}