feat: add database connection with modified endpoints
This commit is contained in:
16
dependencies/database.py
vendored
Normal file
16
dependencies/database.py
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
import os
|
||||
from databases import Database
|
||||
from sqlalchemy import create_engine, MetaData
|
||||
from sqlalchemy.orm import declarative_base, sessionmaker
|
||||
|
||||
DATABASE_URL = os.getenv("DATABASE_URL")
|
||||
|
||||
# for Alembic migrations and sync operations
|
||||
engine = create_engine(DATABASE_URL)
|
||||
|
||||
# to use with async requests
|
||||
database = Database(DATABASE_URL)
|
||||
|
||||
metadata = MetaData()
|
||||
Base = declarative_base(metadata=metadata)
|
||||
|
||||
9
dependencies/models.py
vendored
Normal file
9
dependencies/models.py
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
from sqlalchemy import Column, Integer, String
|
||||
from dependencies.database import Base
|
||||
|
||||
class UrlMapping(Base):
|
||||
__tablename__ = "url_mapping"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
url = Column(String, nullable=False)
|
||||
shortcode = Column(String, index=True, unique=True, nullable=False)
|
||||
Reference in New Issue
Block a user