Skip to main content

No project description provided

Project description

https://travis-ci.org/gabrielfalcao/gitgraph.svg?branch=master

Instalation

pip install gitgraph

Declaring Subjects

from gitgraph import GitGraph
from gitgraph import Subject

store = GitGraph('my-git-cms')

class Document(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,
    }

Create

uuid1 = 'deadbeefdeadbeefdeadbeefdeadbeef'

# providing your own uuid
docs1 = store.create(
    'Document',
    uuid=uuid1,
    title='Essay',
    body='body1',
)

# auto-generated uuid
docs2 = store.create(
    Document,
    title='Blog',
    body='body2',
)

store.commit()

uuid2 = docs2.uuid

Retrieve

One By UUID

# Using the class Document as subject type
docs1 = store.get_subject_by_uuid(Document, uuid1)

# Using the subject label
docs2 = store.get_subject_by_uuid('Document', uuid2)

Many By Indexed Predicate

from gitgraph.query import predicate
# functional
query = lambda title: 'Blog' in title

# DSL
query = predicate('title').contains('Blog')
blog_documents = set(store.match_subjects_by_index(Document, 'title', query))

# With Regex
query = predicate('title').matches('([Bb]log|[Ee]ssa[yi]s?)')
blogs_and_essays = set(store.match_subjects_by_index(Document, 'title', query))

Update

docs1.title = 'new title'

docs2.title = 'documento dois'
docs2.body = '<p>Hello</p>'

store.merge(docs1, docs2)

# recreate the doc1
docs1 = store.create(
    Document,
    uuid=uuid1,
    title='Essay',
    body='body1',
)

Delete

store.delete(docs1)
store.commit()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gitgraph-0.1.1.tar.gz (14.9 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page