本文整理汇总了Python中sqlalchemy.orm.make_transient函数的典型用法代码示例。如果您正苦于以下问题:Python make_transient函数的具体用法?Python make_transient怎么用?Python make_transient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_transient函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: test_make_transient_plus_rollback
def test_make_transient_plus_rollback(self):
# test for [ticket:2182]
mapper(User, users)
sess = Session()
u1 = User(name='test')
sess.add(u1)
sess.commit()
sess.delete(u1)
sess.flush()
make_transient(u1)
sess.rollback()
开发者ID:chatch,项目名称:pinyin-toolkit,代码行数:12,代码来源:test_session.py
示例17: new_version
def new_version(self, session):
# optional - set previous version to have is_current_version=False
old_id = self.id
session.query(self.__class__).filter_by(id=old_id).update(
values=dict(is_current_version=False), synchronize_session=False)
# make us transient (removes persistent
# identity).
make_transient(self)
# increment version_id, which means we have a new PK.
self.version_id += 1
开发者ID:cpcloud,项目名称:sqlalchemy,代码行数:12,代码来源:versioned_rows_w_versionid.py
示例18: clone_dataset
def clone_dataset(dataset_id,**kwargs):
"""
Get a single dataset, by ID
"""
user_id = int(kwargs.get('user_id'))
if dataset_id is None:
return None
dataset = DBSession.query(Dataset).filter(
Dataset.dataset_id==dataset_id).options(joinedload_all('metadata')).first()
if dataset is None:
raise HydraError("Dataset %s does not exist."%(dataset_id))
if dataset is not None and dataset.created_by != user_id:
owner = DBSession.query(DatasetOwner).filter(
DatasetOwner.dataset_id==Dataset.dataset_id,
DatasetOwner.user_id==user_id).first()
if owner is None:
raise PermissionError("User %s is not an owner of dataset %s and therefore cannot clone it."%(user_id, dataset_id))
DBSession.expunge(dataset)
make_transient(dataset)
dataset.data_name = dataset.data_name + "(Clone)"
dataset.dataset_id = None
dataset.cr_date = None
#Try to avoid duplicate metadata entries if the entry has been cloned previously
for m in dataset.metadata:
if m.metadata_name in ("clone_of", "cloned_by"):
del(m)
cloned_meta = Metadata()
cloned_meta.metadata_name = "clone_of"
cloned_meta.metadata_val = str(dataset_id)
dataset.metadata.append(cloned_meta)
cloned_meta = Metadata()
cloned_meta.metadata_name = "cloned_by"
cloned_meta.metadata_val = str(user_id)
dataset.metadata.append(cloned_meta)
dataset.set_hash()
DBSession.add(dataset)
DBSession.flush()
cloned_dataset = DBSession.query(Dataset).filter(
Dataset.dataset_id==dataset.dataset_id).first()
return cloned_dataset
开发者ID:UMWRG,项目名称:HydraPlatform,代码行数:53,代码来源:data.py
示例19: update_org_id
def update_org_id(old_id, new_id, new_parent_id=None, new_name=None):
bind = op.get_bind()
session = Session(bind=bind)
org = session.query(Organization).get(old_id)
if not org:
return
OT = OrgTree()
if len(OT.here_and_below_id(old_id)) > 1:
raise ValueError('organization `{}` cannot be moved '
'before children'.format(old_id))
make_transient(org)
org.id = new_id
if new_parent_id:
org.partOf_id = new_parent_id
if new_name:
org.name = new_name
session.add(org)
session.commit()
# update the related fields to point at new org
for qb in session.query(QuestionnaireBank).filter_by(organization_id=old_id):
qb.organization_id = new_id
session.commit()
for uc in session.query(UserConsent).filter_by(organization_id=old_id):
uc.organization_id = new_id
session.commit()
for uo in session.query(UserOrganization).filter_by(organization_id=old_id):
uo.organization_id = new_id
session.commit()
for tou in session.query(ToU).filter_by(organization_id=old_id):
tou.organization_id = new_id
session.commit()
for oi in session.query(OrganizationIdentifier).filter_by(organization_id=old_id):
oi.organization_id = new_id
session.commit()
for ol in session.query(OrganizationLocale).filter_by(organization_id=old_id):
ol.organization_id = new_id
session.commit()
for oa in session.query(OrganizationAddress).filter_by(organization_id=old_id):
oa.organization_id = new_id
session.commit()
session.execute('DELETE FROM organizations WHERE id = {}'.format(old_id))
开发者ID:ivan-c,项目名称:true_nth_usa_portal,代码行数:53,代码来源:b814b51681bf_.py
示例20: copy_folder
def copy_folder(self, folder_id):
folder = get_folder_by_id(self._db_session, folder_id)
parent_folder = self._get_parent()
self._db_session.expunge(folder)
make_transient(folder)
folder.id = None
folder.folder_id = None
folder.parent_id = parent_folder.id
self._db_session.add(folder)
self._db_session.commit()
self._db_session.add(EventModel(event_type="ITEM_COPY", source_id=folder.folder_id, source_type="folder"))
self._db_session.commit()
return json.dumps(folder)
开发者ID:bhh1988,项目名称:box-python-sdk,代码行数:13,代码来源:folder_behavior.py
注:本文中的sqlalchemy.orm.make_transient函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论