@@ -73,7 +73,7 @@ Synchronous Loading
73
73
# Database connection string
74
74
DATABASE_URL = " sqlite:///db.sqlite3"
75
75
76
- config = SQLAlchemySyncConfig(
76
+ alchemy_config = SQLAlchemySyncConfig(
77
77
engine_instance = create_engine(DATABASE_URL ),
78
78
session_config = SyncSessionConfig(expire_on_commit = False )
79
79
)
@@ -101,7 +101,7 @@ Synchronous Loading
101
101
def initialize_database ():
102
102
""" Initialize the database and create tables."""
103
103
print (" Creating database tables..." )
104
- with config .get_engine().begin() as conn:
104
+ with alchemy_config .get_engine().begin() as conn:
105
105
UUIDBase.metadata.create_all(conn)
106
106
print (" Tables created successfully" )
107
107
@@ -111,7 +111,7 @@ Synchronous Loading
111
111
print (" Seeding database..." )
112
112
113
113
# Create a session
114
- with config .get_session() as db_session:
114
+ with alchemy_config .get_session() as db_session:
115
115
# Create repository for product model
116
116
product_repo = ProductRepository(session = db_session)
117
117
@@ -155,7 +155,7 @@ Asynchronous Loading
155
155
# Database connection string
156
156
DATABASE_URL = " sqlite+aiosqlite:///db.sqlite3"
157
157
158
- config = SQLAlchemyAsyncConfig(
158
+ alchemy_config = SQLAlchemyAsyncConfig(
159
159
engine_instance = create_async_engine(DATABASE_URL ),
160
160
session_config = AsyncSessionConfig(expire_on_commit = False )
161
161
)
@@ -183,7 +183,7 @@ Asynchronous Loading
183
183
async def initialize_database ():
184
184
""" Initialize the database and create tables."""
185
185
print (" Creating database tables..." )
186
- async with config .get_engine().begin() as conn:
186
+ async with alchemy_config .get_engine().begin() as conn:
187
187
await conn.run_sync(UUIDBase.metadata.create_all)
188
188
print (" Tables created successfully" )
189
189
@@ -193,7 +193,7 @@ Asynchronous Loading
193
193
print (" Seeding database..." )
194
194
195
195
# Create a session
196
- async with config .get_session() as db_session:
196
+ async with alchemy_config .get_session() as db_session:
197
197
# Create repository for product model
198
198
product_repo = ProductRepository(session = db_session)
199
199
@@ -256,13 +256,13 @@ Litestar
256
256
fixtures_path = Path(__file__ ).parent / " fixtures"
257
257
258
258
session_config = AsyncSessionConfig(expire_on_commit = False )
259
- sqlalchemy_config = SQLAlchemyAsyncConfig(
259
+ alchemy_config = SQLAlchemyAsyncConfig(
260
260
connection_string = DATABASE_URL ,
261
261
before_send_handler = " autocommit" ,
262
262
session_config = session_config,
263
263
create_all = True ,
264
264
)
265
- alchemy = SQLAlchemyPlugin(config = sqlalchemy_config )
265
+ alchemy = SQLAlchemyPlugin(config = alchemy_config )
266
266
267
267
268
268
class Product (UUIDBase ):
@@ -287,7 +287,7 @@ Litestar
287
287
print (" Running startup routine..." )
288
288
289
289
# Create a session and seed data
290
- async with sqlalchemy_config .get_session() as db_session:
290
+ async with alchemy_config .get_session() as db_session:
291
291
# Create repository for product model
292
292
product_repo = ProductRepository(session = db_session)
293
293
# Load and add product data
@@ -368,7 +368,7 @@ FastAPI
368
368
print (" Running startup routine..." )
369
369
370
370
# Create a session and seed data
371
- async with sqlalchemy_config .get_session() as db_session:
371
+ async with alchemy_config .get_session() as db_session:
372
372
# Create repository for product model
373
373
product_repo = ProductRepository(session = db_session)
374
374
# Load and add product data
@@ -394,7 +394,7 @@ FastAPI
394
394
395
395
396
396
session_config = AsyncSessionConfig(expire_on_commit = False )
397
- sqlalchemy_config = SQLAlchemyAsyncConfig(
397
+ alchemy_config = SQLAlchemyAsyncConfig(
398
398
connection_string = DATABASE_URL ,
399
399
commit_mode = " autocommit" ,
400
400
session_config = session_config,
@@ -404,7 +404,7 @@ FastAPI
404
404
# Create the FastAPI application with lifespan
405
405
app = FastAPI(lifespan = lifespan)
406
406
407
- alchemy = AdvancedAlchemy(config = sqlalchemy_config , app = app)
407
+ alchemy = AdvancedAlchemy(config = alchemy_config , app = app)
408
408
409
409
if __name__ == " __main__" :
410
410
uvicorn.run(app, host = " 0.0.0.0" , port = 8000 )
@@ -454,7 +454,7 @@ Flask
454
454
455
455
app = Flask(__name__ )
456
456
457
- sqlalchemy_config = SQLAlchemySyncConfig(
457
+ alchemy_config = SQLAlchemySyncConfig(
458
458
connection_string = DATABASE_URL ,
459
459
commit_mode = " autocommit" ,
460
460
session_config = SyncSessionConfig(
@@ -463,8 +463,8 @@ Flask
463
463
create_all = True
464
464
)
465
465
466
- db = AdvancedAlchemy(config = sqlalchemy_config )
467
- db .init_app(app)
466
+ alchemy = AdvancedAlchemy(config = alchemy_config )
467
+ alchemy .init_app(app)
468
468
469
469
with app.app_context(): # noqa: SIM117
470
470
# Seed data
0 commit comments