teahouse-hosting / chaise

An async CouchDB python client library
0 stars 0 forks source link

Type query #40

Open AstraLuma opened 1 week ago

AstraLuma commented 1 week ago

Database.find_*() maybe should extend the CouchDB mango syntax with type:

{type: Foo, "spam": "eggs"}

So if your classes were:

class OldFoo(AttrsRegistry.Document, dbid="Foo1"):
    # spam is lowercase
    bar: str

class Foo(AttrsRegistry.Document, dbid="Foo2"):
    # spam is titlecase
    spam: str

The query {type: Foo, "spam": "eggs"} would then be compiled to:

{
    '$and': [
        {
            '$or': [
                {'': 'Foo1'},
                {'': 'Foo2'},
            ],
        },
        {
            'spam': 'egg',
        },
    ],
}

(I think the type query should be pulled out, so that it doesn't interact with a user-specified $or.)

Huly®: BRS-69

AstraLuma commented 1 week ago

Inner queries might become quite messy, like this:

{
    '$or': [
        {type: Foo, "spam": True},
        {type: Bar, "eggs": True},
    ]
}
AstraLuma commented 1 week ago

We should also support type unions as an or: {type: Foo | Bar}