Code Monkey home page Code Monkey logo

pythonormsleepy's Introduction

Python ORM/ODM Examples, For The Sleepy

The same RESTful API (an inventory app), implemented using different ORM/ODMs--a sort of "Hello World" tour of Python data mapper libraries.

Each example demonstrates the syntax for declaring models as well as basic querying, inserting, updating, and deleting of records.

Featuring. . .

SQLAlchemy (Relational DBs)

Full Example

hour_ago  = datetime.utcnow() - timedelta(hours=1)
recent_items = Item.query.filter(Item.checked_out &
                                (Item.updated > hour_ago)) \
                                .order_by(Item.updated.desc()).all()

Peewee (Relational DBs)

Full Example

hour_ago  = datetime.utcnow() - timedelta(hours=1)
recent_items =Item.select().where(Item.checked_out &
                                (Item.updated > hour_ago)) \
                                .order_by(Item.updated.desc())

Mongoengine (MongoDB)

Full Example

hour_ago  = datetime.utcnow() - timedelta(hours=1)
recent_items = Item.objects(checked_out=True, updated__gt=hour_ago)\
                            .order_by("-updated")

Stdnet (Redis)

Full Example

hour_ago  = datetime.utcnow() - timedelta(hours=1)
recent_items = models.item.filter(checked_out=True, updated__gt=hour_ago)\
                                .sort_by("-updated").all()

Pony (Relational DBs)

Full Example

hour_ago  = datetime.utcnow() - timedelta(hours=1)
recent_items = orm.select(item for item in Item
                                if item.checked_out and
                                    item.updated > hour_ago)\
                                    .order_by(Item.updated.desc())[:]

. . . and more to come.

Each of these was put to REST by Flask, Flask-Classy, and marshmallow.

Running an example

First, install dependencies.

$ pip install -r requirements.txt

Then run the example of your choice.

$ python sleepy/api_sqlalchemy.py

Browser interface

An interactive browser interface is included to test out the REST API.

Browser interface

To use the browser interface, run an example and browse to http://localhost:5000.

"Why isn't _____ included here?"

To which I respond: Why don't you fork this project?

License

MIT Licensed.

pythonormsleepy's People

Contributors

amalashkevich avatar j-martin avatar sloria avatar

Watchers

 avatar  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.