当前位置: 首页>>代码示例>>Python>>正文


Python orm.make_transient函数代码示例

本文整理汇总了Python中sqlalchemy.orm.make_transient函数的典型用法代码示例。如果您正苦于以下问题:Python make_transient函数的具体用法?Python make_transient怎么用?Python make_transient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了make_transient函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: check_pdf_urls

def check_pdf_urls(pdf_urls):
    for url in pdf_urls:
        make_transient(url)

    # free up the connection while doing net IO
    safe_commit(db)
    db.engine.dispose()

    req_pool = get_request_pool()

    checked_pdf_urls = req_pool.map(get_pdf_url_status, pdf_urls, chunksize=1)
    req_pool.close()
    req_pool.join()

    row_dicts = [x.__dict__ for x in checked_pdf_urls]
    for row_dict in row_dicts:
        row_dict.pop('_sa_instance_state')

    db.session.bulk_update_mappings(PdfUrl, row_dicts)

    start_time = time()
    commit_success = safe_commit(db)
    if not commit_success:
        logger.info(u"COMMIT fail")
    logger.info(u"commit took {} seconds".format(elapsed(start_time, 2)))
开发者ID:Impactstory,项目名称:sherlockoa,代码行数:25,代码来源:queue_pdf_url_check.py

示例2: test_deleted_flag

    def test_deleted_flag(self):
        users, User = self.tables.users, self.classes.User

        mapper(User, users)

        sess = sessionmaker()()

        u1 = User(name='u1')
        sess.add(u1)
        sess.commit()

        sess.delete(u1)
        sess.flush()
        assert u1 not in sess
        assert_raises(sa.exc.InvalidRequestError, sess.add, u1)
        sess.rollback()
        assert u1 in sess

        sess.delete(u1)
        sess.commit()
        assert u1 not in sess
        assert_raises(sa.exc.InvalidRequestError, sess.add, u1)

        make_transient(u1)
        sess.add(u1)
        sess.commit()

        eq_(sess.query(User).count(), 1)
开发者ID:DeepakAlevoor,项目名称:sqlalchemy,代码行数:28,代码来源:test_session.py

示例3: new_version

    def new_version(self, session):
        # convert to an INSERT
        make_transient(self)
        self.id = None

        # history of the 'elements' collection.
        # this is a tuple of groups: (added, unchanged, deleted)
        hist = attributes.get_history(self, "elements")

        # rewrite the 'elements' collection
        # from scratch, removing all history
        attributes.set_committed_value(self, "elements", {})

        # new elements in the "added" group
        # are moved to our new collection.
        for elem in hist.added:
            self.elements[elem.name] = elem

        # copy elements in the 'unchanged' group.
        # the new ones associate with the new ConfigData,
        # the old ones stay associated with the old ConfigData
        for elem in hist.unchanged:
            self.elements[elem.name] = ConfigValueAssociation(
                elem.config_value
            )
开发者ID:BY-jk,项目名称:sqlalchemy,代码行数:25,代码来源:versioned_map.py

示例4: detach

    def detach(self):
        if self in g.db:
            g.db.expunge(self)
            make_transient(self)

        self.id = None
        return self
开发者ID:alinelle,项目名称:profireader,代码行数:7,代码来源:pr_base.py

示例5: undo

 def undo(self):
     try:
         self.session.delete(self.database_entry)
     except InvalidRequestError:
         # database entry cannot be removed because the last call was not
         # followed by a commit -> use make_transient to revert putting the
         # entry into the pending state
         make_transient(self.database_entry)
开发者ID:MediaPlex,项目名称:sunpy,代码行数:8,代码来源:commands.py

示例6: copy_project_sample_annotations

    def copy_project_sample_annotations(cls, psa):
        locus_annotations = map(SampleLocusAnnotation.copy_sample_locus_annotation, psa.locus_annotations)
        db.session.expunge(psa)
        make_transient(psa)
        psa.id = None

        psa.locus_annotations = locus_annotations
        return psa
开发者ID:Greenhouse-Lab,项目名称:MicroSPAT,代码行数:8,代码来源:sample_annotations.py

示例7: get_copy

 def get_copy(cls, id):
     inst = cls.get(id)
     if not inst:
         return inst
     DBSession.expunge(inst)
     make_transient(inst)
     inst.id = None
     return inst
开发者ID:mazvv,项目名称:travelcrm,代码行数:8,代码来源:__init__.py

示例8: new_version

    def new_version(self, session):
        # make us transient (removes persistent
        # identity).
        make_transient(self)

        # set 'id' to None.
        # a new PK will be generated on INSERT.
        self.id = None
开发者ID:cpcloud,项目名称:sqlalchemy,代码行数:8,代码来源:versioned_rows.py

示例9: clone_row

def clone_row(row, event_id=None):
    db.session.expunge(row)
    make_transient(row)
    row.id = None
    if event_id:
        row.event_id = event_id
    save_to_db(row)
    db.session.flush()
    return row
开发者ID:aviaryan,项目名称:open-event-orga-server,代码行数:9,代码来源:clone.py

示例10: transient_copy

def transient_copy(session, inst):
    """Copy a sample, this approach forces a bunch of flushes"""
    from sqlalchemy.orm import make_transient
    session.expunge(inst)
    make_transient(inst)
    inst.id = None
    session.add(inst)
    session.flush()
    return inst
开发者ID:twist-jenkins,项目名称:Sample_Tracker,代码行数:9,代码来源:spreadsheet.py

示例11: __call__

 def __call__(self):
     try:
         self.session.add(self.database_entry)
     except InvalidRequestError:
         # database entry cannot be added because it was removed from the
         # database -> use make_transient to send this object back to
         # the transient state
         make_transient(self.database_entry)
         self.session.add(self.database_entry)
开发者ID:MediaPlex,项目名称:sunpy,代码行数:9,代码来源:commands.py

示例12: copy_locus_bin_set

    def copy_locus_bin_set(cls, lbs):
        bins = list(map(Bin.copy_bin, lbs.bins))

        db.session.expunge(lbs)
        make_transient(lbs)

        lbs.id = None
        lbs.bins = bins

        return lbs
开发者ID:Greenhouse-Lab,项目名称:MicroSPAT,代码行数:10,代码来源:locus_bin_set.py

示例13: clone

def clone(model):
    """
    Clones the given model and removes it's primary key
    :param model:
    :return:
    """
    db.session.expunge(model)
    make_transient(model)
    model.id = None
    return model
开发者ID:harmw,项目名称:lemur,代码行数:10,代码来源:database.py

示例14: copy_artifact_estimator

    def copy_artifact_estimator(cls, ae):
        assert isinstance(ae, cls)
        art_eqs = list(map(ArtifactEquation.copy_artifact_equation, ae.artifact_equations))

        db.session.expunge(ae)
        make_transient(ae)

        ae.id = None
        ae.artifact_equations = art_eqs

        return ae
开发者ID:Greenhouse-Lab,项目名称:MicroSPAT,代码行数:11,代码来源:artifact_estimator.py

示例15: test_calculate_amount

    def test_calculate_amount(self):
        account = Tag(user=self.users[0], name="account")
        account_group = TagGroup(user=self.users[0], tags=[account])
        db.add(Transaction(user=self.users[0], amount=500, incomeTagGroup=account_group))
        db.add(Transaction(user=self.users[0], amount=-100, incomeTagGroup=account_group))
        db.flush()

        t = Transaction(user=self.users[0], amount=33, incomeTagGroup=account_group)
        make_transient(t)
        t.calculate_amount()
        self.assertEquals(t.amount, 33-400)
开发者ID:MarekSalat,项目名称:Trine,代码行数:11,代码来源:test_Transaction.py


注:本文中的sqlalchemy.orm.make_transient函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。