public ValueTask <GrpcResponse> InsertAsync(RowWithTableNameGrpcRequest request) { var dbTable = _dbTablesList.TryGetTable(request.TableName); var result = new GrpcResponse { Status = GrpcResultStatus.Ok }; if (dbTable == null) { result.Status = GrpcResultStatus.TableNotFound; } else { dbTable.LockWithWriteAccess(writeAccess => { var dbPartition = writeAccess.GetOrCreatePartition(request.DbRow.PartitionKey); var insertResult = dbPartition.Insert(request.DbRow); if (insertResult) { _syncEventsQueue.EnqueueDbRowChange(dbTable, request.DbRow); } else { result.Status = GrpcResultStatus.RecordAlreadyExists; } }); } _syncEventsPusher.PushEventsToReaders(); return(new ValueTask <GrpcResponse>(result)); }
public static DbTable GetTable(this DbTablesList dbTablesList, string tableName) { var table = dbTablesList.TryGetTable(tableName); if (table == null) { throw new Exception($"Table {tableName} is not found"); } return(table); }