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


Python sqlalchemy.bindparam方法代码示例

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


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

示例1: cleanup_expired

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import bindparam [as 别名]
def cleanup_expired(self, max_age_in_seconds):
        cutoff = timestamp() - max_age_in_seconds * 1000
        with self.db.begin() as conn:
            to_delete = conn.execute(
                sa.select([clusters.c.id]).where(clusters.c.stop_time < cutoff)
            ).fetchall()

            if to_delete:
                to_delete = [i for i, in to_delete]

                conn.execute(
                    clusters.delete().where(clusters.c.id == sa.bindparam("id")),
                    [{"id": i} for i in to_delete],
                )

                for i in to_delete:
                    cluster = self.id_to_cluster.pop(i)
                    self.name_to_cluster.pop(cluster.name, None)
                    user_clusters = self.username_to_clusters[cluster.username]
                    user_clusters.pop(cluster.name)
                    if not user_clusters:
                        self.username_to_clusters.pop(cluster.username)

        return len(to_delete) 
开发者ID:dask,项目名称:dask-gateway,代码行数:26,代码来源:db_base.py

示例2: get_pending_or_processing_ops

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import bindparam [as 别名]
def get_pending_or_processing_ops(context, object_uuid, operation=None):
    # NOTE (sai): For performance reasons, we expect this method to use baked
    # query (http://docs.sqlalchemy.org/en/latest/orm/extensions/baked.html)
    baked_query = bakery(lambda s: s.query(
        models.OpenDaylightJournal))
    baked_query += lambda q: q.filter(
        or_(models.OpenDaylightJournal.state == odl_const.PENDING,
            models.OpenDaylightJournal.state == odl_const.PROCESSING),
        models.OpenDaylightJournal.object_uuid == bindparam('uuid'))
    if operation:
        if isinstance(operation, (list, tuple)):
            baked_query += lambda q: q.filter(
                models.OpenDaylightJournal.operation.in_(bindparam('op',
                                                         expanding=True)))
        else:
            baked_query += lambda q: q.filter(
                models.OpenDaylightJournal.operation == bindparam('op'))

    return baked_query(context.session).params(
        uuid=object_uuid, op=operation).all() 
开发者ID:openstack,项目名称:networking-odl,代码行数:22,代码来源:db.py

示例3: __init__

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import bindparam [as 别名]
def __init__(self, api, db):
        super().__init__(api, db)

        ins_user = sa.dialects.postgresql.insert(db.user)
        ins_user_groups = sa.dialects.postgresql.insert(db.user_groups)

        self.sql = {
            ("insert", "user"):
                ins_user.on_conflict_do_update(
                    index_elements=[db.user.c.user_id],
                    set_={
                        "user_name":         ins_user.excluded.user_name,
                        "user_registration": ins_user.excluded.user_registration,
                        "user_editcount":    ins_user.excluded.user_editcount,
                    }),
            ("update", "user"):
                db.user.update() \
                    .where(db.user.c.user_name == sa.bindparam("b_olduser")),
            ("insert", "user_groups"):
                ins_user_groups.on_conflict_do_nothing(),
            ("delete", "user_groups"):
                db.user_groups.delete().where(
                    db.user_groups.c.ug_user == sa.bindparam("b_ug_user")),
        } 
开发者ID:lahwaacz,项目名称:wiki-scripts,代码行数:26,代码来源:user.py

示例4: __init__

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import bindparam [as 别名]
def __init__(self, api, db):
        super().__init__(api, db)

        self.sql = {
            ("delete", "user"):
                db.user.delete() \
                    .where(db.user.c.user_id == sa.bindparam("b_oldid")),
            ("update", "logging"):
                db.logging.update() \
                    .where(db.logging.c.log_user == sa.bindparam("b_oldid")),
            ("update", "ipb"):
                db.ipblocks.update() \
                    .where(db.ipblocks.c.ipb_by == sa.bindparam("b_oldid")),
            ("update", "archive"):
                db.archive.update() \
                    .where(db.archive.c.ar_user == sa.bindparam("b_oldid")),
            ("update", "revision"):
                db.revision.update() \
                    .where(db.revision.c.rev_user == sa.bindparam("b_oldid")),
        } 
开发者ID:lahwaacz,项目名称:wiki-scripts,代码行数:22,代码来源:usermerge.py

示例5: __init__

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import bindparam [as 别名]
def __init__(self, api, db):
        super().__init__(api, db)

        ins_iw = sa.dialects.postgresql.insert(db.interwiki)

        self.sql = {
            ("insert", "interwiki"):
                db.interwiki.insert(),
            ("delete", "interwiki"):
                db.interwiki.delete().where(db.interwiki.c.iw_prefix == sa.bindparam("b_iw_prefix")),
            # iw_api is not visible in the logs so it is not updated
            ("update", "interwiki"):
                ins_iw.on_conflict_do_update(
                    index_elements=[db.interwiki.c.iw_prefix],
                    set_={
                        "iw_url":   ins_iw.excluded.iw_url,
                        "iw_local": ins_iw.excluded.iw_local,
                        "iw_trans": ins_iw.excluded.iw_trans,
                    }),
        } 
开发者ID:lahwaacz,项目名称:wiki-scripts,代码行数:22,代码来源:interwiki.py

示例6: __init__

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import bindparam [as 别名]
def __init__(self, api, db):
        super().__init__(api, db)

        ins_pt = sa.dialects.postgresql.insert(db.protected_titles)

        self.sql = {
            ("insert", "protected_titles"):
                ins_pt.on_conflict_do_update(
                    index_elements=[
                        db.protected_titles.c.pt_namespace,
                        db.protected_titles.c.pt_title,
                    ],
                    set_={
                        "pt_level":  ins_pt.excluded.pt_level,
                        "pt_expiry": ins_pt.excluded.pt_expiry,
                    }),
            ("delete", "protected_titles"):
                db.protected_titles.delete().where(
                    (db.protected_titles.c.pt_namespace == sa.bindparam("b_pt_namespace")) &
                    (db.protected_titles.c.pt_title == sa.bindparam("b_pt_title"))),
        } 
开发者ID:lahwaacz,项目名称:wiki-scripts,代码行数:23,代码来源:protected_titles.py

示例7: _get_alarm_definition

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import bindparam [as 别名]
def _get_alarm_definition(self, conn, tenant_id, _id):
        ad = self.ad_s
        query = (self.base_query
                 .select_from(self.base_query_from)
                 .where(ad.c.tenant_id == bindparam('b_tenant_id'))
                 .where(ad.c.id == bindparam('b_id'))
                 .where(ad.c.deleted_at == null()))

        row = conn.execute(query,
                           b_tenant_id=tenant_id,
                           b_id=_id).fetchone()

        if row is not None:
            return dict(row)
        else:
            raise exceptions.DoesNotExistException 
开发者ID:openstack,项目名称:monasca-api,代码行数:18,代码来源:alarm_definitions_repository.py

示例8: params

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import bindparam [as 别名]
def params(self, *optionaldict, **kwargs):
        """Return a copy with :func:`_expression.bindparam` elements
        replaced.

        Returns a copy of this ClauseElement with
        :func:`_expression.bindparam`
        elements replaced with values taken from the given dictionary::

          >>> clause = column('x') + bindparam('foo')
          >>> print(clause.compile().params)
          {'foo':None}
          >>> print(clause.params({'foo':7}).compile().params)
          {'foo':7}

        """
        return self._replace_params(False, optionaldict, kwargs) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:18,代码来源:elements.py

示例9: _replace_params

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import bindparam [as 别名]
def _replace_params(self, unique, optionaldict, kwargs):
        if len(optionaldict) == 1:
            kwargs.update(optionaldict[0])
        elif len(optionaldict) > 1:
            raise exc.ArgumentError(
                "params() takes zero or one positional dictionary argument"
            )

        def visit_bindparam(bind):
            if bind.key in kwargs:
                bind.value = kwargs[bind.key]
                bind.required = False
            if unique:
                bind._convert_to_unique()

        return cloned_traverse(self, {}, {"bindparam": visit_bindparam}) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:18,代码来源:elements.py

示例10: test_multi_update_rowcount

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import bindparam [as 别名]
def test_multi_update_rowcount(self, connection):
        employees_table = self.tables.employees
        stmt = (
            employees_table.update()
            .where(employees_table.c.name == bindparam("emp_name"))
            .values(department="C")
        )

        r = connection.execute(
            stmt,
            [
                {"emp_name": "Bob"},
                {"emp_name": "Cynthia"},
                {"emp_name": "nonexistent"},
            ],
        )

        eq_(r.rowcount, 2) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:20,代码来源:test_rowcount.py

示例11: test_multi_delete_rowcount

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import bindparam [as 别名]
def test_multi_delete_rowcount(self, connection):
        employees_table = self.tables.employees

        stmt = employees_table.delete().where(
            employees_table.c.name == bindparam("emp_name")
        )

        r = connection.execute(
            stmt,
            [
                {"emp_name": "Bob"},
                {"emp_name": "Cynthia"},
                {"emp_name": "nonexistent"},
            ],
        )

        eq_(r.rowcount, 2) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:19,代码来源:test_rowcount.py

示例12: test_exception_format_hide_parameters_nondbapi_round_trip

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import bindparam [as 别名]
def test_exception_format_hide_parameters_nondbapi_round_trip(self):
        foo = Table("foo", MetaData(), Column("data", String))

        with self.no_param_engine.connect() as conn:
            assert_raises_message(
                tsa.exc.StatementError,
                r"\(sqlalchemy.exc.InvalidRequestError\) A value is required "
                r"for bind parameter 'the_data_2'\n"
                r"\[SQL: SELECT foo.data \nFROM foo \nWHERE "
                r"foo.data = \? OR foo.data = \?\]\n"
                r"\[SQL parameters hidden due to hide_parameters=True\]",
                conn.execute,
                select([foo]).where(
                    or_(
                        foo.c.data == bindparam("the_data_1"),
                        foo.c.data == bindparam("the_data_2"),
                    )
                ),
                {"the_data_1": "some data"},
            ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:22,代码来源:test_logging.py

示例13: test_no_clobs_for_string_params

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import bindparam [as 别名]
def test_no_clobs_for_string_params(self):
        """test that simple string params get a DBAPI type of
        VARCHAR, not CLOB. This is to prevent setinputsizes
        from setting up cx_oracle.CLOBs on
        string-based bind params [ticket:793]."""

        class FakeDBAPI(object):
            def __getattr__(self, attr):
                return attr

        dialect = oracle.OracleDialect()
        dbapi = FakeDBAPI()

        b = bindparam("foo", "hello world!")
        eq_(b.type.dialect_impl(dialect).get_dbapi_type(dbapi), "STRING")

        b = bindparam("foo", "hello world!")
        eq_(b.type.dialect_impl(dialect).get_dbapi_type(dbapi), "STRING") 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:20,代码来源:test_types.py

示例14: test_bindparam_quote

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import bindparam [as 别名]
def test_bindparam_quote(self):
        """test that bound parameters take on quoting for reserved words,
        column names quote flag enabled."""
        # note: this is only in cx_oracle at the moment.  not sure
        # what other hypothetical oracle dialects might need

        self.assert_compile(bindparam("option"), ':"option"')
        self.assert_compile(bindparam("plain"), ":plain")
        t = Table("s", MetaData(), Column("plain", Integer, quote=True))
        self.assert_compile(
            t.insert().values(plain=5),
            'INSERT INTO s ("plain") VALUES (:"plain")',
        )
        self.assert_compile(
            t.update().values(plain=5), 'UPDATE s SET "plain"=:"plain"'
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:18,代码来源:test_compiler.py

示例15: test_update_executemany

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import bindparam [as 别名]
def test_update_executemany(self):
        with testing.db.connect() as conn:
            timestamp = datetime.datetime(2015, 4, 17, 18, 5, 2)
            conn.execute(
                self.tables.t.insert(),
                [
                    {"x": 5, "data": timestamp},
                    {"x": 6, "data": timestamp},
                    {"x": 7, "data": timestamp},
                ],
            )

            conn.execute(
                self.tables.t.update()
                .values(data=func.utc_timestamp())
                .where(self.tables.t.c.x == bindparam("xval")),
                [{"xval": 5}, {"xval": 6}, {"xval": 7}],
            ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:20,代码来源:test_dialect.py


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