Skip to main content

JSON Object storage backed by Git & Elastic Search

Project description

Adventures in an declarative object-y thing backed by Git and using Elastic Search as a query backend.

https://travis-ci.org/smn/elastic-git.svg?branch=develop https://coveralls.io/repos/smn/elastic-git/badge.png?branch=develop

Usage

from elasticgit.manager import EG
from elasticgit.models import Model, IntegerField, TextField


workspace = EG.workspace('/Users/sdehaan/Desktop/test-repo/')
workspace.setup('Simon de Haan', 'simon@praekeltfoundation.org')


"""
# The model looks like this

class Person(Model):
    age = IntegerField('The Age')
    name = TextField('The Name')
"""
from elasticgit.tests.base import TestPerson as Person

person1 = Person({'age': 10, 'name': 'Foo'})
workspace.save(person1, 'Saving Person 1')

person2 = Person({'age': 20, 'name': 'Bar'})
workspace.save(person2, 'Saving Person 2')

person3 = Person({'age': 30, 'name': 'Baz'})
workspace.save(person3, 'Saving Person 3')

Data is now persisted in a git repository and is queryable via elastic search:

>>> from elasticgit.manager import EG
>>> from elasticgit.tests.base import TestPerson as Person
>>> workspace = EG.workspace('/Users/sdehaan/Desktop/test-repo/')
>>> for person in workspace.S(Person).filter(age__gte=20):
...     print person.get_object(), dict(person.get_object())
...
<elasticgit.tests.base.TestPerson object at 0x10f906d90> {'age': 20, 'uuid': u'9890c5813fc14fcd82a3ec3751a1b1fe', 'name': u'Bar'}
<elasticgit.tests.base.TestPerson object at 0x10f906d90> {'age': 30, 'uuid': u'4b5c33de63034205ac23b746ee93344b', 'name': u'Baz'}
>>> for person in workspace.S(Person).query(name__match='Baz'):
...     print person.get_object(), dict(person.get_object())
...
<elasticgit.tests.base.TestPerson object at 0x10f906d90> {'age': 30, 'uuid': u'4b5c33de63034205ac23b746ee93344b', 'name': u'Baz'}
>>>

Git log output of the repository

commit 89afa833e4c537293a5f21d4e867cd061ece82a9
Author: Simon de Haan <simon@praekeltfoundation.org>
Date:   Tue Oct 7 15:23:30 2014 +0200

    Saving Person 3

diff --git a/elasticgit.tests.base/TestPerson/4b5c33de63034205ac23b746ee93344b.json b/elasticgit.tests.base/TestPerson/4b5c33de63034205ac23b746ee93344b.json
new file mode 100644
index 0000000..03d55b8
--- /dev/null
+++ b/elasticgit.tests.base/TestPerson/4b5c33de63034205ac23b746ee93344b.json
@@ -0,0 +1,5 @@
+{
+  "age": 30,
+  "uuid": "4b5c33de63034205ac23b746ee93344b",
+  "name": "Baz"
+}
\ No newline at end of file

commit bc3b779ade98dacfdcb181dd6a24bc4c9350bdd3
Author: Simon de Haan <simon@praekeltfoundation.org>
Date:   Tue Oct 7 15:23:28 2014 +0200

    Saving Person 2

diff --git a/elasticgit.tests.base/TestPerson/9890c5813fc14fcd82a3ec3751a1b1fe.json b/elasticgit.tests.base/TestPerson/9890c5813fc14fcd82a3ec3751a1b1fe.json
new file mode 100644
index 0000000..3fb0070
--- /dev/null
+++ b/elasticgit.tests.base/TestPerson/9890c5813fc14fcd82a3ec3751a1b1fe.json
@@ -0,0 +1,5 @@
+{
+  "age": 20,
+  "uuid": "9890c5813fc14fcd82a3ec3751a1b1fe",
+  "name": "Bar"
+}
\ No newline at end of file

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

elastic-git-0.1.2.tar.gz (7.9 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page