1. DB연결 함수 생성
def get_timeline(user_id):
timeline = current_app.database.execute(text("""
SELECT
t.user_id,
t.tweet
FROM tweets t
LEFT JOIN users_follow_list ufl ON ufl.user_id = :user_id
WHERE t.user_id = :user_id
OR t.user_id = ufl.follow_user_id
"""), {
'user_id' : user_id
}).fetchall()
return [{
'user_id' : tweet['user_id'],
'tweet' : tweet['tweet']
} for tweet in timeline]
2. HTTP 요청
http -v POST 127.0.0.1:5000/tweet id=4 tweet="Iam Natasha"
DB 확인
Database 정리
1. 데이터베이스란?
2. 종류 : RDBMS, NoSQL
3. 관계형 데이터베이스의 상호 관련성 종류: one to one, one to many, many to many
4. primary key, foreign key
5. transaction
6. SQL
7. sqlalchemy (ORM) : DB 연결, 쿼리문 실행, 함수(creat_engine, text)
8. Flask의 어플리케이션 팩토리 함수
'Python > Flask' 카테고리의 다른 글
[미니터] 인증 - sign-up, login (0) | 2022.07.14 |
---|---|
[미니터] 인증 (0) | 2022.07.14 |
[미니터] DB연결 - 팔로우와 언팔로우 (0) | 2022.07.14 |
[미니터] DB연결 - tweet 올리기 (0) | 2022.07.14 |
[미니터] DB 연결 - 회원가입 (0) | 2022.07.12 |