Skip to content

Instantly share code, notes, and snippets.

@Marto32
Created March 22, 2021 18:53
Show Gist options
  • Save Marto32/007703611f0b3454b24ac1952da5ba27 to your computer and use it in GitHub Desktop.
Save Marto32/007703611f0b3454b24ac1952da5ba27 to your computer and use it in GitHub Desktop.
Example that throws exception.
# 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