Skip to content
/ pyoko Public
forked from zetaops/pyoko

Pyoko is a Django-esque ORM for Riak KV

License

Notifications You must be signed in to change notification settings

kunthar/pyoko

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PYOKO

A Django-esque ORM for Riak KV

Supported Features

  • Supports latest Riak (2.1.1)
  • Nested class based data models (schemas).
  • AND queries by using filter() and exclude() methods.
  • Query chaining and caching.
  • Automatic Solr schema creation / update (one way migration).
  • One-To-One, ManyToMany and ManyToOne relations with auto denormalization (aka reactive joins / write-time joins)
  • Row level access control, permission based cell filtering.

Work in progress

  • More pythonic APIs for Solr's extensive query features. (OR queries, searching in list of values)
  • Self referencing model relations.

Planned

  • Auto retry of failed writes (on strongly consistent buckets).
  • Automatic versioning on write-once buckets.
  • Custom migrations with migration history.
  • CRDT based models.

Setup / Configuration

Your project should within Python path, so you could be able to import it.

Base file structure of a Pyoko based project;

  • manage.py:
    from pyoko.manage import *
    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)
    from pyoko import Model, Node, field

    class User(Model):
        first_name = field.String("Name", index=True)
        last_name = field.String("Surname", index=True)


        class ContactInfo(Node):
            address = field.String("Address", index=True, null=True, blank=True)
            city = field.String("City", index=True)
            phone = field.String("Phone", index=True)
            email = field.String("Email", index=True)

    class Employee(Model):
        usr = User()
        role = field.String(index=True)

Usage

See tests for more usage examples.

        from my_project.models import User, Employee

        user = User(name='John')
        user_cont_info = user.ContactInfo(email="foo@foo.com", city="Izmir")
        user_cont_info.phone = "902327055555"
        user.save()
        employee = Employee(role='Coder', usr=user).save()
        emp_from_db = Employee.objects.get(employee.key)
        for emp in Employee.objects.filter(role='Coder'):
            print(emp.usr.name, emp.usr.ContactInfo.email)

Developer Notes

- Do not use Protocol Buffers in development, it doesn't give proper descriptions for server side errors.

Tests

Create 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, "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 update_schema --bucket \<model_name\>,\<model_name\>

or

python manage.py update_schema --bucket all

py.test command runs all the tests from tests directory.

License

GPL v3.0

About

Pyoko is a Django-esque ORM for Riak KV

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 99.8%
  • Shell 0.2%