@@ -41,8 +41,7 @@ The `DBConnection` class has the following methods:
4141
4242#### init_db
4343
44- Initialize the database tables. It also sets the session of the base model to
45- the ` async_scoped_session ` async session factory:
44+ Initialize the database tables for the given base models:
4645
4746``` python
4847from sqlactive import DBConnection
@@ -53,7 +52,7 @@ asyncio.run(conn.init_db()) # Initialize the database
5352```
5453
5554If your base model is not ` ActiveRecordBaseModel ` you must pass
56- your base model class to this method in the ` base_model ` argument :
55+ your base model. You can also initialize multiple base models at once :
5756
5857``` python
5958from sqlactive import DBConnection, ActiveRecordBaseModel
@@ -67,12 +66,13 @@ class BaseModel(ActiveRecordBaseModel):
6766DATABASE_URL = ' sqlite+aiosqlite://'
6867conn = DBConnection(DATABASE_URL , echo = True )
6968asyncio.run(conn.init_db(BaseModel)) # Pass your base model
69+ # or
70+ asyncio.run(conn.init_db(BaseModel, AnotherBaseModel)) # Pass multiple base models
7071```
7172
7273#### close
7374
74- Close the database connection. It also sets the session of the base model
75- to ` None ` :
75+ Close the database connection and remove the session:
7676
7777``` python
7878from sqlactive import DBConnection
@@ -83,26 +83,5 @@ asyncio.run(conn.init_db())
8383
8484# Perform operations...
8585
86- asyncio.run(conn.close()) # Close the database connection
87- ```
88-
89- If your base model is not ` ActiveRecordBaseModel ` you should pass
90- your base model cl0ass to this method in the ` base_model ` argument:
91-
92- ``` python
93- from sqlactive import DBConnection, ActiveRecordBaseModel
94-
95- # Note that it does not matter if your base model
96- # inherits from `ActiveRecordBaseModel`, you still
97- # need to pass it to this method
98- class BaseModel (ActiveRecordBaseModel ):
99- __abstract__ = True
100-
101- DATABASE_URL = ' sqlite+aiosqlite://'
102- conn = DBConnection(DATABASE_URL , echo = True )
103- asyncio.run(conn.init_db())
104-
105- # Perform operations...
106-
107- asyncio.run(conn.close(BaseModel)) # Pass your base model
86+ asyncio.run(conn.close()) # Close the database connection and remove the sessions
10887```
0 commit comments