Last active
August 29, 2015 14:09
-
-
Save smn/306ddb1c3a4654ec4a7f to your computer and use it in GitHub Desktop.
elastic git sample code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/the_repository/ | |
*.pyc | |
/ve/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from elasticgit.models import Model, IntegerField, TextField | |
class Person(Model): | |
age = IntegerField('The Age') | |
name = TextField('The Name') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
elastic-git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
virtualenv ve | |
source ve/bin/activate | |
pip install -r requirements.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ve)$ cat model/Person/a4f6b610c4564673afe95c1d1ed1bffc.json | |
{ | |
"age": 34, | |
"_version": { | |
"package_version": "0.2.9", | |
"language_version": "2.7.6", | |
"language_version_string": "2.7.6 (default, Dec 22 2013, 09:30:03) \n[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)]", | |
"language": "python", | |
"package": "elastic-git" | |
}, | |
"name": "Simon", | |
"uuid": "a4f6b610c4564673afe95c1d1ed1bffc" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from elasticgit import EG | |
from model import Person | |
workspace = EG.workspace('the_repository') | |
simon = Person({ | |
'name': 'Simon', | |
'age': 34, | |
}) | |
workspace.save(simon, 'Saving Simon!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ve)$ python workspace2.py | |
I have found 1 people | |
name: Simon age: 34 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from elasticgit import EG | |
from model import Person | |
workspace = EG.workspace('the_repository') | |
people_count = workspace.S(Person).count() | |
print "I have found %s people" % (people_count,) | |
for person in workspace.S(Person): | |
print 'name:', person.name, 'age:', person.age |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from elasticgit import EG | |
from model import Person | |
workspace = EG.workspace('the_repository') | |
for count in range(20): | |
person = Person({ | |
'name': 'Person %s' % (count,), | |
'age': count, | |
}) | |
workspace.save(person, 'Saving person %s' % (count,)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ve)$ python workspace4.py | |
name: Person 15 age: 15 | |
name: Person 14 age: 14 | |
name: Person 13 age: 13 | |
name: Person 12 age: 12 | |
name: Person 11 age: 11 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from elasticgit import EG | |
from model import Person | |
workspace = EG.workspace('the_repository') | |
people_count = workspace.S(Person).count() | |
# Find all people in older than 10 up until and including 15. | |
people = workspace.S(Person).filter(age__gt=10, age__lte=15).order_by('-age') | |
for person in people: | |
print 'name:', person.name, 'age:', person.age |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ve)$ python workspace5.py | |
ES result <elasticgit.manager.PersonMappingType object at 0x10fbbd4d0> name: Person 10 | |
Git object <model.Person object at 0x10fbbd410> name: Person 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from elasticgit import EG | |
from model import Person | |
workspace = EG.workspace('the_repository') | |
people_count = workspace.S(Person).count() | |
# Find all people in older than 10 up until and including 15. | |
[es_result] = workspace.S(Person).filter(age=10) | |
print 'ES result', es_result, 'name:', es_result.name | |
git_object = es_result.get_object() | |
print 'Git object', git_object, 'name: ', git_object.name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ve)$ python workspace6.py | |
name: Person 10 age: 10 | |
name: Simon age: 34 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from elasticgit import EG, F | |
from model import Person | |
workspace = EG.workspace('the_repository') | |
people = workspace.S(Person).filter(F(age=10) | F(name='simon')) | |
for person in people: | |
print 'name:', person.name, 'age:', person.age |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment