Spaces:
Runtime error
Runtime error
Eric Michael Martinez
commited on
Commit
•
7114487
1
Parent(s):
cc03605
fix
Browse files
app/db.py
CHANGED
@@ -2,9 +2,8 @@ from typing import AsyncGenerator
|
|
2 |
|
3 |
from fastapi import Depends
|
4 |
from fastapi_users.db import SQLAlchemyBaseUserTableUUID, SQLAlchemyUserDatabase
|
5 |
-
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
|
6 |
-
from sqlalchemy.
|
7 |
-
from sqlalchemy.orm import sessionmaker
|
8 |
from dotenv import load_dotenv
|
9 |
import os
|
10 |
|
@@ -24,15 +23,18 @@ else:
|
|
24 |
db_connection_string = os.getenv("DB_CONNECTION_STRING")
|
25 |
|
26 |
DATABASE_URL = db_connection_string
|
27 |
-
Base: DeclarativeMeta = declarative_base()
|
28 |
|
29 |
-
|
|
|
|
|
|
|
|
|
30 |
class User(SQLAlchemyBaseUserTableUUID, Base):
|
31 |
pass
|
32 |
|
33 |
|
34 |
engine = create_async_engine(DATABASE_URL)
|
35 |
-
async_session_maker =
|
36 |
|
37 |
|
38 |
async def create_db_and_tables():
|
|
|
2 |
|
3 |
from fastapi import Depends
|
4 |
from fastapi_users.db import SQLAlchemyBaseUserTableUUID, SQLAlchemyUserDatabase
|
5 |
+
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
|
6 |
+
from sqlalchemy.orm import DeclarativeBase
|
|
|
7 |
from dotenv import load_dotenv
|
8 |
import os
|
9 |
|
|
|
23 |
db_connection_string = os.getenv("DB_CONNECTION_STRING")
|
24 |
|
25 |
DATABASE_URL = db_connection_string
|
|
|
26 |
|
27 |
+
|
28 |
+
class Base(DeclarativeBase):
|
29 |
+
pass
|
30 |
+
|
31 |
+
|
32 |
class User(SQLAlchemyBaseUserTableUUID, Base):
|
33 |
pass
|
34 |
|
35 |
|
36 |
engine = create_async_engine(DATABASE_URL)
|
37 |
+
async_session_maker = async_sessionmaker(engine, expire_on_commit=False)
|
38 |
|
39 |
|
40 |
async def create_db_and_tables():
|