본문 바로가기

전체 글825

컬럼 속성 변경 후 alembic migration할 때 ‘None’ 생기는 현상 테이블 컬럼의 속성을 변경하고 alembic migration 할 때 version 파일에 None이 생기는 현상을 발견했습니다. 의도 일단 저는 stock 테이블에서 code와 name컬럼의 속성을 unique로 변경하고자 했습니다. # models.py class Stock(Base): __tablename__ = "stock" id = Column(Integer, primary_key=True, autoincrement=True) code = Column(String(50), unique=True) # unique=True 속성 추가 name = Column(String(50), unique=True) # unique=True 속성 추가 market = Column(ENUM("KOSPI", "KOS.. 2022. 4. 26.
Apparently-Modifying Strings Description: For every string, after every occurrence of 'and' and/or 'but', insert the substring 'apparently' directly after the occurrence(s). If input does not contain 'and' or 'but', return the same string. If a blank string, return ''. If substring 'apparently' is already directly after an 'and' and/or 'but', do not add another. (Do not add duplicates). Examples: Input 1 'It was great and I.. 2022. 4. 26.
SQLAlchemy 1.x 와 2.0의 Query 스타일 비교 SQLAlchemy 2.0 SQLAlchemy 2.0에서는 query를 생성할 때 2.0 스타일을 사용할 수 있습니다. 2.0 스타일은 기존의 Session.query()가 아닌 select() 등의 메소드로 생성한 쿼리를 Session.execute()로 전달하여 DB와 통신할 수 있습니다. 현재 공식문서에서는 기존 스타일의 ORM을 제거할 계획은 없다고 하며, 어떤 스타일이든 함께 사용할 수 있다고 합니다. 다만, SQLAlchemy를 비동기로 구현할 경우 AsyncSession 클래스는 Session.query()를 지원하지 않으므로 2.0 스타일을 사용해야합니다. Within the ORM, 2.0 style query execution is supported, using select() cons.. 2022. 4. 25.
SQLAlchemy에서의 비동기 쿼리 (feat. 2.0 Style) AsyncSession을 통한 비동기 DB 통신 SQLAlchemy 에서는 DB와 비동기로 통신하기 위해서 AsyncSession 을 사용합니다. 그런데 AsyncSession을 사용하게 되면 ORM방식도 바뀌는데요. SQLAlchemy 공식문서에서는 2.0 스타일 쿼리를 사용한다고 합니다. Synopsis - ORM Using 2.0 style querying, the [AsyncSession] class provides full ORM functionality. Within the default mode of use, special care must be taken to avoid lazy loading or other expired-attribute access involving ORM relati.. 2022. 4. 24.
The Office I - Outed Description: Your colleagues have been looking over you shoulder. When you should have been doing your boring real job, you've been using the work computers to smash in endless hours of codewars. In a team meeting, a terrible, awful person declares to the group that you aren't working. You're in trouble. You quickly have to gauge the feeling in the room to decide whether or not you should gather.. 2022. 4. 24.
Shortest Word Description: Simple, given a string of words, return the length of the shortest word(s). String will never be empty and you do not need to account for different data types. Solution: 1. Count the number of letters in each word. 2. Returns the smallest number of characters. def find_short(s): return min(list(map(len, s.split()))) 2022. 4. 23.