Question

Ming supports GridFS start from 0.3 version, and i've used it in several Turbogears apps so far, but can't find any documentation of how to use GridFS with Ming,

This is what i've done so far, in my model store.py module :

#import statements

BookFile = fs.filesystem('books',DBSession.impl,)

class Book(MappedClass):
    """
    Book definition.
    """
    class __mongometa__:
        session = DBSession
        name = 'books'
        unique_indexes = [('title',),('author',),]

    _id = FieldProperty(s.ObjectId)
    title = FieldProperty(s.String)
    author = FieldProperty(s.String)
    isbn = FieldProperty(s.String)
    vendor = FieldProperty(s.String)
    _file = FieldProperty(s.ObjectId)

    def _get_file(self):
        return BookFile.m.find(dict(_id=self._file)).one()
    def _set_file(self, name, data):
        f = BookFile.m.put(name,data)
        self._file = f

    bookf = SynonymProperty(_get_file, _set_file)

As you can see, the fs.filesystem can't take an ODMSession (ThreadLocalODMSession in this case), so i have to drop down to basic ming.Session class by doing DBSession.impl.

What i'm worried is, Turbogears has been using ThreadLocalODMSession to adapt to multi-threaded environment, but what i'm doing above is giving the GridFS Connection the non thread-safe Session.

is that okay?
how should i do this correctly/safely?
Anyhelp would be appreciated, Thanks :)

Was it helpful?

Solution

The DBSession.impl should be fine, as the ming.Session doesn't store any data.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top