• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python sql.delete函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: update_changes

    def update_changes(self, table, changes,
                       insert_f=None, where_f=None, delete_f=None):

        for action, obj in changes:
            if action == 'new':
                if insert_f is not None:
                    iquery = table.insert().values(
                        **insert_f(obj)
                    )
                    self.session.execute(iquery)
                else:
                    self.conn.update(obj)
            elif action == 'remove_by_id':
                dquery = delete(table)\
                    .where(table.c.id==obj)
                self.session.execute(dquery)
            elif action == 'remove':
                if delete_f is not None:
                    dquery = delete(table).where(
                        delete_f(obj)
                    )
                    self.session.execute(dquery)
                elif not hasattr(obj, '_alchemy_pk') or not obj._alchemy_pk:
                    raise NotImplementedError
                else:
                    raise NotImplementedError
            else:
                raise NotImplementedError(action)
开发者ID:pitcons,项目名称:amarak,代码行数:28,代码来源:common_manager.py


示例2: toolbar_icon_clicked

    def toolbar_icon_clicked(self, widget, movie):
        if question(_('Are you sure you want to remove %d movies?') % self.app.total):
            session = self.db.Session()

            # first: remove all dependend data (associated tags, languages, ...)
            query = select([movies_table.c.movie_id])
            # FIXME: self.app._search_conditions contains advfilter conditions only (no other filters)
            query = update_whereclause(query, self.app._search_conditions)
            query = query.where(movies_table.c.loaned==False) # don't delete loaned movies
            for movie_entry in session.execute(query):
                # tags
                query_movie_tags = delete(movie_tag_table)
                query_movie_tags = query_movie_tags.where(movie_tag_table.c.movie_id==movie_entry.movie_id)
                session.execute(query_movie_tags)
                # languages
                query_movie_lang = delete(movie_lang_table)
                query_movie_lang = query_movie_lang.where(movie_lang_table.c.movie_id==movie_entry.movie_id)
                session.execute(query_movie_lang)
                # TODO: removing posters if no longer used by another movie?

            # second: remove the movie entries
            query = delete(movies_table)
            # FIXME: self.app._search_conditions contains advfilter conditions only (no other filters)
            query = update_whereclause(query, self.app._search_conditions)
            query = query.where(movies_table.c.loaned==False) # don't delete loaned movies

            session.execute(query)
            session.commit()

            self.app.populate_treeview()
开发者ID:BackupTheBerlios,项目名称:griffith-svn,代码行数:30,代码来源:ge_remover.py


示例3: test_delete_extra_froms_alias

 def test_delete_extra_froms_alias(self):
     a1 = table("t1", column("c1")).alias("a1")
     t2 = table("t2", column("c1"))
     q = sql.delete(a1).where(a1.c.c1 == t2.c.c1)
     self.assert_compile(
         q, "DELETE FROM a1 FROM t1 AS a1, t2 WHERE a1.c1 = t2.c1"
     )
     self.assert_compile(sql.delete(a1), "DELETE FROM t1 AS a1")
开发者ID:BY-jk,项目名称:sqlalchemy,代码行数:8,代码来源:test_compiler.py


示例4: customer_del

    def customer_del(self, customer_id):
        """Delete a customer from database, bringing along all it's machines
        and services
        """
        # Get customer
        cust = query(model.Customer).options(model.eagerload('machines'))\
                                    .get(int(customer_id))

        if not cust:
            return vaultMsg(True, "No such customer: c#%s" % customer_id)

        # Get all the services that will be deleted
        servs = query(model.Service).join(['machine', 'customer']) \
                     .filter(model.Customer.id == customer_id) \
                     .all()
        servs_ids = [s.id for s in servs]

        # Make sure no service is child of this one
        childs = query(model.Service) \
                     .filter(model.Service.parent_service_id.in_(servs_ids))\
                     .all()

        # Don't bother for parents/childs if we're going to delete it anyway.
        remnants = list(set(childs).difference(set(servs)))

        if len(remnants):
            # There are still some childs left, we can't delete this one.
            retval = []
            for x in remnants:
                retval.append({'id': x.id, 'url': x.url})
                
            return vaultMsg(False, "Services still child of this customer's machine's services",
                            {'childs': retval})

        # Delete all related groupciphers
        d = sql.delete(model.servicegroups_table) \
               .where(model.servicegroups_table.c.service_id.in_(servs_ids))
        # Delete the services related to customer_id's machines
        d2 = sql.delete(model.services_table) \
                .where(model.services_table.c.id.in_(servs_ids))
        # Delete the machines related to customer_id
        mach_ids = [m.id for m in cust.machines]
        d3 = sql.delete(model.machines_table) \
                .where(model.machines_table.c.id.in_(mach_ids))
        # Delete the customer
        d4 = sql.delete(model.customers_table) \
                .where(model.customers_table.c.id == customer_id)

        meta.Session.execute(d)
        meta.Session.execute(d2)
        meta.Session.execute(d3)
        meta.Session.execute(d4)
        
        meta.Session.commit()

        return vaultMsg(True,
                        'Deleted customer c#%s successfully' % customer_id)
开发者ID:baloo,项目名称:sflvault-server,代码行数:57,代码来源:vault.py


示例5: delete

    def delete(self, scheme):
        if hasattr(scheme, '_alchemy_pk') and scheme._alchemy_pk is not None:
            query = delete(tbl.scheme)\
                .where(tbl.scheme.c.id==scheme._alchemy_pk)
        else:
            query = delete(tbl.scheme)\
                .where(tbl.scheme.c.name==scheme.name)

        self.session.execute(query)
开发者ID:pitcons,项目名称:amarak,代码行数:9,代码来源:schemes.py


示例6: clean_stats

    def clean_stats(self, tags=None):
        eng = self.treatment.experiment.database.engine
        se = delete(StatsRecord).where(and_(
            # StatsRecord.kind.in_(names),
            StatsRecord.replicate_id == self.seq,
            StatsRecord.treatment_id == self.treatment.seq))
        eng.execute(se)

        ge = delete(StatsRecord).where(and_(
            # StatsRecord.kind.in_(names),
            StatsRecord.replicate_id == self.seq,
            StatsRecord.treatment_id == self.treatment.seq))
        eng.execute(ge)
开发者ID:brettc,项目名称:bricolage,代码行数:13,代码来源:experiment.py


示例7: delete_vocabulary

def delete_vocabulary(id, cascade=True):
    """
    Delete a vocabulary, by id

    :param id: vocabulary id
    :param cascade: if True, delete all tags in this vocabulary first
    """
    conn = Session.connection()
    with conn.begin():
        if cascade:
            query = delete(tag_table).where(tag_table.c.vocabulary_id == id)
            query.execute()
        query = delete(vocabulary_table).where(vocabulary_table.c.id == id)
开发者ID:rshk,项目名称:ckanext-api-ng,代码行数:13,代码来源:tag.py


示例8: machine_del

    def machine_del(self, machine_id):
        """Delete a machine from database, bringing on all child services."""
        
        # Get machine
        machine = query(model.Machine).get(int(machine_id))

        if not machine:
            return vaultMsg(True, "No such machine: m#%s" % machine_id)

        # Get all the services that will be deleted
        servs = query(model.Service).join('machine') \
                     .filter(model.Machine.id == machine_id).all()
        servs_ids = [s.id for s in servs]

        # Make sure no service is child of this one
        childs = query(model.Service) \
                     .filter(model.Service.parent_service_id.in_(servs_ids))\
                     .all()

        # Don't bother for parents/childs if we're going to delete it anyway.
        remnants = list(set(childs).difference(set(servs)))

        if len(remnants):
            # There are still some childs left, we can't delete this one.
            retval = []
            for x in remnants:
                retval.append({'id': x.id, 'url': x.url})
                
            return vaultMsg(False, "Services still child of this machine's services",
                            {'childs': retval})


        # Delete all related groupciphers
        d = sql.delete(model.servicegroups_table) \
               .where(model.servicegroups_table.c.service_id.in_(servs_ids))
        # Delete the services related to machine_id
        d2 = sql.delete(model.services_table) \
                .where(model.services_table.c.id.in_(servs_ids))
        # Delete the machine
        d3 = sql.delete(model.machines_table) \
                .where(model.machines_table.c.id == machine_id)

        meta.Session.execute(d)
        meta.Session.execute(d2)
        meta.Session.execute(d3)
        
        meta.Session.commit()

        return vaultMsg(True, 'Deleted machine m#%s successfully' % machine_id)
开发者ID:baloo,项目名称:sflvault-server,代码行数:49,代码来源:vault.py


示例9: clear_reset_code

    def clear_reset_code(self, user_id):
        if self._engine is None:
            raise NotImplementedError()

        query = delete(reset_codes).where(reset_codes.c.username == user_id)
        res = safe_execute(self._engine, query)
        return res.rowcount > 0
开发者ID:irslambouf,项目名称:SyncServer,代码行数:7,代码来源:resetcode.py


示例10: upgrade

def upgrade(ver, session):
    if ver is 0:
        table_names = [
            "rottentomatoes_actors",
            "rottentomatoes_alternate_ids",
            "rottentomatoes_directors",
            "rottentomatoes_genres",
            "rottentomatoes_links",
            "rottentomatoes_movie_actors",
            "rottentomatoes_movie_directors",
            "rottentomatoes_movie_genres",
            "rottentomatoes_movies",
            "rottentomatoes_posters",
            "rottentomatoes_releasedates",
            "rottentomatoes_search_results",
        ]
        tables = [table_schema(name, session) for name in table_names]
        for table in tables:
            session.execute(table.delete())
        table_add_column("rottentomatoes_actors", "rt_id", String, session)
        ver = 1
    if ver is 1:
        table = table_schema("rottentomatoes_search_results", session)
        session.execute(sql.delete(table, table.c.movie_id == None))
        ver = 2
    return ver
开发者ID:home4film,项目名称:Flexget,代码行数:26,代码来源:api_rottentomatoes.py


示例11: test_delete_extra_froms

 def test_delete_extra_froms(self):
     t1 = table("t1", column("c1"))
     t2 = table("t2", column("c1"))
     q = sql.delete(t1).where(t1.c.c1 == t2.c.c1)
     self.assert_compile(
         q, "DELETE FROM t1 FROM t1, t2 WHERE t1.c1 = t2.c1"
     )
开发者ID:BY-jk,项目名称:sqlalchemy,代码行数:7,代码来源:test_compiler.py


示例12: _test_execute

    async def _test_execute(self, engines, binds):
        test_table1 = self.test_models['db1'].test_table1
        test_table2 = self.test_models['db2'].test_table2
        async with Session(engines, binds) as session:
            q = sql.insert(test_table1).values(id=5, title='test_title')
            result = await session.execute(q)
            self.assertEqual(result.lastrowid, 5)
            q = sql.select(test_table1.c).where(test_table1.c.id == 5)
            result = await session.execute(q)
            self.assertEqual(result.rowcount, 1)
            result = list(result)
            self.assertEqual(result[0]['id'], 5)
            self.assertEqual(result[0]['title'], 'test_title')

            q = sql.update(test_table1).where(test_table1.c.id == 5).\
                    values(title='test_title2')
            result = await session.execute(q)
            self.assertEqual(result.rowcount, 1)
            q = sql.select(test_table1.c).\
                    where(test_table1.c.id == 5)
            result = await session.execute(q)
            self.assertEqual(result.rowcount, 1)
            result = list(result)
            self.assertEqual(result[0]['id'], 5)
            self.assertEqual(result[0]['title'], 'test_title2')

            q = sql.delete(test_table1).where(test_table1.c.id == 5)
            result = await session.execute(q)
            self.assertEqual(result.rowcount, 1)
            q = sql.select(test_table1.c).\
                    where(test_table1.c.id == 5)
            result = await session.execute(q)
            self.assertEqual(result.rowcount, 0)
开发者ID:motor23,项目名称:cmstest,代码行数:33,代码来源:test_session.py


示例13: delete

    def delete(self, concept):
        if hasattr(concept, '_alchemy_pk') and concept._alchemy_pk is not None:
            query = delete(tbl.concept)\
                .where(tbl.concept.c.id==concept._alchemy_pk)
        else:
            raise NotImplementedError

        self.session.execute(query)
开发者ID:pitcons,项目名称:amarak,代码行数:8,代码来源:concepts.py


示例14: forget_user

 def forget_user(self, uid=None):
     if uid is None:
         return False
     if type(uid) is str:  # Sorry little Billy '); Drop Tables *;
         return False
     query = delete([user_info]).where(user_info.c.uid == uid)
     self._db.execute(query)
     return True
开发者ID:rafrombrc,项目名称:FirefoxID-Server,代码行数:8,代码来源:id_storage.py


示例15: delete

 def delete(self, id=None):
     id = request.params.getone('id')
     post_q = meta.Session.query(model.Post)
     post = post_q.filter_by(id=id).first()
     if post is None:
         abort(404)
     # delete tags and comments associated with post
     meta.Session.execute(delete(model.poststags_table, model.poststags_table.c.post_id==post.id))
     meta.Session.execute(delete(model.comments_table, model.comments_table.c.post_id==post.id))
     meta.Session.delete(post)
     meta.Session.commit()
     if request.is_xhr:
         response.content_type = 'application/json'
         return "{'success':true,'msg':'The post has been deleted'}"
     else:
         session['flash'] = 'Post successfully deleted.'
         session.save()
         return redirect_to(controller='post', action='list')
开发者ID:bdrydyk,项目名称:wurdig,代码行数:18,代码来源:post.py


示例16: remove

 def remove(self,obj):
     """
     Remove an object from the relation
     """
     with self.obj.backend.transaction(implicit = True):
         relationship_table = self.params['relationship_table']
         condition = and_(relationship_table.c['pk_%s' % self.params['collection']] == obj.pk,
                          relationship_table.c['pk_%s' % self.collection] == self.obj.pk)
         self.obj.backend.connection.execute(delete(relationship_table).where(condition))
         self._queryset = None
开发者ID:SanketSKasar,项目名称:blitzdb,代码行数:10,代码来源:relations.py


示例17: _delete_unused_balances

    def _delete_unused_balances(self):
        abandoned = self.db.execute(select([self.model.Balance.uid], self.model.UserBalance.c.balance_uid==null(),
            from_obj=self.model.balances_table.outerjoin(self.model.users_balances_table))).fetchall()

        where = []
        for uid in abandoned:
            where.append(self.model.Balance.uid==uid[0])
    
        if len(where) > 0:
            self.db.execute(delete(self.model.balances_table, or_(*where)))
开发者ID:pawelniewie,项目名称:5groszy.pl,代码行数:10,代码来源:ops.py


示例18: test_get_engine

 async def test_get_engine(self, engines, binds):
     test_table1 = self.test_models['db1'].test_table1
     test_table2 = self.test_models['db2'].test_table2
     async with Session(engines, binds) as session:
         i1 = sql.insert(test_table1)
         i2 = sql.insert(test_table2)
         u1 = sql.update(test_table1)
         u2 = sql.update(test_table2)
         d1 = sql.delete(test_table1)
         d2 = sql.delete(test_table2)
         s1 = sql.insert(test_table1)
         s2 = sql.insert(test_table2)
         for q1, q2 in [(i1, i2), (u1, u2), (d1, d2), (s1, s2)]:
             engine1 = session.get_engine(q1)
             engine2 = session.get_engine(q2)
             self.assertEqual(engine1, engines['db1'])
             self.assertEqual(engine2, engines['db2'])
         with self.assertRaises(exc.OrmError):
             session.get_engine('error query')
开发者ID:motor23,项目名称:cmstest,代码行数:19,代码来源:test_session.py


示例19: _delete_unused_changes_tags

    def _delete_unused_changes_tags(self, balance_uid):
        abandoned_tags = self.db.execute(select([self.model.BalanceTag.uid], 
            and_(self.model.BalanceTag.balance_uid==balance_uid, self.model.changes_tags_table.c.tag_uid==null()),
            from_obj=self.model.balance_tags_table.outerjoin(self.model.changes_tags_table))).fetchall()

        where = []
        for tag in abandoned_tags:
            where.append(self.model.BalanceTag.uid==tag[0])
    
        if len(where) > 0:
            self.db.execute(delete(self.model.balance_tags_table, or_(*where)))
开发者ID:pawelniewie,项目名称:5groszy.pl,代码行数:11,代码来源:ops.py


示例20: forget_site_association

 def forget_site_association(self, site_id, request, uid=None):
     if uid is None:
         uid = self.uid
     if uid is None:
         return False
     if re.search("[^\w]", uid):
         return False
     site_loc = self._site_loc(request)
     where = _and(site_id_to_uid.c.site_id == site_id, site_id_to_uid.c.site_loc == site_loc)
     query = delete(site_id_to_uid).where(where)
     return True
开发者ID:rafrombrc,项目名称:FirefoxID-Server,代码行数:11,代码来源:id_storage.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python sql.desc函数代码示例发布时间:2022-05-27
下一篇:
Python sql.column函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap