mirror of
https://github.com/Rainyy21/URL_shortener.git
synced 2026-10-10 22:50:14 -04:00
15 lines
390 B
Python
15 lines
390 B
Python
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)
|
|
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()
|