File tree Expand file tree Collapse file tree 4 files changed +38
-8
lines changed
Expand file tree Collapse file tree 4 files changed +38
-8
lines changed Original file line number Diff line number Diff line change 77
88load_dotenv ()
99
10- DATABASE_URL = os .getenv ("DATABASE_URL" )
10+ raw_url = os .getenv ("DATABASE_URL" , "postgresql://user:pass@localhost:5432/dbname" )
11+
12+ # Ensure it uses asyncpg
13+ if raw_url .startswith ("postgresql://" ):
14+ raw_url = raw_url .replace ("postgresql://" , "postgresql+asyncpg://" , 1 )
15+ elif not raw_url .startswith ("postgresql+asyncpg://" ):
16+ raise ValueError ("Invalid DATABASE_URL: must start with postgresql:// or postgresql+asyncpg://" )
17+
18+ DATABASE_URL = raw_url
1119
1220engine = create_async_engine (DATABASE_URL , echo = True )
1321
Original file line number Diff line number Diff line change 77
88load_dotenv ()
99
10- DATABASE_URL = os .getenv ("DATABASE_URL" )
10+ raw_url = os .getenv ("DATABASE_URL" , "postgresql://user:pass@localhost:5432/dbname" )
11+
12+ # Ensure it uses asyncpg
13+ if raw_url .startswith ("postgresql://" ):
14+ raw_url = raw_url .replace ("postgresql://" , "postgresql+asyncpg://" , 1 )
15+ elif not raw_url .startswith ("postgresql+asyncpg://" ):
16+ raise ValueError ("Invalid DATABASE_URL: must start with postgresql:// or postgresql+asyncpg://" )
17+
18+ DATABASE_URL = raw_url
1119
1220engine = create_async_engine (DATABASE_URL , echo = True )
1321
Original file line number Diff line number Diff line change 99
1010BATCH_SIZE = 1000 # Adjust as needed
1111
12- # Database URL format: mysql+asyncmy://user:password@host:port/database
13- DATABASE_URL = os .getenv (
14- "MARIADB_URL" , "mysql+asyncmy://user:password@localhost:3306/database"
12+ raw_url = os .getenv (
13+ "MARIADB_URL" , "mysql://user:password@localhost:3306/database"
1514)
1615
16+ # Ensure the URL uses asyncmy driver
17+ if raw_url .startswith ("mysql://" ):
18+ raw_url = raw_url .replace ("mysql://" , "mysql+asyncmy://" , 1 )
19+ elif not raw_url .startswith ("mysql+asyncmy://" ):
20+ raise ValueError ("Invalid DATABASE_URL: must start with mysql:// or mysql+asyncmy://" )
21+
22+ DATABASE_URL = raw_url
23+
1724# Create async engine
1825engine = create_async_engine (DATABASE_URL , echo = True )
1926
Original file line number Diff line number Diff line change 1010
1111BATCH_SIZE = 1000 # Adjust batch size as needed
1212
13- # Database URL format: mysql+asyncmy://user:password@host:port/database
14- DATABASE_URL = os .getenv (
15- "MARIADB_URL" , "mysql+asyncmy://user:password@localhost:3306/database"
13+ raw_url = os .getenv (
14+ "MARIADB_URL" , "mysql://user:password@localhost:3306/database"
1615)
1716
17+ # Ensure the URL uses asyncmy driver
18+ if raw_url .startswith ("mysql://" ):
19+ raw_url = raw_url .replace ("mysql://" , "mysql+asyncmy://" , 1 )
20+ elif not raw_url .startswith ("mysql+asyncmy://" ):
21+ raise ValueError ("Invalid DATABASE_URL: must start with mysql:// or mysql+asyncmy://" )
22+
23+ DATABASE_URL = raw_url
24+
1825# Create async SQLAlchemy engine
1926engine = create_async_engine (DATABASE_URL , echo = True )
2027
You can’t perform that action at this time.
0 commit comments