-
-
Notifications
You must be signed in to change notification settings - Fork 0
docs: update documentation for collection mapping support #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,64 @@ | ||
| # Attributes | ||
|
|
||
| Documentation coming soon. See [Phase 1 Requirements](../roadmap/phase-1.md) for detailed specifications. | ||
| DynamoMapper configuration is done via attributes on the **mapper class**. | ||
|
|
||
| ## DynamoMapperAttribute | ||
|
|
||
| Marks a static partial class as a mapper and sets defaults. | ||
|
|
||
| ```csharp | ||
| [DynamoMapper( | ||
| Convention = DynamoNamingConvention.CamelCase, | ||
| DefaultRequiredness = Requiredness.InferFromNullability, | ||
| OmitNullStrings = true, | ||
| OmitEmptyStrings = false, | ||
| DateTimeFormat = "O", | ||
| EnumFormat = "G")] | ||
| public static partial class OrderMapper | ||
| { | ||
| public static partial Dictionary<string, AttributeValue> ToItem(Order source); | ||
| public static partial Order FromItem(Dictionary<string, AttributeValue> item); | ||
| } | ||
| ``` | ||
|
|
||
| ## DynamoFieldAttribute | ||
|
|
||
| Configures mapping for a specific member. Apply multiple times to the mapper class. | ||
|
|
||
| ```csharp | ||
| [DynamoMapper] | ||
| [DynamoField(nameof(Order.Notes), OmitIfNull = true, OmitIfEmptyString = true)] | ||
| [DynamoField(nameof(Order.OrderId), AttributeName = "orderId")] | ||
| public static partial class OrderMapper | ||
| { | ||
| public static partial Dictionary<string, AttributeValue> ToItem(Order source); | ||
| public static partial Order FromItem(Dictionary<string, AttributeValue> item); | ||
| } | ||
| ``` | ||
|
|
||
| Properties: | ||
| - `MemberName` (ctor) - target member name | ||
| - `AttributeName` - DynamoDB attribute name override | ||
| - `Required` - requiredness override | ||
| - `Kind` - DynamoDB `DynamoKind` override | ||
| - `OmitIfNull` - omit when null | ||
| - `OmitIfEmptyString` - omit when empty string | ||
| - `ToMethod` / `FromMethod` - static conversion methods on the mapper class | ||
|
|
||
| ## DynamoIgnoreAttribute | ||
|
|
||
| Skips a member in one or both directions. | ||
|
|
||
| ```csharp | ||
| [DynamoMapper] | ||
| [DynamoIgnore(nameof(Order.InternalNotes), Ignore = IgnoreMapping.All)] | ||
| public static partial class OrderMapper | ||
| { | ||
| public static partial Dictionary<string, AttributeValue> ToItem(Order source); | ||
| public static partial Order FromItem(Dictionary<string, AttributeValue> item); | ||
| } | ||
| ``` | ||
|
|
||
| Properties: | ||
| - `MemberName` (ctor) - target member name | ||
| - `Ignore` - `IgnoreMapping.All`, `IgnoreMapping.FromModel`, or `IgnoreMapping.ToModel` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,47 @@ | ||
| # Generated Code | ||
|
|
||
| Documentation coming soon. See [Phase 1 Requirements](../roadmap/phase-1.md) for detailed specifications. | ||
| The generator emits explicit `ToItem`/`FromItem` implementations that call the runtime | ||
| extension methods. The example below is a real-world output. | ||
|
|
||
| ```csharp | ||
| //------------------------------------------------------------------------------ | ||
| // <auto-generated> | ||
| // This code was generated by a tool. | ||
| // | ||
| // Changes to this file may cause incorrect behavior and will be lost if | ||
| // the code is regenerated. | ||
| // </auto-generated> | ||
| //------------------------------------------------------------------------------ | ||
|
|
||
| #nullable enable | ||
|
|
||
| using DynamoMapper.Runtime; | ||
| using System.Collections.Generic; | ||
| using Amazon.DynamoDBv2.Model; | ||
|
|
||
| namespace Trivia.Manager.Shared.Models; | ||
|
|
||
| internal static partial class DuplicateResultMapper | ||
| { | ||
| [global::System.CodeDom.Compiler.GeneratedCode("DynamoMapper", "1.0.0.0")] | ||
| internal static partial global::System.Collections.Generic.Dictionary<string, global::Amazon.DynamoDBv2.Model.AttributeValue> ToItem(global::Trivia.Manager.Shared.Models.DuplicateResult duplicateResult) => | ||
| new Dictionary<string, AttributeValue>(2) | ||
| .SetString("id", duplicateResult.Id, false, true) | ||
| .Set("score", ScoreToAttribute(duplicateResult)); | ||
|
|
||
| [global::System.CodeDom.Compiler.GeneratedCode("DynamoMapper", "1.0.0.0")] | ||
| internal static partial global::Trivia.Manager.Shared.Models.DuplicateResult FromItem(global::System.Collections.Generic.Dictionary<string, global::Amazon.DynamoDBv2.Model.AttributeValue> item) | ||
| { | ||
| var duplicateResult = new global::Trivia.Manager.Shared.Models.DuplicateResult | ||
| { | ||
| Id = item.GetString("id", Requiredness.InferFromNullability), | ||
| Score = item.GetFloat("score", Requiredness.InferFromNullability), | ||
| }; | ||
| return duplicateResult; | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| Notes: | ||
| - Generated code uses `SetX`/`GetX` helpers from `DynamoMapper.Runtime`. | ||
| - Class-level `[DynamoField]`/`[DynamoIgnore]` configuration influences argument values. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,75 @@ | ||
| # Runtime Helpers | ||
|
|
||
| Documentation coming soon. See [Phase 1 Requirements](../roadmap/phase-1.md) for detailed specifications. | ||
| The runtime package exposes extension methods on | ||
| `Dictionary<string, AttributeValue>` for both generated code and manual use. | ||
|
|
||
| ## Core Value Helpers | ||
|
|
||
| These methods live in `DynamoMapper.Runtime` and are used by the generator. | ||
|
|
||
| String: | ||
| - `GetString`, `GetNullableString` | ||
| - `SetString` | ||
|
|
||
| Boolean: | ||
| - `GetBool`, `GetNullableBool` | ||
| - `SetBool` | ||
|
|
||
| Numbers: | ||
| - `GetInt`, `GetNullableInt` | ||
| - `GetLong`, `GetNullableLong` | ||
| - `GetFloat`, `GetNullableFloat` | ||
| - `GetDouble`, `GetNullableDouble` | ||
| - `GetDecimal`, `GetNullableDecimal` | ||
| - `GetShort`, `GetNullableShort` | ||
| - `GetByte`, `GetNullableByte` | ||
| - `SetInt`, `SetLong`, `SetFloat`, `SetDouble`, `SetDecimal`, `SetShort`, `SetByte` | ||
|
|
||
| Date/Time: | ||
| - `GetDateTime`, `GetNullableDateTime` | ||
| - `GetDateTimeOffset`, `GetNullableDateTimeOffset` | ||
| - `GetTimeSpan`, `GetNullableTimeSpan` | ||
| - `SetDateTime`, `SetDateTimeOffset`, `SetTimeSpan` | ||
|
|
||
| Guid: | ||
| - `GetGuid`, `GetNullableGuid` | ||
| - `SetGuid` | ||
|
|
||
| Enum: | ||
| - `GetEnum<T>`, `GetNullableEnum<T>` | ||
| - `SetEnum<T>` | ||
|
|
||
| ## Collection Helpers | ||
|
|
||
| Lists and maps: | ||
| - `GetList<T>`, `GetNullableList<T>` | ||
| - `SetList<T>` | ||
| - `GetMap<T>`, `GetNullableMap<T>` | ||
| - `SetMap<T>` | ||
|
|
||
| Sets: | ||
| - `GetStringSet`, `GetNullableStringSet`, `SetStringSet` | ||
| - `GetNumberSet<T>`, `GetNullableNumberSet<T>`, `SetNumberSet<T>` | ||
| - `GetBinarySet`, `GetNullableBinarySet`, `SetBinarySet` | ||
|
|
||
| ## Parameters | ||
|
|
||
| - `Requiredness` controls missing-attribute behavior (`Required`, `Optional`, | ||
| `InferFromNullability`). | ||
| - `DynamoKind` lets you override the inferred DynamoDB kind. | ||
|
|
||
| ## Example | ||
|
|
||
| ```csharp | ||
| var attributes = new Dictionary<string, AttributeValue>(); | ||
|
|
||
| attributes | ||
| .SetString("pk", "USER#123") | ||
| .SetInt("version", 2) | ||
| .SetList("tags", new List<string> { "alpha", "beta" }) | ||
| .SetMap("metadata", new Dictionary<string, int> { ["count"] = 42 }) | ||
| .SetBinarySet("payloads", new List<byte[]> { new byte[] { 1, 2, 3 } }); | ||
|
|
||
| var tags = attributes.GetList<string>("tags"); | ||
| var version = attributes.GetInt("version"); | ||
| ``` |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add guid and timespan formats here to if you want all props set?