GridFS in Ming

71 views
Skip to first unread message

Panjie Setiawan Wicaksono

unread,
Aug 4, 2012, 8:03:50 AM8/4/12
to turbo...@googlegroups.com
Hi all,
is there anywhere i can read about using GridFS with Ming in TG2 ?
Ming supports GridFS start from 0.3 version, and i've used this in several apps so far, but can't find any documentation of how to use GridFS with Ming,
Any help would be appreciated, thanks :)

Panjie Setiawan Wicaksono

unread,
Aug 7, 2012, 4:39:03 PM8/7/12
to turbo...@googlegroups.com
anyone?
this is what i did so far, in my model module store.py :

from ming import schema as s, Field
from ming.odm import FieldProperty, ForeignIdProperty, RelationProperty
from ming.odm import Mapper
from ming.odm.declarative import MappedClass
from ming import fs
from tgming import SynonymProperty, ProgrammaticRelationProperty
import os
from session import DBSession

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 :)
Reply all
Reply to author
Forward
0 new messages