本文整理汇总了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
示例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()
示例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()
示例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))
示例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"))
示例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))
示例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,
)
示例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()
示例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
示例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()
示例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
示例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)
示例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)))
示例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