Skip to main content

A python orm with identity pattern mainly for arango

Project description

arorm

arango orm with identity pattern

examples

import typing
from arorm import ListProperty, Field, ObjectProperty, PasswordField, Model, ReferenceId, Reference, ReferenceIdList, ReferenceList, Store, RemoteReferenceList

class UserAttributes(ObjectProperty):
    class Settings(ObjectProperty):
        notifications = Field(default=False)
        html5Notifications = Field(default=False)
    last_update: float = Field(default=0)
    last_login: float = Field(default=0)
    settings = Settings()
    
class User(Model):
    __collection__ = 'users'
    name = Field()
    password = PasswordField(hidden=True)
    email = Field()
    attributes = UserAttributes()
    achievements: typing.List[str] = ListProperty(str)
    books: typing.List['Book'] = RemoteReferenceList('author_id', 'Book')

class Book(Model):
    __collection__ = 'books'
    author_id = ReferenceId()
    author = Reference(author_id, User)
    co_authors_ids = ReferenceIdList()
    co_authors: typing.List[User] = ReferenceList(co_authors_ids, User)

db = dict(host='127.0.01', user='root', password='root', port=8529, driver='arango')
store = Store(db)
store.setup_db()
user = store.create(User) # will create a user on commit
book = store.create(Book) # will create a book on commit
book.author = user
book.co_authors.append(user)

store.query(User).filter(User.name == 'admin').delete() # queued to be executed on commit

store.run_after_commit(lambda: print('did commit'))

store.commit()

user.to_json() # -> will now have _id, _rev
book.to_json() # -> will now have author_id set to same id as user

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

arorm-0.3.3.tar.gz (10.4 kB view hashes)

Uploaded Source

Built Distribution

arorm-0.3.3-py3-none-any.whl (10.1 kB view hashes)

Uploaded Python 3

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