Created
March 22, 2021 18:53
-
-
Save Marto32/007703611f0b3454b24ac1952da5ba27 to your computer and use it in GitHub Desktop.
Example that throws exception.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Created to illustrate an example for: | |
# https://github.com/sqlalchemy/sqlalchemy/issues/6102 | |
from typing import List | |
from sqlalchemy import (Column, Integer, String) | |
from sqlalchemy.ext.declarative import declarative_base | |
from sqlalchemy.orm import Session | |
Base = declarative_base() | |
class Example(Base): | |
__tablename__ = "examples" | |
id = Column(Integer, primary_key=True) | |
name = Column(String, nullable=False) | |
@classmethod | |
def get_data_by_name( | |
cls, session: Session, name: str | |
) -> List["Example"]: | |
return session.execute( | |
select(cls).where(cls.name == name) | |
).scalars().all() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment