incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel ItaboraĆ­ <itabora...@gmail.com>
Subject Declarative validation of recursive documents
Date Tue, 13 Sep 2011 02:37:03 GMT
I'm pretty new to Couch and I'm trying to let go of my relational footing
for a little bit. This is going to sound a little like a crackpot rant, so
please bear with me for a second.

Relational databases are all about meaningfully linking simple tuples. The
validity of the "data graph" is maintained basically by how you identify and
how you relate such tuples.

In a document database all document are tree like structures. The database
itself is like a forrest of such trees. There is no joining. The validity of
a document is all in its structure and the validity of the "data forrest" is
achieved by making sure that every document adheres to some sort of tree
like schema.

I'm starting to think that "the fatter, the better" for documents, as along
as you don't hit some operational hiccups such as high probability of
concurrent writes.

It seems to me that it would be useful to be able to declaratively specify
this tree like schema to validate complex documents, something like the
following

    Doc(
        Field('left', Recursive()),
        Field('value', Number()),
        Field('right', Recursive())
    ).validate({
        'value': 10,
        'left': {
            'value': 5,
            'left': {'value': 2},
            'right': {'value': 6, 'right': {'value': 7}}
        }
    })

    or

    Doc(
        Field('subject', String()),
        Field('body', String()),
        Field('replies', Array(Recursive()))
    ).validate({
        'subject': 'Couch rulez',
        'body': '... and yet I suck',
        'replies': [
            {
                'subject': 'Re: Couch rulez',
                'body': 'this!',
                'replies': [{'subject': 'Re: Re: Couch rulez', 'body':
'Totally', 'replies':[]}]
            },
            {
                'subject': 'Spam',
                'body': 'Buy something crappy',
                'replies': []
            }
        ]
    })

I banged away at the keyboard until I got this
http://pastebin.com/N8cv1mYn(it ain't pretty and is probably filled
with errors) ... and I'm not sure if
it is something worth pursuing.

Is this sort of thing useful? And more importantly, is there anything
that already does this better?

Thanks,
Daniel

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message