File size: 950 Bytes
973406c
ce1e080
5a5f1de
973406c
5a5f1de
973406c
5a5f1de
973406c
 
5a5f1de
ce1e080
 
973406c
 
 
 
 
 
 
 
 
 
 
5a5f1de
 
 
 
 
ce1e080
973406c
 
 
 
 
5a5f1de
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from typing import AsyncGenerator

from dotenv import load_dotenv
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
from sqlmodel import SQLModel, create_engine
from sqlmodel.ext.asyncio.session import AsyncSession

from src.core import *
from src.core.config import settings

load_dotenv()

engine = create_engine(
    settings.DATABASE_URL, echo=True
)  # to false on prod just to chcek for now

async_engine = create_async_engine(
    url=settings.ASYNC_DATABASE_URL, future=True, connect_args={"ssl": True}
)

async_session = async_sessionmaker(
    class_=AsyncSession, bind=async_engine, expire_on_commit=False
)


def init_db():
    SQLModel.metadata.create_all(engine)


async def get_async_session() -> AsyncGenerator[AsyncSession, None]:
    async with async_session() as session:
        yield session


if __name__ == "__main__":
    print("Table creating")
    init_db()
    print("Table Created successfully!")