Giter VIP home page Giter VIP logo

pureodm's Introduction

pureodm

A super-lightweight object-document mapper for Python and MongoDB.

It is so lightweight, all it does is provide a way for you to structure your data, and that's it! It leaves all of the index creation, and connection management, to you. At some point in the future, however, there may be some functionality added that provides you with some shortcuts to doing things like creating indexes.

Why another ODM?

Basically, I am sick-n'-tired of other ODMs doing a ton of work behind the scenes, and making some jobs harder than they need to be. One of the main reasons pureodm does not manage database connections for you, is because that would duplicate the functionality provided by the pymongo driver, but at the same time abstract away from it, and make certain tasks more difficult.

Which tasks am I referring to? Suppose you want to establish multiple connections to multiple databases - from the same process - and while all of their data may be identical in structure, it must be kept separate for one reason or another.

In case you are wondering, yes, this has come up before, and no, there was no viable solution other than using just pymongo.

Now, it should be mentioned that using the term "ODM" here, is a serious misnomer. All pureodm does, is provide you with a way to declare your data structures, and from that, generate dicts that can be passed directly to any of the methods of a pymongo.collection.Collection object.

What are the benefits?

  • You establish the connections to the databases
  • Absolutely nothing is done behind your back - not even index creation

Dependencies

  • pymongo (>=2.4.1)

Despite there having been almost an entire year since the last release of pureodm, the version of PyMongo does not need to change, and impose an artificial version number that pureodm does not realistically make use of.

That being said though, you should really be using the latest version of PyMongo.

pureodm's People

Contributors

nesv avatar

Stargazers

 avatar Jake avatar Zach McGrenere avatar Nick Coutsos avatar  avatar Thomas A Caswell avatar Tomás Dowling avatar Adam Presley avatar  avatar Kevin Lewandowski avatar  avatar

Watchers

 avatar James Cloos avatar Nick Coutsos avatar  avatar

pureodm's Issues

Add support for field encoding/decoding

Just a thought: implement encoders and decoders for fields. The initial thinking, here, is to pass the value we are setting to the attribute through the encoder on its way in, and then (optionally) passing it through a decoder on the way out. Here is an example using base64 encoding:

import base64
import pureodm

class MyModel(pureodm.Model):
    fields = {
        'an_image': {
            'type': unicode,
            'encoder': base64.b64encode,
            'decoder': base64.b64decode
        }
    }

(For those doubting the validity of this example, I have done something very similar in the past, with storing images.)

Add Model.find_one_in() method

Add a class method miniodm.Model.find_one_in() which is almost identical to miniodm.Model.find_in() but will only return the first result from the query.

See find_one (pymongo documentation).

Fix argument list to Model.find_in()

In miniodm/models.py:135 there is a typo in the argument list to the miniodm.Model.find_in() class method. It should read:

def find_in(cls, collection, spec=None, **kwargs):

Add in model-type safety

Because the Model.save_to() method just takes a pymongo.collection.Collection object, it is probably prudent to add in a string field that specifies a "type name" for that model.

You should be able to save any model to any collection. At the same time, you will need to map the documents returned from a query to a model, which will ultimately fail if you have models of various types co-existing in the same collection.

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.