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提供的BLOB存储。
这是一个简单的例子:
[ 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转换器需要在模型中提供。您可以在方便的情况下使用汽车应用程序或其他工具。
[ 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 ,
} ;
}请参阅文档。
麻省理工学院许可证(请参阅许可证文件)。