add database and test that it work

This commit is contained in:
Rainy21
2026-03-12 17:32:40 -04:00
parent 46bc71f16a
commit 855a9971cb
6 changed files with 16 additions and 14 deletions
+7 -11
View File
@@ -1,18 +1,14 @@
from pydantic import Secret
import sqlalchemy.orm import Session
from sqlalchemy.orm import Session
from . import models
def create_url(db:Session, short_code:str , long_url:str):
db_url = models.URL(
short_code=short_code,
long_url=long_url
)
def create_url(db: Session, short_code: str, long_url: str):
db_url = models.URL(short_code=short_code, long_url=long_url)
db.add(db_url)
db.commit()
db.refresh(db_url)
return db_url
def get_url(db:Session , short_code:str):
return db.query(models.URL).filter(
models.URL.short_code == short_code
).first()
def get_url(db: Session, short_code: str):
return db.query(models.URL).filter(models.URL.short_code == short_code).first()