- Notifications
You must be signed in to change notification settings - Fork12
Pyoko is a Django-esque ORM for Riak KV
License
zetaops/pyoko
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation

- Nested class based data models (schemas).
- One-To-One, ManyToMany and ManyToOne relations.
- AND queries by using filter() and exclude() methods.
- Or, in, greater than, lower than queries.
- Query chaining and caching.
- Automatic Solr schema creation / update (one way migration).
- Row level access control, permission based cell filtering.
- Self referencing model relations.
- Automatic versioning on write-once buckets.
- Customizable activity logging to write-once buckets.
- Works with Riak 2.1 and up.
- Configurable auto-denormalization (aka reactive joins / write-timejoins) for relations.
- Custom migrations with migration history.
- CRDT based models.
Read the API documentation atpyoko.readthedocs.org.
Your project should within Python path, so you could be able to importit.
Base file structure of a Pyoko based project;
- manage.py:
frompyoko.manageimport*environ.setdefault('PYOKO_SETTINGS','``<PYTHON.PATH.TO.PROJECT>``.settings')ManagementCommands(argv[1:])
- settings.py
RIAK_SERVER='localhost'RIAK_PROTOCOL='http'RIAK_PORT='8098'# if not defined, will be searched within same directory as settings.py# MODELS_MODULE = '<PYTHON.PATH.OF.MODELS.MODULE>'
- models.py (or models package)
frompyokoimportModel,Node,ListNode,fieldclassPermission(Model):name=field.String("Name")code=field.String("Code Name")classMeta:verbose_name="Permission"verbose_name_plural="Permissions"def__unicode__(self):return"%s %s"% (self.name,self.code)classUnit(Model):name=field.String("Name")address=field.String("Address",null=True,blank=True)classMeta:verbose_name="Unit"verbose_name_plural="Units"def__unicode__(self):returnself.nameclassPerson(Model):first_name=field.String("Name")last_name=field.String("Surname")work=Unit(verbose_name="Work",reverse_name="workers")home=Unit(verbose_name="Home",reverse_name="residents")classContactInfo(Node):address=field.String("Address",null=True,blank=True)city=field.String("City")phone=field.String("Phone")email=field.String("Email")classPermissions(ListNode):perm=Permission()def__unicode__(self):returnself.permdef__unicode__(self):return"%s %s"% (self.first_name,self.last_name)defget_permission_codes(self):return [p.perm.codeforpinself.Permissions]defadd_permission(self,perm):self.Permissions(permission=perm)self.save()defhas_permission(self,perm):returnperminself.Permissionsdefhas_permission_code(self,perm_code):perm=Permission.object.get(code=perm_code)returnself.has_permission(perm)
from .modelsimportPerson,Unit,Permissionuser=Person(first_name='Bugs')user.last_name='Bunny'contact_info=user.ContactInfo(email="foo@foo.com",city="Izmir")contact_info.phone="55555555"user.work=Unit(name="Acme").save()user.home=Unit(name="Emac").save()user.save()
- Do not use Protocol Buffers in development, it doesn't give proper descriptions for server side errors.
- Use CamelCase for model, node and listnodes
- Use underscored names for fields
_idand_setare reserved suffixes for internal use. Do not suffix your fields with_idor_set.deletedandtimestampare implicitly added fields. Do not use these words as field names.- Set DEBUG to 1 or greater integer to enable query debugging which collects query stats under sys._debug_db_queries:
In [1]:importsysIn [2]:sys._debug_db_queriesOut[2]:[ {'BUCKET':'models_personel','QUERY':'-deleted:True','QUERY_PARAMS': {'rows':1,'sort':b'timestamp desc','start':0},'TIME':0.0056,'TIMESTAMP':1452245987.258094}, {'BUCKET':'models_personel','KEY':'Aqq2O50XGqerJsfOPquqDmINbyM','TIME':0.00229,'TIMESTAMP':1452245980.413088}, ]
- Set value of DEBUG to 5 or a greater integer to get instant print out of each executed query.
In [1]:Personel.objects.filter(ad__startswith='Al')Out[1]:QRY=>ad:Al*AND-deleted:True[<Personel:alig.>]
- If you want to enable logging and versioning, create and activate a bucket type with leveldb backend
riak-admin bucket-type create log_version'{"props": {"backend": "leveldb_mult"}}'riak-admin bucket-type activate log_versionCreate a bucket type named "pyoko_models" and activate it with following commands:
#!/bin/sh# 1 node development:./bin/riak-admin bucket-type create pyoko_models'{"props":{"last_write_wins":true, "dvv_enabled":false, "allow_mult":false, "n_val":1}}'# >= 3 node production:#./bin/riak-admin bucket-type create pyoko_models '{"props":{"consistent":true}}'./bin/riak-admin bucket-type activate pyoko_models
You need to define the following environmental variable to run tests.
PYOKO_SETTINGS='tests.settings'
to create or update schemas run the following command:
python manage.py migrate --model User,Permission
or
python manage.py migrate --model all
py.test command runs all the tests from tests directory.
Feel free to fork this and send back Pull Requests for anydefects or features that you want to contribute back.Opening issues here is also recommended.
If you need to get the attention of the ZetaOps team send an emailto info ~at~ zetaops.io.Commercial support fromZetaOps requires a valid support contract.
Locutus is not dead yet!
Pyoko is licensed under theGPL v3.0
About
Pyoko is a Django-esque ORM for Riak KV
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors10
Uh oh!
There was an error while loading.Please reload this page.