Skip to content

Latest commit

History

68 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

ognom

Build StatusLatest Version

Documentation: #TODO

Ognom is object-to-document mapper for mongodb. Currently ognom uses pymongo as default backend, but you can easily implement your own backend based on another driver (for example asyncio-mongo) if needed, as serialization and storage logic in ognom are separated.

Supports python2.7+, python3.3+, PyPy.

Documentation: #TODO

Install

pipinstallognom

Tests

tox

Features

  • Vanilla python, no dependencies;
  • From version 1.0 exposes full pymongo API(!);
  • Easy to write your own backend with your own API.

Quickstart

fromognom.baseimportConnectionManager, Document, Collectionfromognom.fieldsimportStringField, IntFieldConnectionManager.connect({
'main': { # ognom use aliases for databases to make it possible to use multiple db's per project'name': 'birzha_main',
'args': ['127.0.0.1:27017'],
'kwargs': {'socketTimeoutMS': 60000}},})
classFoo(Document):
objects=Collection(
db_name='main'collection_name='my_foos'# collection name (by default 'foos')indexes=[{
'index': [('bar', 1), ('baz', -1)],
'background': True}])
bar=StringField(required=True, default='baaar')
baz=IntField(choices=[10, 20, 30, 40, 50])
foo1=Foo.objects.create({'bar': 'lalala'})
assertFoo.objects.get({'bar': 'lalala'}).id==foo1.idfoo2=Foo(bar='lololo', baz=10)
assertfoo2.idisNonefoo2.save()
assertfoo2.idisnotNonefoo2.remove()
foos=Foo.objects.find({'bar': 'lalala'}) # not list but CursorWrapper!assertlen(list(foos)) ==1

Contributors

About

No description, website, or topics provided.

Resources

Stars

3 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages