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


Python engine.Connection方法代码示例

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


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

示例1: bind

# 需要导入模块: from sqlalchemy import engine [as 别名]
# 或者: from sqlalchemy.engine import Connection [as 别名]
def bind(self):
        """Return the current "bind".

        In online mode, this is an instance of
        :class:`sqlalchemy.engine.Connection`, and is suitable
        for ad-hoc execution of any kind of usage described
        in :ref:`sqlexpression_toplevel` as well as
        for usage with the :meth:`sqlalchemy.schema.Table.create`
        and :meth:`sqlalchemy.schema.MetaData.create_all` methods
        of :class:`~sqlalchemy.schema.Table`,
        :class:`~sqlalchemy.schema.MetaData`.

        Note that when "standard output" mode is enabled,
        this bind will be a "mock" connection handler that cannot
        return results and is only appropriate for a very limited
        subset of commands.

        """
        return self.connection 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:21,代码来源:migration.py

示例2: auction_model_with_a_bid

# 需要导入模块: from sqlalchemy import engine [as 别名]
# 或者: from sqlalchemy.engine import Connection [as 别名]
def auction_model_with_a_bid(
    connection: Connection, winning_bid_amount: Decimal, bidder_id: int, ends_at: datetime
) -> RowProxy:
    connection.execute(
        auctions.insert().values(
            {
                "id": 1,
                "title": "Cool socks",
                "starting_price": winning_bid_amount / 2,
                "current_price": winning_bid_amount,
                "ends_at": ends_at,
                "ended": False,
            }
        )
    )
    connection.execute(bids.insert().values({"amount": winning_bid_amount, "auction_id": 1, "bidder_id": bidder_id}))
    return connection.execute(auctions.select(whereclause=auctions.c.id == 1)).first() 
开发者ID:Enforcer,项目名称:clean-architecture,代码行数:19,代码来源:test_sqlalchemy_auctions_repository.py

示例3: test_removes_withdrawn_bids

# 需要导入模块: from sqlalchemy import engine [as 别名]
# 或者: from sqlalchemy.engine import Connection [as 别名]
def test_removes_withdrawn_bids(
    connection: Connection, bid_model: RowProxy, auction_model_with_a_bid: dict, ends_at: datetime, event_bus_mock: Mock
) -> None:
    auction = Auction(
        id=auction_model_with_a_bid.id,
        title=auction_model_with_a_bid.title,
        starting_price=get_dollars(auction_model_with_a_bid.starting_price),
        ends_at=ends_at,
        bids=[Bid(bid_model.id, bid_model.bidder_id, get_dollars(bid_model.amount))],
        ended=False,
    )
    auction.withdraw_bids([bid_model.id])

    SqlAlchemyAuctionsRepo(connection, event_bus_mock).save(auction)

    assert connection.execute(select([func.count()]).select_from(bids)).scalar() == 0 
开发者ID:Enforcer,项目名称:clean-architecture,代码行数:18,代码来源:test_sqlalchemy_auctions_repository.py

示例4: test_AuctionsRepo_UponSavingAuction_ClearsPendingEvents

# 需要导入模块: from sqlalchemy import engine [as 别名]
# 或者: from sqlalchemy.engine import Connection [as 别名]
def test_AuctionsRepo_UponSavingAuction_ClearsPendingEvents(
    connection: Connection, another_bidder_id: int, auction_model_with_a_bid: RowProxy, event_bus_mock: Mock
) -> None:
    repo = SqlAlchemyAuctionsRepo(connection, event_bus_mock)
    auction = repo.get(auction_model_with_a_bid.id)
    auction.place_bid(another_bidder_id, auction.current_price + get_dollars("1.00"))

    repo.save(auction)

    assert len(auction.domain_events) == 0


# @pytest.mark.usefixtures("transaction")
# def test_AuctionsRepo_UponSavingAuction_PostsPendingEventsViaEventBus(
#     connection: Connection, another_bidder_id: int, auction_model_with_a_bid: RowProxy, event_bus_stub: EventBusStub
# ) -> None:
#     repo = SqlAlchemyAuctionsRepo(connection, event_bus_stub)
#     auction = repo.get(auction_model_with_a_bid.id)
#     auction.place_bid(another_bidder_id, auction.current_price + get_dollars("1.00"))
#
#     repo.save(auction)
#
#     event_bus_stub.events 
开发者ID:Enforcer,项目名称:clean-architecture,代码行数:25,代码来源:test_sqlalchemy_auctions_repository.py

示例5: test_create_drop_constructor_bound

# 需要导入模块: from sqlalchemy import engine [as 别名]
# 或者: from sqlalchemy.engine import Connection [as 别名]
def test_create_drop_constructor_bound(self):
        for bind in (testing.db, testing.db.connect()):
            try:
                for args in (([bind], {}), ([], {"bind": bind})):
                    metadata = MetaData(*args[0], **args[1])
                    table = Table(
                        "test_table", metadata, Column("foo", Integer)
                    )
                    assert metadata.bind is table.bind is bind
                    metadata.create_all()
                    is_true(inspect(bind).has_table(table.name))
                    metadata.drop_all()
                    table.create()
                    table.drop()
                    is_false(inspect(bind).has_table(table.name))
            finally:
                if isinstance(bind, engine.Connection):
                    bind.close() 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:20,代码来源:test_bind.py

示例6: db_connection

# 需要导入模块: from sqlalchemy import engine [as 别名]
# 或者: from sqlalchemy.engine import Connection [as 别名]
def db_connection(module_scoped_container_getter) -> Connection:
    retries = 60
    while True:
        try:
            connection = get_connection()
            try:
                yield connection
            finally:
                if not connection.closed:
                    connection.close()
                break
        except Exception as e:
            print(str(e))
            if retries > 0:
                retries -= 1
                time.sleep(1)
                continue
            raise 
开发者ID:koxudaxi,项目名称:py-data-api,代码行数:20,代码来源:test_mysql.py

示例7: create_sa_connection

# 需要导入模块: from sqlalchemy import engine [as 别名]
# 或者: from sqlalchemy.engine import Connection [as 别名]
def create_sa_connection(con, **kwargs):
    import sqlalchemy as sa
    from sqlalchemy.engine import Connection, Engine

    # process con
    engine = None
    if isinstance(con, Connection):
        # connection create by user
        close = False
        dispose = False
    elif isinstance(con, Engine):
        con = con.connect()
        close = True
        dispose = False
    else:
        engine = sa.create_engine(con, **kwargs)
        con = engine.connect()
        close = True
        dispose = True

    try:
        yield con
    finally:
        if close:
            con.close()
        if dispose:
            engine.dispose() 
开发者ID:mars-project,项目名称:mars,代码行数:29,代码来源:utils.py

示例8: start_new_payment

# 需要导入模块: from sqlalchemy import engine [as 别名]
# 或者: from sqlalchemy.engine import Connection [as 别名]
def start_new_payment(payment_uuid: UUID, customer_id: int, amount: Money, description: str, conn: Connection) -> None:
    conn.execute(
        payments.insert(
            {
                "uuid": str(payment_uuid),
                "customer_id": customer_id,
                "amount": int(amount.amount) * 100,
                "currency": amount.currency.iso_code,
                "description": description,
                "status": PaymentStatus.NEW.value,
            }
        )
    ) 
开发者ID:Enforcer,项目名称:clean-architecture,代码行数:15,代码来源:dao.py

示例9: get_pending_payments

# 需要导入模块: from sqlalchemy import engine [as 别名]
# 或者: from sqlalchemy.engine import Connection [as 别名]
def get_pending_payments(customer_id: int, conn: Connection) -> List[PaymentDto]:
    rows = conn.execute(
        payments.select((payments.c.customer_id == customer_id) & (payments.c.status == PaymentStatus.NEW.value))
    ).fetchall()
    return [PaymentDto.from_row(row) for row in rows] 
开发者ID:Enforcer,项目名称:clean-architecture,代码行数:7,代码来源:dao.py

示例10: get_payment

# 需要导入模块: from sqlalchemy import engine [as 别名]
# 或者: from sqlalchemy.engine import Connection [as 别名]
def get_payment(payment_uuid: UUID, customer_id: int, conn: Connection) -> PaymentDto:
    row = conn.execute(
        payments.select((payments.c.customer_id == customer_id) & (payments.c.uuid == str(payment_uuid)))
    ).first()
    return PaymentDto.from_row(row) 
开发者ID:Enforcer,项目名称:clean-architecture,代码行数:7,代码来源:dao.py

示例11: get_payment_charge_id

# 需要导入模块: from sqlalchemy import engine [as 别名]
# 或者: from sqlalchemy.engine import Connection [as 别名]
def get_payment_charge_id(payment_uuid: UUID, customer_id: int, conn: Connection) -> Optional[str]:
    row = conn.execute(
        payments.select((payments.c.customer_id == customer_id) & (payments.c.uuid == str(payment_uuid)))
    ).first()
    return str(row.charge_id) if row.charge_id else None 
开发者ID:Enforcer,项目名称:clean-architecture,代码行数:7,代码来源:dao.py

示例12: update_payment

# 需要导入模块: from sqlalchemy import engine [as 别名]
# 或者: from sqlalchemy.engine import Connection [as 别名]
def update_payment(payment_uuid: UUID, customer_id: int, values: dict, conn: Connection) -> None:
    conn.execute(
        payments.update()
        .where((payments.c.uuid == str(payment_uuid)) & (payments.c.customer_id == customer_id))
        .values(**values)
    ) 
开发者ID:Enforcer,项目名称:clean-architecture,代码行数:8,代码来源:dao.py

示例13: facade

# 需要导入模块: from sqlalchemy import engine [as 别名]
# 或者: from sqlalchemy.engine import Connection [as 别名]
def facade(connection: Connection, event_bus: Mock) -> PaymentsFacade:
    return PaymentsFacade(PaymentsConfig("", ""), connection, event_bus) 
开发者ID:Enforcer,项目名称:clean-architecture,代码行数:4,代码来源:test_facade.py

示例14: inserted_payment

# 需要导入模块: from sqlalchemy import engine [as 别名]
# 或者: from sqlalchemy.engine import Connection [as 别名]
def inserted_payment(request: SubRequest, connection: Connection) -> dict:
    status = getattr(request, "param", None) or PaymentStatus.NEW.value
    charge_id = None if status not in (PaymentStatus.CHARGED.value, PaymentStatus.CAPTURED.value) else "token"
    data: Dict[str, Any] = {
        "uuid": str(uuid.uuid4()),
        "customer_id": 1,
        "amount": 100,
        "currency": "USD",
        "status": status,
        "description": "irrelevant",
        "charge_id": charge_id,
    }
    connection.execute(payments.insert(data))
    return data 
开发者ID:Enforcer,项目名称:clean-architecture,代码行数:16,代码来源:test_facade.py

示例15: get_payment

# 需要导入模块: from sqlalchemy import engine [as 别名]
# 或者: from sqlalchemy.engine import Connection [as 别名]
def get_payment(connection: Connection, payment_uuid: str) -> RowProxy:
    row = connection.execute(payments.select(payments.c.uuid == payment_uuid)).first()
    return row 
开发者ID:Enforcer,项目名称:clean-architecture,代码行数:5,代码来源:test_facade.py


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