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


Python base.Connection方法代码示例

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


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

示例1: parse_bind

# 需要导入模块: from sqlalchemy.engine import base [as 别名]
# 或者: from sqlalchemy.engine.base import Connection [as 别名]
def parse_bind(bind):
    """Parses a connection string and creates SQL trace metadata"""
    if isinstance(bind, Connection):
        engine = bind.engine
    else:
        engine = bind
    m = re.match(r"Engine\((.*?)\)", str(engine))
    if m is not None:
        u = urlparse(m.group(1))
        # Add Scheme to uses_netloc or // will be missing from url.
        uses_netloc.append(u.scheme)
        safe_url = ""
        if u.password is None:
            safe_url = u.geturl()
        else:
            # Strip password from URL
            host_info = u.netloc.rpartition('@')[-1]
            parts = u._replace(netloc='{}@{}'.format(u.username, host_info))
            safe_url = parts.geturl()
        sql = {}
        sql['database_type'] = u.scheme
        sql['url'] = safe_url
        if u.username is not None:
            sql['user'] = "{}".format(u.username)
    return sql 
开发者ID:aws,项目名称:aws-xray-sdk-python,代码行数:27,代码来源:decorators.py

示例2: after_insert

# 需要导入模块: from sqlalchemy.engine import base [as 别名]
# 或者: from sqlalchemy.engine.base import Connection [as 别名]
def after_insert(
        cls,
        mapper: Mapper,
        connection: Connection,
        target: Union["Dashboard", "FavStar", "Slice"],
    ) -> None:
        # pylint: disable=unused-argument
        session = Session(bind=connection)

        # add `owner:` tags
        cls._add_owners(session, target)

        # add `type:` tags
        tag = get_tag("type:{0}".format(cls.object_type), session, TagTypes.type)
        tagged_object = TaggedObject(
            tag_id=tag.id, object_id=target.id, object_type=cls.object_type
        )
        session.add(tagged_object)

        session.commit() 
开发者ID:apache,项目名称:incubator-superset,代码行数:22,代码来源:tags.py

示例3: after_delete

# 需要导入模块: from sqlalchemy.engine import base [as 别名]
# 或者: from sqlalchemy.engine.base import Connection [as 别名]
def after_delete(
        cls,
        mapper: Mapper,
        connection: Connection,
        target: Union["Dashboard", "FavStar", "Slice"],
    ) -> None:
        # pylint: disable=unused-argument
        session = Session(bind=connection)

        # delete row from `tagged_objects`
        session.query(TaggedObject).filter(
            TaggedObject.object_type == cls.object_type,
            TaggedObject.object_id == target.id,
        ).delete()

        session.commit() 
开发者ID:apache,项目名称:incubator-superset,代码行数:18,代码来源:tags.py

示例4: _upsert_postgres

# 需要导入模块: from sqlalchemy.engine import base [as 别名]
# 或者: from sqlalchemy.engine.base import Connection [as 别名]
def _upsert_postgres(self: T, conn: Connection) -> None:
        conn.execute(pg_insert(self.t).values(**self._insert_values)
                     .on_conflict_do_update(constraint=self.t.primary_key,
                                            set_=self._upsert_values)) 
开发者ID:tulir,项目名称:mautrix-python,代码行数:6,代码来源:base.py

示例5: _upsert_sqlite

# 需要导入模块: from sqlalchemy.engine import base [as 别名]
# 或者: from sqlalchemy.engine.base import Connection [as 别名]
def _upsert_sqlite(self: T, conn: Connection) -> None:
        conn.execute(self.t.insert().values(**self._insert_values).prefix_with("OR REPLACE")) 
开发者ID:tulir,项目名称:mautrix-python,代码行数:4,代码来源:base.py

示例6: _upsert_generic

# 需要导入模块: from sqlalchemy.engine import base [as 别名]
# 或者: from sqlalchemy.engine.base import Connection [as 别名]
def _upsert_generic(self: T, conn: Connection):
        conn.execute(self.t.delete().where(self._edit_identity))
        conn.execute(self.t.insert().values(**self._insert_values)) 
开发者ID:tulir,项目名称:mautrix-python,代码行数:5,代码来源:base.py

示例7: test_no_branching

# 需要导入模块: from sqlalchemy.engine import base [as 别名]
# 或者: from sqlalchemy.engine.base import Connection [as 别名]
def test_no_branching(self, connection):
        assert_raises_message(
            NotImplementedError,
            "sqlalchemy.future.Connection does not support "
            "'branching' of new connections.",
            connection.connect,
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:9,代码来源:test_execute.py

示例8: copy_dashboard

# 需要导入模块: from sqlalchemy.engine import base [as 别名]
# 或者: from sqlalchemy.engine.base import Connection [as 别名]
def copy_dashboard(mapper: Mapper, connection: Connection, target: "Dashboard") -> None:
    # pylint: disable=unused-argument
    dashboard_id = config["DASHBOARD_TEMPLATE_ID"]
    if dashboard_id is None:
        return

    session_class = sessionmaker(autoflush=False)
    session = session_class(bind=connection)
    new_user = session.query(User).filter_by(id=target.id).first()

    # copy template dashboard to user
    template = session.query(Dashboard).filter_by(id=int(dashboard_id)).first()
    dashboard = Dashboard(
        dashboard_title=template.dashboard_title,
        position_json=template.position_json,
        description=template.description,
        css=template.css,
        json_metadata=template.json_metadata,
        slices=template.slices,
        owners=[new_user],
    )
    session.add(dashboard)
    session.commit()

    # set dashboard as the welcome dashboard
    extra_attributes = UserAttribute(
        user_id=target.id, welcome_dashboard_id=dashboard.id
    )
    session.add(extra_attributes)
    session.commit() 
开发者ID:apache,项目名称:incubator-superset,代码行数:32,代码来源:dashboard.py

示例9: event_after_dashboard_changed

# 需要导入模块: from sqlalchemy.engine import base [as 别名]
# 或者: from sqlalchemy.engine.base import Connection [as 别名]
def event_after_dashboard_changed(  # pylint: disable=unused-argument
    mapper: Mapper, connection: Connection, target: Dashboard
) -> None:
    cache_dashboard_thumbnail.delay(target.id, force=True)


# events for updating tags 
开发者ID:apache,项目名称:incubator-superset,代码行数:9,代码来源:dashboard.py

示例10: after_update

# 需要导入模块: from sqlalchemy.engine import base [as 别名]
# 或者: from sqlalchemy.engine.base import Connection [as 别名]
def after_update(
        cls,
        mapper: Mapper,
        connection: Connection,
        target: Union["Dashboard", "FavStar", "Slice"],
    ) -> None:
        # pylint: disable=unused-argument
        session = Session(bind=connection)

        # delete current `owner:` tags
        query = (
            session.query(TaggedObject.id)
            .join(Tag)
            .filter(
                TaggedObject.object_type == cls.object_type,
                TaggedObject.object_id == target.id,
                Tag.type == TagTypes.owner,
            )
        )
        ids = [row[0] for row in query]
        session.query(TaggedObject).filter(TaggedObject.id.in_(ids)).delete(
            synchronize_session=False
        )

        # add `owner:` tags
        cls._add_owners(session, target)

        session.commit() 
开发者ID:apache,项目名称:incubator-superset,代码行数:30,代码来源:tags.py

示例11: set_related_perm

# 需要导入模块: from sqlalchemy.engine import base [as 别名]
# 或者: from sqlalchemy.engine.base import Connection [as 别名]
def set_related_perm(mapper: Mapper, connection: Connection, target: Slice) -> None:
    # pylint: disable=unused-argument
    src_class = target.cls_model
    id_ = target.datasource_id
    if id_:
        ds = db.session.query(src_class).filter_by(id=int(id_)).first()
        if ds:
            target.perm = ds.perm
            target.schema_perm = ds.schema_perm 
开发者ID:apache,项目名称:incubator-superset,代码行数:11,代码来源:slice.py

示例12: event_after_chart_changed

# 需要导入模块: from sqlalchemy.engine import base [as 别名]
# 或者: from sqlalchemy.engine.base import Connection [as 别名]
def event_after_chart_changed(  # pylint: disable=unused-argument
    mapper: Mapper, connection: Connection, target: Slice
) -> None:
    cache_chart_thumbnail.delay(target.id, force=True) 
开发者ID:apache,项目名称:incubator-superset,代码行数:6,代码来源:slice.py

示例13: unique_sounds

# 需要导入模块: from sqlalchemy.engine import base [as 别名]
# 或者: from sqlalchemy.engine.base import Connection [as 别名]
def unique_sounds(conn: Connection, corpus_id: int) -> [str]:
    sql = """
        select distinct rhyme_sound
        from phrases p
        join corpora_sources cs
        on p.source_id = cs.source_id
        where corpus_id = :corpus_id
    """
    result = conn.execute(sa.text(sql).params(corpus_id=corpus_id)).fetchall()
    return list(filter(lambda r: r is not None, map(lambda r: r[0], result))) 
开发者ID:vilmibm,项目名称:prosaic,代码行数:12,代码来源:generation.py

示例14: map_letters_to_sounds

# 需要导入模块: from sqlalchemy.engine import base [as 别名]
# 或者: from sqlalchemy.engine.base import Connection [as 别名]
def map_letters_to_sounds(conn: Connection, corpus_id: int, template, sound_cache=None):
    letters = list(set(pluck(template, "rhyme")))
    if is_empty(letters):
        cache = {}
    else:
        sounds = sound_cache if sound_cache is not None else unique_sounds(conn, corpus_id)
        cache = dict(map(lambda l: [l, choice(sounds)], letters))
    return cache 
开发者ID:vilmibm,项目名称:prosaic,代码行数:10,代码来源:generation.py


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