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

Python sql.sql函数代码示例

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

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



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

示例1: fill_id

def fill_id(conn, user_id, email_id):
    assert user_id is not None or email_id is not None

    if email_id is None:
        email_id = conn.execute(
            sql('select id from email where user_id = :user_id order by ctime limit 1'),
            user_id=user_id
        ).fetchone()
        if email_id:
            email_id = email_id[0]

    if user_id is None:
        user_id = conn.execute(
            sql('select user_id from email where id = :email_id'),
            email_id=email_id
        ).fetchone()
        if user_id:
            user_id = user_id[0]

    if user_id is None:
        raise UserNotExistError()
    if email_id is None:
        raise EmailNotExistError()

    return user_id, email_id
开发者ID:Answeror,项目名称:torabot,代码行数:25,代码来源:watch.py


示例2: set_next_sync_time

def set_next_sync_time(conn, id, time):
    conn.execute(sql(
        '''
        update query set next_sync_time = :time
        where id = :id
        '''
    ), id=id, time=time)
开发者ID:Answeror,项目名称:torabot,代码行数:7,代码来源:query.py


示例3: get_users

def get_users(conn, offset=None, limit=None):
    result = conn.execute(sql('\n'.join([
        'select * from "user" order by id',
        '' if offset is None else 'offset :offset',
        '' if limit is None else 'limit :limit'
    ])), **dict(offset=offset, limit=limit))
    return [bunchr(**row) for row in result.fetchall()]
开发者ID:funagi,项目名称:torabot,代码行数:7,代码来源:user.py


示例4: get_query_bi_kind_and_text

def get_query_bi_kind_and_text(conn, kind, text):
    ret = conn.execute(
        sql('select * from query where kind = :kind and text = :text'),
        kind=kind,
        text=text
    ).fetchone()
    return None if ret is None else mq(**ret)
开发者ID:Answeror,项目名称:torabot,代码行数:7,代码来源:query.py


示例5: set_user_field_bi_id

def set_user_field_bi_id(conn, id, field, value):
    assert_in(field, ('name', 'email', 'openid', 'maxwatch'))
    conn.execute(
        sql('update "user" set %s = :value where id = :id' % field),
        id=id,
        value=value
    )
开发者ID:funagi,项目名称:torabot,代码行数:7,代码来源:user.py


示例6: is_query_active_bi_id

def is_query_active_bi_id(conn, id):
    return conn.execute(sql(
        '''
        select 1 from watch as w0
        where w0.query_id = :id
        '''
    ), id=id).fetchone() is not None
开发者ID:Answeror,项目名称:torabot,代码行数:7,代码来源:query.py


示例7: add_query

def add_query(conn, kind, text, result={}):
    ret = conn.execute(sql('''
        insert into query (kind, text, result)
        values (:kind, :text, :result)
        returning *
    '''), kind=kind, text=text, result=Json(result)).fetchone()
    return ret[0]
开发者ID:Answeror,项目名称:torabot,代码行数:7,代码来源:query.py


示例8: rename_watch

def rename_watch(conn, user_id, query_id, name):
    conn.execute(sql(
        '''
        update watch set name = :name
        where user_id = :user_id and query_id = :query_id
        '''
    ), user_id=user_id, query_id=query_id, name=name)
开发者ID:sorunis,项目名称:torabot,代码行数:7,代码来源:watch.py


示例9: get_watches_bi_user_id

def get_watches_bi_user_id(conn, user_id, offset=None, limit=None):
    result = conn.execute(sql('\n'.join([
        '''
        select
            w0.user_id,
            w0.query_id,
            w0.name,
            w0.ctime,
            q0.kind query_kind,
            q0.text query_text,
            q0.mtime query_mtime,
            w0.email_id,
            e0.text email_text,
            e0.label email_label,
            e0.activated email_activated
        from watch w0
            inner join query q0 on w0.query_id = q0.id
            inner join email e0 on w0.email_id = e0.id
        where w0.user_id = :user_id
        order by w0.ctime desc
        ''',
        '' if offset is None else 'offset :offset',
        '' if limit is None else 'limit :limit'
    ])), user_id=user_id, offset=offset, limit=limit)
    return [bunchr(**row) for row in result.fetchall()]
开发者ID:Answeror,项目名称:torabot,代码行数:25,代码来源:watch.py


示例10: count_recent_notice_bi_user_id

def count_recent_notice_bi_user_id(conn, user_id, interval):
    return conn.execute(sql(
        '''
        select count(1) from notice
        where user_id = :user_id and ctime >= :begin
        '''
    ), user_id=user_id, begin=datetime.utcnow() - interval).fetchone()[0]
开发者ID:Answeror,项目名称:torabot,代码行数:7,代码来源:notice.py


示例11: update_email_bi_id

def update_email_bi_id(conn, id, email, label):
    conn.execute(
        sql('update email set text = :text, label = :label where id = :id'),
        id=id,
        text=email,
        label=label
    )
开发者ID:Answeror,项目名称:torabot,代码行数:7,代码来源:user.py


示例12: set_next_sync_time_bi_kind_and_text

def set_next_sync_time_bi_kind_and_text(conn, kind, text, time):
    conn.execute(sql(
        '''
        update query set next_sync_time = :time
        where kind = :kind and text = :text
        '''
    ), kind=kind, text=text, time=time)
开发者ID:Answeror,项目名称:torabot,代码行数:7,代码来源:query.py


示例13: get_user_detail_bi_id

def get_user_detail_bi_id(conn, id):
    return enrich(conn, conn.execute(sql(
        '''
        select u0.*, (select count(1) from watch as w0 where w0.user_id = u0.id) watch_count
        from "user" as u0
        where u0.id = :id
        '''
    ), id=id).fetchone())
开发者ID:Answeror,项目名称:torabot,代码行数:8,代码来源:user.py


示例14: get_email_watch_states

def get_email_watch_states(conn, user_id, query_id):
    return [bunchr(**row) for row in conn.execute(sql(
        '''
        select e0.*, (select count(1) from watch as w0 where w0.email_id = e0.id and w0.query_id = :query_id) watching
        from email e0
        where e0.user_id = :user_id
        order by e0.ctime
        '''
    ), user_id=user_id, query_id=query_id).fetchall()]
开发者ID:Answeror,项目名称:torabot,代码行数:9,代码来源:watch.py


示例15: get_active_query_count

def get_active_query_count(conn):
    return conn.execute(sql(
        '''
        select count(1) from query as q0
        where exists (
            select 1 from watch as w0
            where w0.query_id = q0.id
        )
        '''
    )).fetchone()[0]
开发者ID:Answeror,项目名称:torabot,代码行数:10,代码来源:query.py


示例16: add_email_bi_user_id

def add_email_bi_user_id(conn, id, email, label):
    # http://stackoverflow.com/a/14485817/238472
    if not email or parseaddr(email) == ('', ''):
        raise InvalidEmailError(email)
    return conn.execute(sql(
        '''
        insert into email (text, label, user_id)
        values (:text, :label, :user_id)
        returning *
        '''
    ), text=email, label=label, user_id=id).fetchone()[0]
开发者ID:Answeror,项目名称:torabot,代码行数:11,代码来源:user.py


示例17: get_users_detail

def get_users_detail(conn, offset=None, limit=None):
    result = conn.execute(sql('\n'.join([
        '''
        select u0.*, (select count(1) from watch as w0 where w0.user_id = u0.id) watch_count
        from "user" as u0
        order by u0.id
        ''',
        '' if offset is None else 'offset :offset',
        '' if limit is None else 'limit :limit'
    ])), **dict(offset=offset, limit=limit))
    return [bunchr(**row) for row in result.fetchall()]
开发者ID:funagi,项目名称:torabot,代码行数:11,代码来源:user.py


示例18: unwatch

def unwatch(conn, query_id, user_id=None, email_id=None):
    user_id, email_id = fill_id(conn, user_id, email_id)
    if user_id is None or email_id is None:
        return

    conn.execute(sql(
        '''
        delete from watch
        where email_id = :email_id and query_id = :query_id
        '''
    ), email_id=email_id, query_id=query_id)
开发者ID:Answeror,项目名称:torabot,代码行数:11,代码来源:watch.py


示例19: rename_watch

def rename_watch(conn, query_id, name, user_id=None, email_id=None):
    user_id, email_id = fill_id(conn, user_id, email_id)
    if user_id is None or email_id is None:
        return

    conn.execute(sql(
        '''
        update watch set name = :name
        where email_id = :email_id and query_id = :query_id
        '''
    ), email_id=email_id, query_id=query_id, name=name)
开发者ID:Answeror,项目名称:torabot,代码行数:11,代码来源:watch.py


示例20: get_queries

def get_queries(conn, offset=None, limit=None, order_by=None, desc=False):
    ignore_none(check_order_field)(order_by)
    result = conn.execute(sql('\n'.join([
        '''
        select * from query as q0
        ''',
        '' if order_by is None else 'order by q0.%s' % order_by,
        '' if order_by is None or not desc else 'desc',
        '' if offset is None else 'offset :offset',
        '' if limit is None else 'limit :limit'
    ])), **dict(offset=offset, limit=limit))
    return [mq(**row) for row in result.fetchall()]
开发者ID:Answeror,项目名称:torabot,代码行数:12,代码来源:query.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python sql.sqltext函数代码示例发布时间:2022-05-27
下一篇:
Python sql.select函数代码示例发布时间: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