Skip to Content
파이썬으로 살펴보는 아키텍처 패턴
book

파이썬으로 살펴보는 아키텍처 패턴

by 오현석, 해리 퍼시벌, 밥 그레고리
June 2021
Beginner to intermediate
356 pages
8h 13m
Korean
Hanbit Media, Inc.
Content preview from 파이썬으로 살펴보는 아키텍처 패턴
101
4
첫 번째 유스 케이스: 플라스크 API와 서비스 계층
사람들은 다양한 방법으로 이런 문제를 해결한다. 하지만 여기에서는 플라스크를 (특히 컨테
이너 내부에서) 시작하고,
Postgres
데이터베이스와 통신할 방법이 필요하다. 필자들이 어떻
게 처리했는지 보고 싶은 독자는 부록
B
를 참조하기 바란다.
4.3
직접 구현하기
이 모든 요소를 가장 뻔한 방법으로 구현하면 코드가 다음과 비슷하다.
플라스크 앱의 첫 번째 버전(
flask
_
app
.
py
)
from flask import Flask, jsonify, request
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
import config
import model
import orm
import repository
orm.start_mappers()
get_session = sessionmaker(bind=create_engine(config.get_postgres_uri()))
app = Flask(__name__)
@app.route(“/allocate”, methods=[‘POST’])
def allocate_endpoint():
session = get_session()
batches = repository.SqlAlchemyRepository(session).list() ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

효율적인 리눅스 명령어 사용의 기술

효율적인 리눅스 명령어 사용의 기술

Daniel J Barrett
쿠버네티스를 활용한 클라우드 네이티브 데브옵스

쿠버네티스를 활용한 클라우드 네이티브 데브옵스

최경현, 저스틴 도밍거스, 존 어런들

Publisher Resources

ISBN: 9791162244319