-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow persisting entities as documents
Introduce a document-based repository that allows persisting the entire entity payload to a single column. Regardless of the serialization strategy used, we persist the type full name and assembly version of the persisted entity, which can be invaluable in data migration scenarios. In addition to the built-in JSON text serialization, we provide three binary serializers too as separate packages: Bson, MessagePack and Protobuf. The last two require annotating the entity as required by the underlying libraries. Fixes #24.
- Loading branch information
Showing
39 changed files
with
1,284 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -26,4 +26,5 @@ _site | |
.jekyll-metadata | ||
.jekyll-cache | ||
Gemfile.lock | ||
package-lock.json | ||
package-lock.json | ||
__azurite_db_table__.json |
This file contains 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
10 changes: 10 additions & 0 deletions
10
src/TableStorage.Bson.Source/Devlooped.TableStorage.Bson.Source.targets
This file contains 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<Project> | ||
|
||
<ItemGroup> | ||
<Compile Update="@(Compile -> WithMetadataValue('NuGetPackageId', 'Devlooped.TableStorage.Bson.Source'))"> | ||
<Visible>false</Visible> | ||
<Link>Devlooped\TableStorage.Bson\%(Filename)%(Extension)</Link> | ||
</Compile> | ||
</ItemGroup> | ||
|
||
</Project> |
32 changes: 32 additions & 0 deletions
32
src/TableStorage.Bson.Source/TableStorage.Bson.Source.csproj
This file contains 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<AssemblyName>Devlooped.TableStorage.Bson.Source</AssemblyName> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<IsPackable>true</IsPackable> | ||
<PackBuildOutput>false</PackBuildOutput> | ||
<PackCompile>true</PackCompile> | ||
<Description>A source-only BSON binary serializer for use with document-based repositories. | ||
|
||
Usage: | ||
|
||
var repo = DocumentRepository.Create<Product>(storageAccount, serializer: BsonDocumentSerializer.Default); | ||
</Description> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="NuGetizer" Version="0.7.0" /> | ||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="all" /> | ||
<PackageReference Include="Newtonsoft.Json.Bson" Version="1.0.2" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\TableStorage.Source\TableStorage.Source.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="..\TableStorage.Bson\**\*.cs" Exclude="..\TableStorage.Bson\Visibility.cs;..\TableStorage.Bson\obj\**\*.cs;" /> | ||
<None Update="Devlooped.TableStorage.Bson.Source.targets" PackFolder="build" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains 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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//<auto-generated/> | ||
#nullable enable | ||
using System.IO; | ||
using Newtonsoft.Json; | ||
|
||
namespace Devlooped | ||
{ | ||
/// <summary> | ||
/// Default implementation of <see cref="IBinaryDocumentSerializer"/> which | ||
/// uses Newtonsoft.Json implementation of BSON for serialization. | ||
/// </summary> | ||
partial class BsonDocumentSerializer : IBinaryDocumentSerializer | ||
{ | ||
static readonly JsonSerializer serializer = new JsonSerializer(); | ||
|
||
/// <summary> | ||
/// Default instance of the serializer. | ||
/// </summary> | ||
public static IDocumentSerializer Default { get; } = new BsonDocumentSerializer(); | ||
|
||
/// <inheritdoc /> | ||
public T? Deserialize<T>(byte[] data) | ||
{ | ||
if (data.Length == 0) | ||
return default; | ||
|
||
using var mem = new MemoryStream(data); | ||
using var reader = new Newtonsoft.Json.Bson.BsonDataReader(mem); | ||
return (T?)serializer.Deserialize<T>(reader); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public byte[] Serialize<T>(T value) | ||
{ | ||
if (value == null) | ||
return new byte[0]; | ||
|
||
using var mem = new MemoryStream(); | ||
using var writer = new Newtonsoft.Json.Bson.BsonDataWriter(mem); | ||
serializer.Serialize(writer, value); | ||
return mem.ToArray(); | ||
} | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<AssemblyName>Devlooped.TableStorage.Bson</AssemblyName> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<IsPackable>true</IsPackable> | ||
<Description>A BSON binary serializer for use with document-based repositories. | ||
|
||
Usage: | ||
|
||
var repo = DocumentRepository.Create<Product>(storageAccount, serializer: BsonDocumentSerializer.Default); | ||
</Description> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="NuGetizer" Version="0.7.0" /> | ||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="all" /> | ||
<PackageReference Include="Newtonsoft.Json.Bson" Version="1.0.2" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\TableStorage\TableStorage.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
//<auto-generated/> | ||
namespace Devlooped | ||
{ | ||
// Sets default visibility when using compiled version, where everything is public | ||
public partial class BsonDocumentSerializer { } | ||
} |
10 changes: 10 additions & 0 deletions
10
src/TableStorage.MessagePack.Source/Devlooped.TableStorage.MessagePack.Source.targets
This file contains 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<Project> | ||
|
||
<ItemGroup> | ||
<Compile Update="@(Compile -> WithMetadataValue('NuGetPackageId', 'Devlooped.TableStorage.MessagePack.Source'))"> | ||
<Visible>false</Visible> | ||
<Link>Devlooped\TableStorage.MessagePack\%(Filename)%(Extension)</Link> | ||
</Compile> | ||
</ItemGroup> | ||
|
||
</Project> |
32 changes: 32 additions & 0 deletions
32
src/TableStorage.MessagePack.Source/TableStorage.MessagePack.Source.csproj
This file contains 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<AssemblyName>Devlooped.TableStorage.MessagePack.Source</AssemblyName> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<IsPackable>true</IsPackable> | ||
<PackBuildOutput>false</PackBuildOutput> | ||
<PackCompile>true</PackCompile> | ||
<Description>A source-only MessagePack binary serializer for use with document-based repositories. | ||
|
||
Usage: | ||
|
||
var repo = DocumentRepository.Create<Product>(storageAccount, serializer: MessagePackDocumentSerializer.Default); | ||
</Description> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="NuGetizer" Version="0.7.0" /> | ||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="all" /> | ||
<PackageReference Include="MessagePack" Version="2.2.85" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\TableStorage.Source\TableStorage.Source.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="..\TableStorage.MessagePack\**\*.cs" Exclude="..\TableStorage.MessagePack\Visibility.cs;..\TableStorage.MessagePack\obj\**\*.cs;" /> | ||
<None Update="Devlooped.TableStorage.MessagePack.Source.targets" PackFolder="build" /> | ||
</ItemGroup> | ||
|
||
</Project> |
24 changes: 24 additions & 0 deletions
24
src/TableStorage.MessagePack/MessagePackDocumentSerializer.cs
This file contains 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//<auto-generated/> | ||
#nullable enable | ||
using MessagePack; | ||
|
||
namespace Devlooped | ||
{ | ||
/// <summary> | ||
/// Default implementation of <see cref="IBinaryDocumentSerializer"/> which | ||
/// uses Newtonsoft.Json implementation of BSON for serialization. | ||
/// </summary> | ||
partial class MessagePackDocumentSerializer : IBinaryDocumentSerializer | ||
{ | ||
/// <summary> | ||
/// Default instance of the serializer. | ||
/// </summary> | ||
public static IDocumentSerializer Default { get; } = new MessagePackDocumentSerializer(); | ||
|
||
/// <inheritdoc /> | ||
public T? Deserialize<T>(byte[] data) => data.Length == 0 ? default : MessagePackSerializer.Deserialize<T>(data); | ||
|
||
/// <inheritdoc /> | ||
public byte[] Serialize<T>(T value) => value == null ? new byte[0] : MessagePackSerializer.Serialize(value.GetType(), value); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/TableStorage.MessagePack/TableStorage.MessagePack.csproj
This file contains 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<AssemblyName>Devlooped.TableStorage.MessagePack</AssemblyName> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<IsPackable>true</IsPackable> | ||
<Description>A MessagePack binary serializer for use with document-based repositories. | ||
|
||
Usage: | ||
|
||
var repo = DocumentRepository.Create<Product>(storageAccount, serializer: BsonDocumentSerializer.Default); | ||
</Description> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="NuGetizer" Version="0.7.0" /> | ||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="all" /> | ||
<PackageReference Include="MessagePack" Version="2.2.85" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\TableStorage\TableStorage.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
//<auto-generated/> | ||
namespace Devlooped | ||
{ | ||
// Sets default visibility when using compiled version, where everything is public | ||
public partial class MessagePackDocumentSerializer { } | ||
} |
Oops, something went wrong.