示例#1
0
def setupStore():
    avatar_store.__init__(create_database(config['db']))

    if config.get('trace'):
        import sys
        from storm.tracer import debug
        debug(True, stream=sys.stdout)

    # Only sqlite uses this now
    sqlBundle = getCreationSQL(avatar_store)
    if not sqlBundle:
        return

    tableExists = sql['tableExists'] = sqlBundle['tableExists']

    for (table, creationSQL) in sqlBundle['creations']:

        if not tableExists(avatar_store, table):

            # Unlike log.message, this works during startup
            print "~~~ Creating Warp table '%s'" % table

            if not isinstance(creationSQL, tuple): creationSQL = [creationSQL]
            for sqlCmd in creationSQL:
                avatar_store.execute(sqlCmd)
            avatar_store.commit()
示例#2
0
    def __storm_flushed__(self):
        avatar_store.execute(DELETE_SQL, (self.__class__.__name__, self.id))

        if get_obj_info(self).get("store") is not None:
            
            vals = [v for v in self.getSearchVals() if v is not None]

            if vals:
                text = self._searchSeparator.join(vals).encode("utf-8")

                avatar_store.execute(INSERT_SQL,
                                     (self.__class__.__name__,
                                      self.id,
                                      self.getSearchLanguage(),
                                      text))
        avatar_store.commit()
示例#3
0
文件: store.py 项目: khangpn/warp
def setupStore():
    avatar_store.__init__(create_database(config['db']))

    if config.get('trace'):
        import sys
        from storm.tracer import debug
        debug(True, stream=sys.stdout)

    sqlBundle = getCreationSQL(avatar_store)
    tableExists = sql['tableExists'] = sqlBundle['tableExists']

    for (table, creationSQL) in sqlBundle['creations']:

        if not tableExists(avatar_store, table):

            # Unlike log.message, this works during startup
            print "~~~ Creating Warp table '%s'" % table

            if not isinstance(creationSQL, tuple): creationSQL = [creationSQL]
            for sqlCmd in creationSQL: avatar_store.execute(sqlCmd)
            avatar_store.commit()
示例#4
0
def search(term, language='english'):
    for modelName, doc_id in avatar_store.execute(SEARCH_SQL, (language, term.encode("utf-8"))):
        model = searchModels[modelName]
        yield avatar_store.get(model, doc_id)
示例#5
0
def reindex():
    import storm.database
    avatar_store.execute("DELETE FROM warp_fulltext")
    for klass in searchModels.itervalues():
        for obj in avatar_store.find(klass):
            obj.__storm_flushed__()