Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add local db support with neo4j #47

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft

Conversation

rokroskar
Copy link
Member

@rokroskar rokroskar commented Sep 22, 2020

This adds simple support for retrieving missing data from a neo4j instance.

Given this setup:

class Author:
    def __init__(self, _id, name, organization):
        self._id = _id
        self.name = name

class Book:
    def __init__(self, _id, name, author):
        self._id = _id
        self.name = name
        self.author = author

class AuthorSchema(JsonLDSchema):
    """Author schema."""
    name = fields.String(schema.name)
    _id = fields.Id()

    class Meta:
        """Meta class."""
        rdf_type = schema.Person
        model = Author

class BookSchema(JsonLDSchema):
    _id = fields.Id()
    name = fields.String(schema.name)
    author = fields.Nested(schema.author, AuthorSchema, missing=None)

    class Meta:
        rdf_type = schema.Book
        model = Book

One can retrieve the data for a single book with

from calamus.backends.neo4j import CalamusNeo4JBackend
neo = CalamusNeo4JBackend()
neo.initialize()

data = neo.fetch_by_id('http://example.com/books/1')

The full data, including the author information can then be obtained with

book = BookSchema(session=neo).load(data)

A full example

addresses #10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants