본문 바로가기

전체 글

(411)
[Python] SQLAlchemy 업서트(upsert) - PostgreSQL * on_conflict_do_updatefrom sqlalchemy.dialects.postgresql import insertins = insert(user_table).values(id=1, name="Alice")stmt = ins.on_conflict_do_update( index_elements=['id'], # 충돌 기준 (unique 키/PK) set_={"name": "Alice Updated"} # 충돌 시 업데이트할 값)id를 기준으로 - 데이터가 없는 경우, 새로운 행 insert - 데이터가 있는 경우(충돌), 기존 행 name 컬럼 업데이트 * ins 는 SQLAlchemy Core의 (insert) 쿼리 객체* stmt 는 UPSERT를 수행할 수..
[Python] SQLAlchemy 라이브러리 SQLAlchemy Python에서 데이터베이스를 다루기 위한 ORM(Object Relational Mapping) 라이브러리.ORM 기능 : SQL문 작성 없이 Python 클래스/객체와 데이터베이스 테이블/레코드 매핑 가능.SQL 표현식 언어 : SQL을 Python 코드로 표현 가능.다양한 DB 지원 (MySQL, PostgreSQL, SQLite, Oracle 등) 1. Create_engineEngine 객체를 통해 DB와 연결. ( PostgreSQL )from sqlalchemy import create_engineengine = create_engine("postgresql+psycopg2://user:password@localhost:5432/mydb") 2. MetaData, Tab..
[JPA] 컨테이너 조회 보호되어 있는 글입니다.
[Nginx] upstream * upstream Nginx가 여러 백엔드 서버(또는 애플리케이션 서버) 로 요청을 분산(로드 밸런싱) 하기 위해 사용하는 블록. upstream backend_servers { server 192.168.0.10:5000; server 192.168.0.11:5000;}server { listen 80; location / { proxy_pass http://backend_servers; }}upstream 블록 : 이름이 backend_servers 인 서버 풀(pool)을 정의.server 블록 : 클라이언트 요청을 해당 서버 풀에 라운드로빈(Round Robin) 방식으로 전달. 나열된 순서를..
[JS / jQuery] 동적 요소 이벤트 바인딩 append() 를 사용해 동적으로 생성한 요소에 스크롤 감지 이벤트가 적용이 안됨. $target.append($ulElement)// 생략$('.scroll_ul').on('scroll', function () { console.log('스크롤 위치:', $(this).scrollTop());}); 새로운 요소 append이후 아래처럼 실행해주니 해당 요소를 잡아 이벤트가 실행된다.$target.append($ulElement)// 생략setTimeout(() => { $('.scroll_ul').on('scroll', function () { console.log('스크롤 위치:', $(this).scrollTop()); });}, 0); 자바스크립트는 단일 스레드 기반..
[1과목] 필기기출 (2021-09-12) 보호되어 있는 글입니다.
[JS] URL 객체 const u = new URL("https://test.co.kr:8000/path?query=value");u.protocol // "https:"u.hostname // "test.co.kr"u.port // "8000"u.host // "test.co.kr:8000"u.origin // "https://test.co.kr:8000"u.pathname // "/path"u.search // "?query=value"url형태의 문자열을 넣으면 자동으로 url 구성 요소들 분리 가능.문자열 정규식보다 간편하고 안전하다. 로컬/배포 환경 차이로 url 구성이 달라지는 경우,URL 객체를 활용해서 쉽게 비교.const normalize = (url) => {..
[Python] ast.literal_eval() AST(Abstract Syntax Tree, 추상 구문 트리)프로그래밍 언어에서 소스 코드를 구조적으로 표현한 트리 형태의 자료구조.파이썬은 표준 라이브러리로 ast 모듈을 제공. ast.dump() 함수AST 트리를 문자열로 출력 (디버깅용)ast.parse() 함수코드 문자열을 AST로 변환. import astcode = "x = 3 + 4"tree = ast.parse(code)print(ast.dump(tree, indent=4)) # 트리 구조 출력 (출력결과)Module( body=[ Assign( targets=[Name(id='x', ctx=Store())], value=BinOp( left=Cons..