Skip to main content

pymongodm

Project description

pymongodm
=========

pymongodm is a odm respecting pymongo functionality and adds
functionality such as model validation.

change your current orm by pymongodb.

Before:

.. figure:: http://i.imgur.com/8TTqJ9h.jpg
:alt: Imgur

Imgur
After:

.. figure:: http://i.imgur.com/NDna9Wp.jpg
:alt: Imgur

Imgur
https://pypi.python.org/pypi/pymongodm

install
-------

::

pip install pymongodm

connect db
----------

\`\`\`python import pymongodm

pymongodm.connect('name\_db') \`\`\`

or

\`\`\`python import pymongodm import pymongo

db = pymongo.MongoClient()['name\_db'] pymongodm.connect(db) \`\`\`

use db
------

\`\`\`python import pymongodm

pymongodm.connect('example\_db')

# Identical to pymongo pymongodm.db.nice\_collection.insert({'name':
'pepis'}) print(pymongodm.db.nice\_collection.find\_one()) \`\`\`

use models!
-----------

\`\`\`python import pymongodm pymongodm.connect("gstudio")

from pymongodm.models import Base

class User(Base): schema = {"name": {'type': str}, "other": {'type':
list, 'required': False}} # optional, default is class\_name + s
collection\_name = "random\_name"

::

def cut_name(self):
return self.name[:3]

insert
======

result = User({'name': 'pepito'}) print("id in db", result.\_id)

convert dict to object Model
============================

a = User({'\ *id': result.*\ id, 'name': result.name}) b =
User(result.getattrs()) # get attrs return only db attrs b =
User(result.get\_clean()) # not return except arguments (exclude\_view )

convert result finds to model
=============================

results = pymongodm.db.users.find().model(User) # or results =
User.collect.find().model(User) # or result = User(id)

for result in results: print(result.\ *id) print(result.name)
print(result.cut*\ name())

Modify values
=============

results = pymongodm.db.users.find().model(User) for result in results:
result.name = "Pymongodm\_%s" % result.name result.other = ["random",
"info"] result.update()

Remove
======

result.remove()

\`\`\`

Models options
~~~~~~~~~~~~~~

use other collection
^^^^^^^^^^^^^^^^^^^^

by default the name of the collection is the name of the class + s. It
can be changed with the following argument: collection =
"encoding\_profiles"

hidden arguments in returns
^^^^^^^^^^^^^^^^^^^^^^^^^^^

exclude\_view = ['name']

schemes allow the following parameters:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

- type
- required
- function

Rewrite basic methods
---------------------

Only need declare identic name in your class

.. code:: python


class User(Base):
schema = {"name": {'type': str},
"other": {'type': list, 'required': False}}
# optional, default is class_name + s
collection_name = "random_name"

def remove(self):
print("uhm ...")

Plugins
-------

TODO ...


- 1.0.4 (29-9-2016)
- support custom\_id

- 1.0.3 (28-9-2016)
- automatic creation

1.0.2 (18-7-2016)
=================

- add method insert()

1.0.1 (12-7-2016)
=================

- remove prints

1.0.0 (12-7-2016)
=================

- auto\_get = True
- disable automatic discover cache
- if you use auto\_get = False must make a .get() to get the data in
the class
- Add support Python 2

0.1.0 (11-7-2016)
=================

- Add collect property

0.0.5 (11-7-2016)
=================

- fix require=False and value None

0.0.4 (6-6-2016)
================

- Update readme

0.0.3 (6-6-2016)
================

- Update readme
- Fix minor bugs

0.0.2 (3-6-2016)
================

- Fix pip install

0.0.1 (3-6-2016)
================

- Initial version

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymongodm-1.0.4.tar.gz (5.9 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page