GitObjectDB ทำให้การกำหนดค่าการกำหนดค่าการกำหนดค่าง่ายขึ้นโดยการสนับสนุนใน Git
| ชื่อ | ตราสัญลักษณ์ |
|---|---|
| GitobjectDB | |
| gitobjectdb.systemtextjson | |
| gitobjectdb.yamldotnet | |
| gitobjectdb.api.odata | |
| gitobjectdb.api.graphql | |
| gitobjectdb.api.protobuf | |
| gitobjectdb.api.protobuf.model |
GitObjectDB ได้รับการออกแบบมาเพื่อลดความซับซ้อนของการกำหนดค่าการจัดการการกำหนดค่า มันทำได้โดยการลบความจำเป็นในการเข้ารหัสด้วยมือที่จำเป็นในการโต้ตอบกับ Git
พื้นที่เก็บข้อมูล GIT ใช้เป็นฐานข้อมูลบริสุทธิ์เป็นไฟล์ที่มีสำเนาอนุกรมของวัตถุจะไม่ถูกดึงในระบบไฟล์ GitObjectDB ใช้ที่เก็บของ Blob เท่านั้นที่จัดทำโดย 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 มีข้อมูลที่มีความหมายมากขึ้นโดยอาศัย enums:
[ 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 (ดูไฟล์ใบอนุญาต)