GitObjectDb
v0.2.79-alpha
gitobjectdbは、gitにバックすることにより、構成管理バージョンを簡素化します。
| 名前 | バッジ |
|---|---|
| gitobjectdb | |
| gitobjectdb.systemtextjson | |
| gitobjectdb.yamldotnet | |
| gitobjectdb.api.odata | |
| gitobjectdb.api.graphql | |
| gitobjectdb.api.protobuf | |
| gitobjectdb.api.protobuf.model |
gitobjectdbは、構成管理バージョンの単純化を実現するように設計されています。これは、GITと対話するために必要なコマンドをハンドコーディングする必要があることを削除することで行います。
GITリポジトリは、オブジェクトのシリアル化コピーを含むファイルがファイルシステムに取得されないため、純粋なデータベースとして使用されます。 gitobjectdbは、gitが提供するブロブストレージのみを使用します。
これが簡単な例です:
[ GitFolder ( "Applications" ) ]
public record Application : Node
{
public string Name { get ; init ; }
public string Description { get ; init ; }
}
[ GitFolder ( "Pages" ) ]
public record Table : Node
{
public string Name { get ; init ; }
public string Description { get ; init ; }
[ StoreAsSeparateFile ( Extension = "txt" ) ]
public string ? RichContent { get ; init ; }
} var existingApplication = connection . Lookup < Application > ( "main" , "applications" , new UniqueId ( id ) ) ;
var newTable = new Table { .. . } ;
connection
. Update ( "main" , c => c . CreateOrUpdate ( newTable , parent : existingApplication ) )
. Commit ( new ( "Added new table." , author , committer ) ) ; var node = new SomeNode
{
SomeProperty = "Value stored as json" ,
RichContent = "Value stored as raw text in separate Git blob, next to primary one" ,
} :...次のようにGitに保存されます:
{
"$type" : " Sample.SomeNode " ,
"id" : " zerzrzrz " ,
"someProperty" : " Value stored as json "
} Value stored many dynamic resources in separate Git blob, next to primary one
リソースを個別のファイルとして保存することもできます。
new Resource ( node , "Some/Folder" , "File.txt" , new Resource . Data ( "Value stored in a separate file in <node path>/Resources/Some/Folder/File.txt" ) ) ; connection
. Update ( "main" , c => c . CreateOrUpdate ( table with { Description = newDescription } ) )
. Commit ( new ( "Some message" , signature , signature ) ) ;
connection . Checkout ( "newBranch" , "main~1" ) ;
connection
. Update ( "main" , c => c . CreateOrUpdate ( table with { Name = newName } ) )
. Commit ( new ( "Another message" , signature , signature ) ) ; var comparison = connection . Compare ( "main~5" , "main" ) ;
var nodeChanges = comparison . Modified . OfType < Change . NodeChange > ( ) ; ノード参照により、既存のノードをリポジトリにリンクできます。
public record Order : Node
{
public Client Client { get ; set ; }
// ...
}
public record Client : Node
{
// ...
}
// Nodes get loaded with their references (using a shared )
var cache = new Dictionary < DataPath , ITreeItem > ( ) ;
var order = connection . GetNodes < Order > ( "main" , referenceCache : cache ) . First ( ) ;
Console . WriteLine ( order . Client . Id ) ; // main: A---B A---B
// ->
// newBranch: C C---x
connection
. Update ( "main" , c => c . CreateOrUpdate ( table with { Description = newDescription } ) )
. Commit ( new ( "B" , signature , signature ) ) ;
connection . Repository . Branches . Add ( "newBranch" , "main~1" ) ;
connection
. Update ( "newBranch" , c => c . CreateOrUpdate ( table with { Name = newName } ) )
. Commit ( new ( "C" , signature , signature ) ) ;
sut . Merge ( upstreamCommittish : "main" ) ; コードで最初のタイプを定義するシナリオを想像してください。
[ GitFolder ( FolderName = "Items" , UseNodeFolders = false ) ]
[ IsDeprecatedNodeType ( typeof ( SomeNodeV2 ) ) ]
private record SomeNodeV1 : Node
{
public int Flags { get ; set ; }
}
[ GitFolder ( FolderName = "Items" , UseNodeFolders = false ) ]
private record SomeNodeV2 : Node
{
public BindingFlags TypedFlags { get ; set ; }
}次に、 Flagsプロパティにより意味のある情報が含まれているように、新しい変更を導入したいと思います。
[ GitFolder ( FolderName = "Items" , UseNodeFolders = false ) ]
private record SomeNodeV2 : Node
{
public BindingFlags TypedFlags { get ; set ; }
}必要なのは、#1 [IsDeprecatedNodeType(typeof(SomeNodeV2))]属性を追加することです。これにより、Deserializerに、コンバーターを使用してノードを新しいバージョンに変換するよう指示します。 #2コンバーターはモデルで提供する必要があります。都合の良いときに、AutomApperやその他のツールを使用できます。
[ GitFolder ( FolderName = "Items" , UseNodeFolders = false ) ]
[ IsDeprecatedNodeType ( typeof ( SomeNodeV2 ) ) ]
private record SomeNodeV1 : Node
{
// ...
}
var model = new ConventionBaseModelBuilder ( )
. RegisterType < SomeNodeV1 > ( )
. RegisterType < SomeNodeV2 > ( )
. AddDeprecatedNodeUpdater ( UpdateDeprecatedNode )
. Build ( ) ;
Node UpdateDeprecatedNode ( Node old , Type targetType )
{
var nodeV1 = ( SomeNodeV1 ) old ;
return new SomeNodeV2
{
Id = old . Id ,
TypedFlags = ( BindingFlags ) nodeV1 . Flags ,
} ;
}ドキュメントを参照してください。
MITライセンス(ライセンスファイルを参照)。