Skip to content

Commit

Permalink
Few more code comments
Browse files Browse the repository at this point in the history
  • Loading branch information
halgari committed Sep 19, 2024
1 parent 94e054f commit 2663339
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,20 @@

namespace NexusMods.Abstractions.NexusModsLibrary;

public struct GraphQLResolver(ITransaction Tx, ReadOnlyModel Model)
/// <summary>
/// A helper for upserting entities in the database. When created, you must define a "pimary key" attribute and value,
/// these are used to determine if the entity already exists in the database. If it does, the existing entity is updated,
/// otherwise a new entity is created.
///
/// For each attribute you want to add to the entity, call the Add method with the attribute and value and any duplicate values
/// will not be added.
/// </summary>
// ReSharper disable once InconsistentNaming
public readonly struct GraphQLResolver(ITransaction Tx, ReadOnlyModel Model)
{
/// <summary>
/// Create a new resolver using the given primary key attribute and value.
/// </summary>
public static GraphQLResolver Create<THighLevel, TLowLevel>(IDb referenceDb, ITransaction tx, ScalarAttribute<THighLevel, TLowLevel> primaryKeyAttribute, THighLevel primaryKeyValue) where THighLevel : notnull
{
var existing = referenceDb.Datoms(primaryKeyAttribute, primaryKeyValue);
Expand All @@ -22,6 +34,9 @@ public static GraphQLResolver Create<THighLevel, TLowLevel>(IDb referenceDb, ITr
/// </summary>
public EntityId Id => Model.Id;

/// <summary>
/// Add a value to the entity. If the value already exists, it will not be added again.
/// </summary>
public void Add<THighLevel, TLowLevel>(ScalarAttribute<THighLevel, TLowLevel> attribute, THighLevel value)
where THighLevel : notnull
{
Expand All @@ -35,6 +50,9 @@ public void Add<THighLevel, TLowLevel>(ScalarAttribute<THighLevel, TLowLevel> at
Tx.Add(Model.Id, attribute, value);
}

/// <summary>
/// Add a value to the entity. If the value already exists, it will not be added again.
/// </summary>
public void Add<TOther>(ReferencesAttribute<TOther> attribute, EntityId id)
where TOther : IModelDefinition
{
Expand All @@ -51,6 +69,9 @@ public void Add<TOther>(ReferencesAttribute<TOther> attribute, EntityId id)
Tx.Add(Model.Id, attribute, id);
}

/// <summary>
/// Add a value to the entity. If the value already exists, it will not be added again.
/// </summary>
public void Add<TOther>(ReferenceAttribute<TOther> attribute, EntityId id)
where TOther : IModelDefinition
{
Expand Down

0 comments on commit 2663339

Please sign in to comment.