小程序后端补充数据库兼容层与启动适配
This commit is contained in:
@@ -8,11 +8,13 @@ from sqlalchemy.orm import Session
|
||||
try:
|
||||
# For module mode: `uvicorn app.main:app`
|
||||
from app.db import get_db
|
||||
from app.db_compat import current_timestamp_sql
|
||||
from app.schemas.auth import LoginRequest, LoginResponse
|
||||
from app.security import create_access_token
|
||||
except ModuleNotFoundError:
|
||||
# For script mode: `python app/main.py` or VS Code "Run Python File"
|
||||
from db import get_db
|
||||
from db_compat import current_timestamp_sql
|
||||
from schemas.auth import LoginRequest, LoginResponse
|
||||
from security import create_access_token
|
||||
|
||||
@@ -34,6 +36,7 @@ def login(
|
||||
db: Session = Depends(get_db),
|
||||
) -> LoginResponse:
|
||||
username_masked = _mask_username(payload.username)
|
||||
now_sql = current_timestamp_sql(db)
|
||||
with db.begin():
|
||||
row = (
|
||||
db.execute(
|
||||
@@ -107,10 +110,10 @@ def login(
|
||||
|
||||
db.execute(
|
||||
text(
|
||||
"""
|
||||
f"""
|
||||
UPDATE chat_user_auth
|
||||
SET last_login_at = CURRENT_TIMESTAMP(3),
|
||||
updated_at = CURRENT_TIMESTAMP(3)
|
||||
SET last_login_at = {now_sql},
|
||||
updated_at = {now_sql}
|
||||
WHERE id = :user_auth_id
|
||||
"""
|
||||
),
|
||||
@@ -118,10 +121,10 @@ def login(
|
||||
)
|
||||
db.execute(
|
||||
text(
|
||||
"""
|
||||
f"""
|
||||
UPDATE chat_user
|
||||
SET last_login_at = CURRENT_TIMESTAMP(3),
|
||||
updated_at = CURRENT_TIMESTAMP(3)
|
||||
SET last_login_at = {now_sql},
|
||||
updated_at = {now_sql}
|
||||
WHERE id = :user_id
|
||||
"""
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user