Giter Site home page Giter Site logo

repocket's Introduction

Repocket

Simple active record for redis. Drop-in replacement for CQLEngine

image

Why

I needed an active record that worked almost as a drop-in replacement for CQLEngine.

Long-story-short I had a project where I originally wrote the db layer usign cassandra, through CQLEngine. It became an overkill and I decided to use redis instead.

There is a pretty good documentation available and more importantly I commited to 100% of unit and functional test coverage. This code is battle ready for production, if you find any bugs in it you can fix within minutes.

That also means that collaboration is easy, just don't break anything, don't delete tests and add as test coverage to you collaboration: when fixing a bug, write at least one test to reproduce the problem in an automated way.

If you want a new feature, please feel free to open a ticket and request, someone might make your dreams come true. Better yet, submit a pull request; just please remember to write tests and documentation for your contributions.

Quick Usage

$ pip install repocket

Declare your models

>>> from repocket import attributes
>>> from repocket import ActiveRecord
>>>
>>>
>>> class User(ActiveRecord):
...     name = attributes.Unicode()
...     house_name = attributes.Unicode()
...     email = attributes.Bytes()
...     password = attributes.Bytes()
...     metadata = attributes.JSON()

Persist in redis

>>> import bcrypt

>>> harry = User(
...     id='970773fa-4de1-11e5-86f4-6c4008a70392',
...     name='Harry Potter',
...     email='[email protected]',
...     house_name='Gryffindor',
...     password=bcrypt.hashpw(b'hermione42', bcrypt.gensalt(10)),
...     metadata={
...         'known_tricks': [
...             "Protego",
...             "Expelliarmus",
...             "Wingardium Leviosa",
...             "Expecto Patronum"
...         ]
...     }
... )
>>> redis_keys_for_harry = harry.save()
>>>
>>> ron = User.create(
...     id='40997aa4-71fc-4ad3-b0d7-04c0fac6d6d8',
...     name='Ron Weasley',
...     house_name='Gryffindor',
...     email='[email protected]',
...     password=bcrypt.hashpw(b'hermione42', bcrypt.gensalt(10)),
...     metadata={
...         'known_tricks': [
...             "Protego",
...             "Expelliarmus",
...         ]
...     }
... )

Query

>>> harry = User.objects.get(id='970773fa-4de1-11e5-86f4-6c4008a70392')
>>> harry.metadata

>>> results = User.objects.filter(house_name='Griffindor')
>>> len(results)
>>> results[0] == harry
True

>>> results[1] == ron
True

repocket's People

Contributors

gabrielfalcao avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

adamchainz

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.