https://github.com/patricklx/ar-orm
arango orm with identity pattern
https://github.com/patricklx/ar-orm
Last synced: 13 days ago
JSON representation
arango orm with identity pattern
- Host: GitHub
- URL: https://github.com/patricklx/ar-orm
- Owner: patricklx
- License: mit
- Created: 2021-04-06T11:35:14.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-06-22T11:22:38.000Z (about 3 years ago)
- Last Synced: 2025-06-27T15:06:20.926Z (13 days ago)
- Language: Python
- Size: 31.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# arorm
arango orm with identity pattern## examples
```python
import typing
from arorm import ListProperty, Field, ObjectProperty, PasswordField, Model, ReferenceId, Reference, ReferenceIdList, ReferenceList, Store, RemoteReferenceListclass 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
```