GithubHelp home page GithubHelp logo

pombredanne / flywheel Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stevearc/flywheel

0.0 1.0 0.0 1.07 MB

Object mapper for Amazon's DynamoDB

License: MIT License

Makefile 2.59% Python 96.85% Shell 0.56%

flywheel's Introduction

Flywheel

Master Build:build coverage
0.2 Build:build-0.2 coverage-0.2
0.3 Build:build-0.3 coverage-0.3
Documentation:http://flywheel.readthedocs.org/
Downloads:http://pypi.python.org/pypi/flywheel
Source:https://github.com/mathcamp/flywheel

Object mapper for Amazon's DynamoDB

Getting Started

This is what a basic model looks like (schema taken from this DynamoDB API documentation)

from flywheel import Model, Field, GlobalIndex

class GameScore(Model):
    __metadata__ = {
        'global_indexes': [
            GlobalIndex('GameTitleIndex', 'title', 'top_score')
        ],
    }
    userid = Field(hash_key=True)
    title = Field(range_key=True)
    top_score = Field(data_type=int)
    top_score_time = Field(data_type=datetime)
    wins = Field(data_type=int)
    losses = Field(data_type=int)

    def __init__(self, title, userid):
        self.title = title
        self.userid = userid

Create a new top score:

>>> score = GameScore('Master Blaster', 'abc')
>>> score.top_score = 9001
>>> score.top_score_time = datetime.utcnow()
>>> engine.sync(score)

Get all top scores for a user:

>>> scores = engine.query(GameScore).filter(userid='abc').all()

Get the top score for Galaxy Invaders:

>>> top_score = engine.query(GameScore).filter(title='Galaxy Invaders')\
...     .first(desc=True)

Atomically increment a user's "wins" count on Alien Adventure:

>>> score = GameScore('Alien Adventure', 'abc')
>>> score.incr_(wins=1)
>>> engine.sync(score)

Get all scores on Comet Quest that are over 9000:

>>> scores = engine.query(GameScore).filter(GameScore.top_score > 9000,
...                                         title='Comet Quest').all()

flywheel's People

Contributors

hoov avatar stevearc avatar

Watchers

 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.