GithubHelp home page GithubHelp logo

bwstearns / django-cassandra-engine Goto Github PK

View Code? Open in Web Editor NEW

This project forked from r4fek/django-cassandra-engine

0.0 3.0 0.0 136 KB

Django Cassandra Engine - the Cassandra backend for Django

License: BSD 2-Clause "Simplified" License

Python 100.00%

django-cassandra-engine's Introduction

Django Cassandra Engine

Latest Version https://travis-ci.org/r4fek/django-cassandra-engine.svg?branch=master Downloads

django-cassandra-engine is a database wrapper for Django Framework. It uses latest Cqlengine which is currently the best Cassandra CQL 3 Object Mapper for Python.

License:2-clause BSD
Keywords:django, cassandra, orm, nosql, database, python
URL (pypi):django-cassandra-engine

Requirements

  • cassandra
  • cqlengine
  • django-nonrel
  • djangotoolbox
  • django (1.6 or 1.7)

Features

  • complete Django integration
  • working syncdb and flush commands
  • support for creating/destroying test database
  • accept all Cqlengine connection options
  • automatic connection/disconnection handling
  • support for multiple databases (also relational)

Installation

Recommended installation:

pip install django-cassandra-engine

Usage

  1. Add django-cassandra-engine to INSTALLED_APPS in your settings.py file:

    INSTALLED_APPS += ('django_cassandra_engine',)
    

IMPORTANT: This app should be last on INSTALLED_APPS list.

  1. Also change DATABASES setting:

    DATABASES = {
        'default': {
            'ENGINE': 'django_cassandra_engine',
            'NAME': 'db',
            'TEST_NAME': 'test_db',
            'HOST': 'db1.example.com,db2.example.com',
            'OPTIONS': {
                'replication': {
                    'strategy_class': 'SimpleStrategy',
                    'replication_factor': 1
                }
            }
        }
    }
    
  2. Define some model:

    #  myapp/models.py
    import uuid
    from cqlengine import columns
    from cqlengine.models import Model
    
    class ExampleModel(Model):
        read_repair_chance = 0.05 # optional - defaults to 0.1
        example_id      = columns.UUID(primary_key=True, default=uuid.uuid4)
        example_type    = columns.Integer(index=True)
        created_at      = columns.DateTime()
        description     = columns.Text(required=False)
    
  3. Run ./manage.py syncdb

  4. Done!

Advanced usage

Sometimes you want to use cassandra database along with your RDMS. This is also possible! Just define your DATABASES like here:

from django_cassandra_engine.connection import ConsistencyLevel

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    },
    'cassandra': {
        'ENGINE': 'django_cassandra_engine',
        'NAME': 'db',
        'TEST_NAME': 'test_db',
        'HOST': '127.0.0.1',
        'OPTIONS': {
            'replication': {
                'strategy_class': 'SimpleStrategy',
                'replication_factor': 1
            },
            'connection': {
                'consistency': ConsistencyLevel.ONE,
                'lazy_connect': False,
                'retry_connect': False
                # + All connection options for cassandra.Cluster()
            }
        }
    }
}

Then run ./manage.py syncdb for your regular database and ./manage.py syncdb --database cassandra for Cassandra DB.

Links

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.