本文整理汇总了Python中sqlalchemy.delete函数的典型用法代码示例。如果您正苦于以下问题:Python delete函数的具体用法?Python delete怎么用?Python delete使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了delete函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: delete_member
def delete_member(self, id):
"""
@param id: primary key (int) of document.
Delete a "file type" record. Normally these records are linked
to "doc type" records. However, there are cases where these
records ("file type") are not associated with any "doc type",
so we've used this method to delete them.
"""
if isinstance(id, int):
# NOTE: Quando a operação DELETE envolve id_doc! By John Doe
stmt = delete(self.entity.__table__).where(
self.entity.__table__.c.id_doc == id)
else:
# NOTE: Quando a operação DELETE envolve id_file! By John Doe
stmt = delete(self.entity.__table__).where(
self.entity.__table__.c.id_file == id)
self.session.execute(stmt)
# NOTE: Now commits and closes session in the view instead of here
# flush() pushes operations to DB's buffer - DCarv
self.session.flush()
# NOTE: Clear cache! By John Doe
cache.clear_collection_cache(self.base_name)
return True
开发者ID:lightbase,项目名称:LBGenerator,代码行数:29,代码来源:file.py
示例2: delete_member
def delete_member(self, id):
"""
@param id: primary key (int) of document.
Query the document object, verify the flag `dt_del`. If setted,
that means that this document was deleted once, but it's index was not
successfull deleted. So we delete the document. If not, will try to
delete it's index and document. In case of failure, will SET all
columns to NULL and clear document, leaving only it's metadata.
"""
stmt1 = delete(self.entity.__table__).where(
self.entity.__table__.c.id_doc == id)
stmt2 = delete(self.file_entity.__table__).where(
self.file_entity.__table__.c.id_doc == id)
self.session.execute(stmt1)
self.session.execute(stmt2)
self.session.commit()
self.session.close()
if self.index.is_indexable:
Thread(target=self.async_delete_member,
args=(id, self.session)).start()
# Clear cache
cache.clear_collection_cache(self.base_name)
return True
开发者ID:VictorMedeiros,项目名称:LBGenerator,代码行数:26,代码来源:document.py
示例3: downgrade
def downgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
aggregates = Table('aggregates', meta, autoload=True)
aggregate_metadata = Table('aggregate_metadata', meta, autoload=True)
availability_zone = Column('availability_zone', String(255))
aggregates.create_column(availability_zone)
# Migrate data back
# NOTE(jhesketh): This needs to be done with individual inserts as multiple
# results in an update sub-query do not work with MySQL. See bug/1207956.
record_list = list(aggregates.select().execute())
for rec in record_list:
result = aggregate_metadata.select().where(
aggregate_metadata.c.key == 'availability_zone'
).where(
aggregate_metadata.c.aggregate_id == rec['id']
)
aggregates.update().values(
availability_zone=list(result.execute())[0]['value']
).where(
aggregates.c.id == rec['id']
).execute()
delete(aggregate_metadata,
aggregate_metadata.c.key == 'availability_zone').execute()
aggregates.c.availability_zone.alter(nullable=False)
开发者ID:674009287,项目名称:nova,代码行数:29,代码来源:146_aggregate_zones.py
示例4: delete_entry
def delete_entry(fav_id):
try:
delete(favorites_table, favorites_table.c.id == fav_id).execute()
except:
print 'There was an error deleting this favorite.'
return redirect(url_for('show_favorites'))
开发者ID:dtia,项目名称:Uber-Challenge,代码行数:7,代码来源:favorites.py
示例5: insert_messages
def insert_messages(reader, session, japanese_module):
'''
retrieve new messages from reader limit MESSAGE_COUNT_PER_COMMIT
insert messages into database if in Japanese.
'''
mid = _insert_tmp_messages(reader, session)
# delete messages without need from tmp table
_mark_tmpmsg_from_known_senders(session)
_mark_tmpmsg_in_japanese(session, japanese_module)
stmt = delete(TmpMessage.__table__).where(TmpMessage.need == False)
session.execute(stmt)
# register new senders and new messages from tmp table.
for sender, in _get_new_tmp_senders(session):
session.add(Sender(sender))
session.flush()
_register_new_tmp_messages(session)
# delete all records from tmp table.
session.execute(delete(TmpMessage.__table__))
# record last registered mid into parameters table.
if mid:
session.merge(Parameter(LAST_MID_OF_INSERT_MESSAGE, mid))
开发者ID:nekomusha,项目名称:public,代码行数:25,代码来源:statistics_logic.py
示例6: deleteItem
def deleteItem(category_id=None, item_id=None, item_name=None):
if "username" not in login_session or login_session["username"] == "":
print "why"
return "fap"
redirect(url_for("showCategories"))
print request.method
if request.method == "POST":
deleted = None
print "hey1"
if item_id:
deleted = delete(Item).where(Item.id == item_id)
if item_name:
print "hey2"
deleted = delete(Item).where(Item.title == item_name)
session.execute(deleted)
session.commit()
flash("the Item was deleted")
return redirect(url_for("showCategories"))
if request.method == "GET":
item = None
if item_id:
item = session.query(Item).filter(Item.id == item_id).first()
if item_name:
item = session.query(Item).filter(Item.title == item_name).first()
return render_template("deleteitem.html", item=item)
开发者ID:bpoole6,项目名称:Uprojects,代码行数:27,代码来源:project.py
示例7: tearDown
def tearDown(self):
table_name = self.conf[mk.TARGET_DB_TABLE]
guid_batch = self.conf['guid_batch']
with get_udl_connection() as conn:
table = conn.get_table(table_name)
try:
delete(table).where(table.c.guid_batch == guid_batch)
except Exception as e:
print('Exception -- ', e)
开发者ID:SmarterApp,项目名称:RDW_DataWarehouse,代码行数:9,代码来源:test_file_loader.py
示例8: test_delete_returning
def test_delete_returning(self):
table1 = table(
'mytable', column('myid', Integer),
column('name', String(128)), column('description', String(128)))
d = delete(table1).returning(table1.c.myid, table1.c.name)
self.assert_compile(d,
'DELETE FROM mytable OUTPUT deleted.myid, '
'deleted.name')
d = delete(table1).where(table1.c.name == 'bar'
).returning(table1.c.myid,
table1.c.name)
self.assert_compile(d,
'DELETE FROM mytable OUTPUT deleted.myid, '
'deleted.name WHERE mytable.name = :name_1')
开发者ID:CyberCollins,项目名称:sqlalchemy,代码行数:14,代码来源:test_compiler.py
示例9: opt_in
def opt_in(self, msg_hash):
"""Removes recipient of the email from the opt-out list"""
email = self.get_recipient(msg_hash)
if email:
o = self.opt_table
if self.has_opted_out(email):
sa.delete(o, o.c.email == email).execute()
clear_memo('r2.models.mail_queue.has_opted_out',
email)
clear_memo('r2.models.mail_queue.opt_count')
return (email, True)
else:
return (email, False)
return (None, False)
开发者ID:Craigus,项目名称:lesswrong,代码行数:14,代码来源:mail_queue.py
示例10: deleteCategory
def deleteCategory(category_id):
if 'username' not in login_session or login_session['username'] == '':
return redirect(url_for('showCategories'))
if request.method == 'POST':
deletedCategory = delete(Category).where(Category.id == category_id)
deletedItems = delete(Item).where(Item.category_id == category_id)
session.execute(deletedItems)
session.execute(deletedCategory)
session.commit()
return redirect(url_for('showCategories'))
if request.method == 'GET':
category = session.query(Category).filter(Category.id == category_id).first()
items = session.query(Item).filter(Item.category_id == category_id)
print category.id
return render_template('deletecategory.html', category=category, items=items)
开发者ID:bpoole6,项目名称:catalog,代码行数:15,代码来源:project.py
示例11: drop_samples_fields
def drop_samples_fields(engine, test_suite_id, trans):
"""In the TestSuiteSampleFields, drop entries related to the test_suite_id.
This extra function is needed because in MySQL it can't sort out the forign
keys in the same table.
"""
samples_table = introspect_table(engine, 'TestSuiteSampleFields')
order_files = delete(samples_table,
and_(samples_table.c.TestSuiteID == test_suite_id,
samples_table.c.status_field.isnot(None)))
trans.execute(order_files)
order_files = delete(samples_table,
samples_table.c.TestSuiteID == test_suite_id)
trans.execute(order_files)
return samples_table
开发者ID:llvm-mirror,项目名称:lnt,代码行数:15,代码来源:upgrade_13_to_14.py
示例12: deleteCategory
def deleteCategory(category_id):
if "username" not in login_session or login_session["username"] == "":
return redirect(url_for("showCategories"))
if request.method == "POST":
deletedCategory = delete(Category).where(Category.id == category_id)
deletedItems = delete(Item).where(Item.category_id == category_id)
session.execute(deletedItems)
session.execute(deletedCategory)
session.commit()
return redirect(url_for("showCategories"))
if request.method == "GET":
category = session.query(Category).filter(Category.id == category_id).first()
items = session.query(Item).filter(Item.category_id == category_id)
print category.id
return render_template("deletecategory.html", category=category, items=items)
开发者ID:bpoole6,项目名称:Uprojects,代码行数:15,代码来源:project.py
示例13: delete_files
def delete_files(self, member, files):
"""
Will delete files that are not present in document.
@param member: LBDoc_<base> object (mapped ORM entity).
@param files: List of files ids present in document.
"""
where_clause = [(self.file_entity.__table__.c.id_doc==member.id_doc)]
if len(files) > 0:
notin_clause = self.file_entity.__table__.c.id_file.notin_(files)
where_clause.append(notin_clause)
where_clause = and_(*where_clause)
stmt = delete(self.file_entity.__table__).where(where_clause)
else:
stmt = delete(self.file_entity.__table__).where(*where_clause)
self.session.execute(stmt)
开发者ID:antonygc,项目名称:LBGenerator,代码行数:15,代码来源:document.py
示例14: opt_in
def opt_in(self, msg_hash):
"""Removes recipient of the email from the opt-out list"""
email = self.get_recipient(msg_hash)
if email:
o = self.opt_table
if self.has_opted_out(email):
sa.delete(o, o.c.email == email).execute()
#clear caches
has_opted_out(email, _update = True)
opt_count(_update = True)
return (email, True)
else:
return (email, False)
return (None, False)
开发者ID:asdfjasdjkfl,项目名称:reddit,代码行数:15,代码来源:mail_queue.py
示例15: delete
def delete(self):
self.logger.info("{SELF} deleting db entry".format(SELF=self))
with user_database.get_session(self, acquire=True) as session:
session.execute(delete(user_database.Metadata).where(
user_database.Metadata.id == self.db_id
))
self.db_id = None
开发者ID:seanegoodwin,项目名称:PandaViewer,代码行数:7,代码来源:metadata.py
示例16: test_correlated
def test_correlated(self):
table1, table2 = self.tables.mytable, self.tables.myothertable
# test a non-correlated WHERE clause
s = select([table2.c.othername], table2.c.otherid == 7)
self.assert_compile(
delete(table1, table1.c.name == s),
"DELETE FROM mytable "
"WHERE mytable.name = ("
"SELECT myothertable.othername "
"FROM myothertable "
"WHERE myothertable.otherid = :otherid_1"
")",
)
# test one that is actually correlated...
s = select([table2.c.othername], table2.c.otherid == table1.c.myid)
self.assert_compile(
table1.delete(table1.c.name == s),
"DELETE FROM mytable "
"WHERE mytable.name = ("
"SELECT myothertable.othername "
"FROM myothertable "
"WHERE myothertable.otherid = mytable.myid"
")",
)
开发者ID:BY-jk,项目名称:sqlalchemy,代码行数:26,代码来源:test_delete.py
示例17: calculate_tf_idf
def calculate_tf_idf(session):
'''
calculate and update TF-IDF for all scores.
'''
all_sender_count = session.query(Sender).count()
session.execute(delete(Score.__table__))
session.execute("""
insert into
scores
select
sid,
words.wid,
1. * sum(message_words.count)
* :all_sender_count / sender_count as tfidf
from
words,
messages,
message_words
where
words.wid = message_words.wid
and message_words.mid = messages.mid
group by
sid,
words.wid
order by
sid,
message_words.wid,
tfidf desc
""", {'all_sender_count': all_sender_count})
开发者ID:nekomusha,项目名称:public,代码行数:29,代码来源:statistics_logic.py
示例18: test_cascade_release_deletion
def test_cascade_release_deletion(self):
release_component_table = self.meta.tables['release_components']
release_table = self.meta.tables['releases']
release_id = insert_table_row(
release_table,
{
'name': 'release_with_components',
'version': '2014.2.2-6.1',
'operating_system': 'ubuntu',
'state': 'available'
}
)
component_id = insert_table_row(
self.meta.tables['components'],
{'name': six.text_type(uuid.uuid4()), 'type': 'hypervisor'}
)
insert_table_row(
release_component_table,
{'release_id': release_id, 'component_id': component_id}
)
db.execute(
sa.delete(release_table).where(release_table.c.id == release_id))
deleted_plugin_components = db.execute(
sa.select([sa.func.count(release_component_table.c.id)]).
where(release_component_table.c.release_id == release_id)
).fetchone()[0]
self.assertEqual(deleted_plugin_components, 0)
开发者ID:gdyuldin,项目名称:fuel-web,代码行数:27,代码来源:test_migration_fuel_8_0.py
示例19: delete_member
def delete_member(self):
# NOTE: Obtêm o nome do índice textual na rota submetida!
# By Questor
nm_idx = self.request.matchdict['nm_idx']
self.single_member = True
try:
stmt = delete(self.entity.__table__).where(
self.entity.__table__.c.nm_idx == nm_idx)
except Exception as e:
raise LbException("Failed to format persistence object!", str(e))
try:
result = self.session.execute(stmt)
self.session.commit()
# NOTE: Manipula o cache conforme as regras dessa rota!
# By Questor
if result.rowcount > 0:
self.remove_item(nm_idx)
return result.rowcount
except Exception as e:
raise LbException("Failed to persist data!", str(e))
finally:
self.session.close()
开发者ID:lightbase,项目名称:LBGenerator,代码行数:28,代码来源:txt_idx.py
示例20: test_delete_stmt_with_comma_subquery_alias_join
def test_delete_stmt_with_comma_subquery_alias_join():
parent_ = sa.alias(product)
del_stmt = (
sa.delete(items)
.where(items.c.order_id == orders.c.id)
.where(orders.c.customer_id.in_(sa.select([customers.c.id]).where(customers.c.email.endswith("test.com"))))
.where(items.c.product_id == product.c.id)
.where(product.c.parent_id == parent_.c.id)
.where(parent_.c.id != hammy_spam.c.ham_id)
)
expected = """
DELETE FROM items
USING orders, products, products AS products_1, "ham, spam"
WHERE items.order_id = orders.id
AND orders.customer_id IN
(SELECT customers.id
FROM customers
WHERE (customers.email LIKE '%%' || 'test.com'))
AND items.product_id = products.id
AND products.parent_id = products_1.id
AND products_1.id != "ham, spam".ham_id"""
assert clean(compile_query(del_stmt)) == clean(expected)
开发者ID:solackerman,项目名称:sqlalchemy-redshift,代码行数:25,代码来源:test_delete_stmt.py
注:本文中的sqlalchemy.delete函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论