Skip to main content

Simple DRM for motor client

Project description

pipeline status coverage report pypi link

MDocument is a simple ORM for MongoDB with addition of relations.

Usage

There are two ways of using mdocument: 1. Specify database, colleciton and client in class. 2. Use modified mongo motor client.

Specifying document parameters in class

import asyncio

import motor.motor_asyncio

from mdocument import MDocument, relations, model

client = motor.motor_asyncio.AsyncIOMotorClient()

class Video(MDocument):
    __collection__ = "videos"
    __database__ = "mdocument"
    __client__ = client

    class Model(MDocument.Model):
        title = model.Field(str)
        views_count = model.Field(int)
        public_id = model.Field(str, unique=True)

class Comment(MDocument):
    __collection__ = "comments"
    __database__ = "mdocument"
    __client__ = client

    class Model(MDocument.Model):
        text = model.Field(str)
        video = model.FieldSync(Video, relation=relations.RelationOneToMany, synced_fields=["_id", "title"])


async def main():
    video = await Video.create({"title": "Test"})

    comment1 = await Comment.create(
        video=video._id,
        message="First!",
    )

    comment2 = await Comment.create(
        video=video._id,
        message="Second!"
    )

loop = asyncio.get_event_loop()
loop.run_until_complete(main())

Now we can easily access our comments using our related documents

TODO: REWRITE DOCUMENTATION!

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

mdocument-4.0.1612475595.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

mdocument-4.0.1612475595-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file mdocument-4.0.1612475595.tar.gz.

File metadata

  • Download URL: mdocument-4.0.1612475595.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for mdocument-4.0.1612475595.tar.gz
Algorithm Hash digest
SHA256 ff636cb48cd172dd48244d8f1c3ffb6d037a3d6e5a4589118e246192a6e02658
MD5 e191fd94b3bc9fb7de6c55884da82c90
BLAKE2b-256 9bf29e583e3752447926f16ce55d259641c4cf54abeb14bf5b6346d7b4030a1a

See more details on using hashes here.

File details

Details for the file mdocument-4.0.1612475595-py3-none-any.whl.

File metadata

  • Download URL: mdocument-4.0.1612475595-py3-none-any.whl
  • Upload date:
  • Size: 13.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for mdocument-4.0.1612475595-py3-none-any.whl
Algorithm Hash digest
SHA256 85d854f89ea851508ad7499bc7e4357707b793ba9ef18dd3fa01d65dd3287f98
MD5 1f8314bb90ec58f954a5a1d3cfc2a013
BLAKE2b-256 436533ab6496cc0d2270b964761c1eb2cbc2badb9035e55625050a9d68606fab

See more details on using hashes here.

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