Flask
Flask postman mysql
leopard4
2023. 1. 6. 14:21
셀렉한 컬럼만 가져온다
유저아이디가 = 6인것
datetime 으로 내림차순 정렬
0부터 3개 까지
SELECT id, title, datetime, content, createdAt, updatedAt
FROM memo
where userId = 6
order by datetime desc
limit 0, 3;
# 클라이언트에서 쿼리스트링으로 보내는 데이터는
# request.args.get('키값', '기본값') 으로 받아온다.
# 키값은 쿼리 스트링과 같아야한다.
offset = request.args.get('offset') # page가 없으면 1을 가져온다.
limit = request.args.get('limit') # limit가 없으면 3을 가져온다.
# 2. db에 저장된 데이터를 가져온다.
try :
### 3 . DB 연결
# mysql_connection.py 에서 만든 함수를 호출
connection = get_connection()
### 4. 쿼리문 만들기
query = '''
SELECT id, title, datetime, content, createdAt, updatedAt
FROM memo
where userId = %s
order by datetime desc
limit ''' + offset +''', ''' + limit + ''';
'''
# %s 는 = 기호가 있을때만 사용하는것.
record = (user_id, )