Skip to content

krisrogers/smobs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

SMOBS

SMOBS (Simple Mongo OBjectS) is a minimal, lightweight library for mapping MongoDB Documents to self-sufficient Python objects.

Examples

import smobs

# Setup DB connnection
smobs.init('TEST')

class Car(smobs.Document):
    """
    Car object.
    """
    
    def __after_init__(self):
        # Set some defaults
        if not hasattr(self, 'num_wheels'):
            self.num_wheels = 4
            
car1 = Car(make='Nissan', colour='Black')
car1.save()

car2 = Car(make='Toyota', colour='Red')
car2.save()

car3 = Car(make='Reliant', colour='Blue', num_wheels=3)
car3.save()

print 'There are {0} cars.'.format(Car.count())

Output: There are 3 cars.

print '{0} of them have 4 wheels.'.format(Car.count({'num_wheels' : 4}))

Output: 2 of them have 4 wheels.

print 'The Toyota is {0}.'.format(Car.find({'make' : 'Toyota'})[0].colour)

Output: The Toyota is Red.

for c in Car.all():
    c.delete()

Cleanup!

About

A simple Python object library for MongoDB

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages