MongoFrames icon indicating copy to clipboard operation
MongoFrames copied to clipboard

Support for `TypedFrame` class

Open njordr opened this issue 9 years ago • 2 comments

Hi. It would be great if MongoFrame implements also a check of field type/structure.

Let me say I want to have all the documents of a certain type with the same _id structure:

class Test(Frame):
    _db = 'testdb'
    _collection = 'testcollection'
    _fields = {
        '_id': {
            'template': 'test_id_'
            'type': str
        },

so when I create a new Test class, i could do the following:

Test(_id=1234).insert()

and the result _id will be "test_id_1234"

In this way it's more simple also to document the structure of the document.

Let me know if this could be in the philosophy of MongoFrames or it's better to use an external validator. In the latter case, any advice?

Thanks

njordr avatar Dec 09 '16 10:12 njordr

Hi @njordr,

We have been looking at adding support for a TypedFrame class that would allow simple type validation for documents based on Python types. I've avoided this in general because of the performance overhead but I see no reason not to add it as something people can use optionally.

My personal preference when working with Mongo is to keep validation logic separate (for example within forms) but this isn't to everyones taste and I'm not convinced by any means I'm correct anyhow.

I'm working on a web development framework based on flask, MongoFrames (and a bunch of other open source libraries we're intending to release shortly) which is dividing my time (and that of my colleagues) across a wide array of tasks currently. I expect this to be the case until March when we hope to officially release the new web development framework, included in that planned work are a number of updates to MongoFrames including support for a TypedFrame class - but as of now I don't have a more accurate time frame than that I'm afraid.

anthonyjb avatar Dec 11 '16 19:12 anthonyjb

Thank you for your reply. I'll wait to see your web framework :)

njordr avatar Dec 11 '16 19:12 njordr