commit with Backend arch MYSQL connection done

AMB_DEV
ambag12 2026-05-07 20:01:24 +05:00
parent ddc80f04ac
commit 953f1f868f
24 changed files with 121 additions and 0 deletions

9
dev_backend/.env Normal file
View File

@ -0,0 +1,9 @@
MYSQL_HOST=localhost
MYSQL_PORT=3306
MYSQL_USER=root
MYSQL_PASSWORD='AmB@ig123'
MYSQL_DATABASE=listing_radar

Binary file not shown.

Binary file not shown.

44
dev_backend/db_setup.py Normal file
View File

@ -0,0 +1,44 @@
from __future__ import annotations
import os
from contextlib import asynccontextmanager
from typing import AsyncGenerator
from dotenv import load_dotenv
from qdrant_client import AsyncQdrantClient, models
from typing import Annotated
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sessionmaker
from sqlalchemy.orm import declarative_base
from sqlalchemy.orm import sessionmaker
# pyrefly: ignore [missing-import]
from fastapi import FastAPI, Depends
from sqlalchemy.engine.url import URL
from dotenv import load_dotenv
load_dotenv()
DATABASE_URL = URL.create(
drivername="mysql+asyncmy",
username=os.getenv("MYSQL_USER"),
password=os.getenv("MYSQL_PASSWORD"),
host=os.getenv("MYSQL_HOST"),
port=os.getenv("MYSQL_PORT"),
database=os.getenv("MYSQL_DATABASE"),
)
async def get_qdrant_client()->AsyncGenerator[AsyncQdrantClient,None]:
# Replace with your Qdrant URL
client = AsyncQdrantClient(url="http://localhost:6333", timeout=60)
try:
yield client
finally:
# Properly close the async client
await client.close()
async def get_session():
engine = create_async_engine(DATABASE_URL, echo=True)
async_session = async_sessionmaker(bind=engine, class_=AsyncSession, expire_on_commit=False)
session = async_session()
Base = declarative_base()
try:
yield session
finally:
await session.close()

15
dev_backend/main.py Normal file
View File

@ -0,0 +1,15 @@
from fastapi import FastAPI, status
from starlette.middleware.base import BaseHTTPMiddleware, RequestResponseEndpoint
from dotenv import load_dotenv
from db_setup import get_qdrant_client,get_session
from mysql_process.views import app_router
from vector_db_router.views
load_dotenv()
api = FastAPI(
docs_url="/docs",
redoc_url="/redocs",
)
api.include_router(app_router,tags=["mysql_process"])
api.include_router(vector_db_router,tags=["vector_db"])

View File

@ -0,0 +1,12 @@
from fastapi import FastAPI
from sqlmodel import SQLModel, Field
class Memory(SQLModel,table=True):
id: int = Field(default=None,primary_key=True)
product_link: str = Field(default=None,index=True)
price: float = Field(default=None)
product_image: str = Field(default=None)
product_name: str = Field(default=None)
product_description: str = Field(default=None)
product_rating: float = Field(default=None)
product_review: str = Field(default=None)

View File

@ -0,0 +1,16 @@
from fastapi import FastAPI
from pydantic import BaseModel
from .models import Memory
class MemorySerializer(BaseModel):
id: int
product_link: str
price: float
product_image: str
product_name: str
product_description: str
product_rating: float
product_review: str
class Config:
orm_mode = True

View File

@ -0,0 +1,20 @@
from typing import Annotated
from fastapi import Depends, Header, HTTPException,APIRouter
from typing import List,Optional
from db_setup import get_session,get_qdrant_client
# from .models import Product
from sqlalchemy.ext.asyncio import AsyncSession
from qdrant_client import AsyncQdrantClient
from fastapi.responses import JSONResponse
app_router = APIRouter()
@app_router.get("/products")
async def get_all_products(
session: Annotated[AsyncSession, Depends(get_session)],
vector_db:Annotated[AsyncQdrantClient, Depends(get_qdrant_client)],
):
try:
return JSONResponse(content={"message": "Hello World"})
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))

View File

View File

@ -0,0 +1 @@
from qdrant_client import AsyncQdrantClient, models

View File

@ -0,0 +1,4 @@
from db_setup import get_session,get_qdrant_client
# from .models import Product
from sqlalchemy.ext.asyncio import AsyncSession
from qdrant_client import AsyncQdrantClient

0
model_export/README.md Normal file
View File