GithubHelp home page GithubHelp logo

aryanet / alexandra Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dziegler/alexandra

2.0 2.0 1.0 83 KB

An abstraction layer for using Cassandra with Django

Home Page: http://github.com/dziegler/alexandra

License: Other

alexandra's Introduction

alexandra

alexandra is a thin abstraction over pycassa to interact with Cassandra from Django.

Installation

Requires Django and pycassa 0.20 or greater:

pip install -e git+http://github.com/dziegler/alexandra.git#egg=alexandra  

add CASSANDRA_CLUSTER and CASSANDRA_KEYSPACE to settings.py :

CASSANDRA_CLUSTER = ['localhost:9160']
CASSANDRA_KEYSPACE = 'my_keyspace'

Sample Usage

Syntax for model definition is similar to Django's, but because rows can have as many columns as you want, there's no need to define them. :

import pycassa
from alexandra import cass

class EventManager(cass.Manager):

    def get_for_uuid(self, uuid):
        return self.get(uuid)

class Event(cass.ColumnFamily):
    """
    Event = {
        "89c23f26377e439a8e52fadec8f6bf19" = {
            "uuid": "804e39e29a6148039633e5a69f0c0870",
            "action": "landing:home"
            "ip_address": "127.0.0.1",
            "gender": "1",
        }
        ...
    }
    """
    objects = EventManager()

    class Meta:
        # defaults to pycassa.ConsistencyLevel.ONE
        read_consistency_level = pycassa.ConsistencyLevel.ONE 
        # defaults to pycassa.ConsistencyLevel.ONE
        write_consistency_level = pycassa.ConsistencyLevel.QUORUM
        # defaults to settings.CASSANDRA_KEYSPACE
        keyspace = 'another_keyspace' 
        # defaults to False. Set to True if this is a super column family
        super_cf = False 


    def save(self, *args, **kwargs):
        super(Event, self).save(*args, **kwargs)
        TrackingUUID.objects.add_event(self['uuid'], self.pk)

Queries use the pycassa query api, along with whatever other methods you want to define in your manager. :

import uuid

event = Event()
event['uuid'] = "804e39e29a6148039633e5a69f0c0870"
event['action'] = 'landing: home'
event['gender'] = "1"
event.pk = uuid.uuid4().hex
event.save()

# or you could do this
event = Event(uuid="804e39e29a6148039633e5a69f0c0870", action='landing: home', gender='1')
Event.objects.insert(uuid.uuid4().hex, event)

alexandra's People

Contributors

dziegler avatar

Stargazers

Julian avatar Arya Goudarzi avatar

Watchers

Arya Goudarzi avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.