fastAPI 심화
- Chart.js - pdf, csv 파일 업로드 후 데이터 정제하여 llm으로 처리 후 결과 도출 - sqlite로 데이터 저장 - ORM - SQLAlchemy
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import sqlite3
|
||||
import os
|
||||
|
||||
DB_PATH = "db/history.db"
|
||||
|
||||
"""
|
||||
cursor.execute('select id, name for users')
|
||||
cursor.fetchone() => (1, 'alice', '010-1234-5678')
|
||||
|
||||
row['id']
|
||||
"""
|
||||
|
||||
def get_connection():
|
||||
coon = sqlite3.connect(DB_PATH, isolation_level=None)
|
||||
# 조회 결과를 어떻게 반활할지 설정
|
||||
coon.row_factory = sqlite3.Row
|
||||
return coon
|
||||
|
||||
def init_db():
|
||||
# 디렉토리 생성
|
||||
os.makedirs("db", exist_ok=True)
|
||||
conn = get_connection()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("""create table if not exists transactions (
|
||||
id integer primary key AUTOINCREMENT,
|
||||
date text,
|
||||
category text,
|
||||
merchant text,
|
||||
amount integer
|
||||
)
|
||||
""")
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
print("DB 초기화")
|
||||
|
||||
def get_table_columns(table_name):
|
||||
conn = get_connection()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("PRAGMA table_info({})".format(table_name))
|
||||
columns = cursor.fetchall()
|
||||
conn.close()
|
||||
return [column[1] for column in columns]
|
||||
|
||||
Reference in New Issue
Block a user