没有项目描述
gitgraph的Python项目详细描述
安装
pip install gitgraph
申报对象
fromgitgraphimportGitGraphfromgitgraphimportSubjectstore=GitGraph('my-git-cms')classDocument(Subject):indexes={'title'}predicates=(('title',codec.Unicode),('body',codec.Unicode),('created_at',codec.DateTime),('published_at',codec.DateTime),)incoming={'authored_by':Author,}outgoing={'contains':Tag,}
创建
uuid1='deadbeefdeadbeefdeadbeefdeadbeef'# providing your own uuiddocs1=store.create('Document',uuid=uuid1,title='Essay',body='body1',)# auto-generated uuiddocs2=store.create(Document,title='Blog',body='body2',)store.commit()uuid2=docs2.uuid
检索
一个由uuid
# Using the class Document as subject typedocs1=store.get_subject_by_uuid(Document,uuid1)# Using the subject labeldocs2=store.get_subject_by_uuid('Document',uuid2)
多按索引谓词
fromgitgraph.queryimportpredicate# functionalquery=lambdatitle:'Blog'intitle# DSLquery=predicate('title').contains('Blog')blog_documents=set(store.match_subjects_by_index(Document,'title',query))# With Regexquery=predicate('title').matches('([Bb]log|[Ee]ssa[yi]s?)')blogs_and_essays=set(store.match_subjects_by_index(Document,'title',query))
更新
docs1.title='new title'docs2.title='documento dois'docs2.body='<p>Hello</p>'store.merge(docs1,docs2)# recreate the doc1docs1=store.create(Document,uuid=uuid1,title='Essay',body='body1',)
删除
store.delete(docs1)store.commit()