Skip to main content

Zerorm is a simple wrapper for three amazing packages. This repository is the place where TinyDB, Schematics and Lifter together look like Django ORM.

It’s still work in progress and not everything looks like Django ORM, but it will.

Installation

pip install zerorm

Usage

First create a file with models and database instance attached to every model:

from zerorm import db, models

database = db('db.json')


class Message(models.Model):
    author = models.StringType(required=True)
    author_email = models.EmailType()
    text = models.StringType()
    views = models.IntType(min_value=0)

    class Meta:
        database = database

Now create some objects:

>>> from models import Message
>>>
>>> bob_message = Message(author='Bob',
...                       author_email='bob@example.com',
...                       text='Hello, everyone!')
>>> bob_message
<Message: Message object>
>>> bob_message.save()  # Save object
1
>>>
>>> bob_message.views = 3
>>> bob_message.save()  # Update object
>>>
>>> alice_message = Message.objects.create(author='Alice',
...                                        text='Hi, Bob!',
...                                        views=0)
>>> alice_message
<Message: Message object>

And try to retrieve them via objects

>>> Message.objects.all()
<QuerySet, len() = 2>
>>> list(Message.objects.all())
[<Message: Message object>, <Message: Message object>]
>>>
>>> second_message = Message.objects.get(eid=2)
>>> second_message.author
'Alice'
>>>
>>> Message.objects.filter(views__gte=3)  # Only Bob's message has 3 views
<QuerySet, len() = 1>
>>> list(Message.objects.filter(views__gte=3))
[<Message: Message object>]

You can also redefine model’s __str__ method for better repr just like in Django.

class Message(models.Model):
    ...

    def __str__(self):
        return 'by {}'.format(self.author)
>>> list(Message.objects.all())
[<Message: by Bob>, <Message: by Alice>]

License

MIT. See LICENSE for details.

Metadata

Release files for zerorm 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for zerorm 0.2.0
File Size Uploaded
zerorm-0.2.0.tar.gz 3.4 kB Details

Release files / zerorm-0.2.0.tar.gz

Download URL zerorm-0.2.0.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
52c7d71abe913fbe854f3d129ef5734320202b23a3eccbe82c80e6d2a7f25afe
BLAKE2b-256 checksum
How to use checksums
0ab7c31cec17ed84772c4a08c2e8b601117e1089e2c1446f80e65ea2b256d4d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.2.0 This release

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page