-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update metadata to allow multiple db concurrently in app (#52)
* adding __metadata__ from database instance during DataBaseModel.setup(), added Float to supported supported_sqlalchemy_types. BaseMeta now creates separate instances instead of global class references * creating BaseMeta instance for each separate Database instance * added test for multiple databases * added test_multiple_databases test to Makefile * added test_multiple_databases test to Makefile --------- Co-authored-by: Joshua (codemation)
- Loading branch information
1 parent
2256dfd
commit 658e9f8
Showing
5 changed files
with
55 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import pytest | ||
|
||
from pydbantic import Database, DataBaseModel | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_multiple_database(): | ||
class DB1Model1(DataBaseModel): | ||
__tablename__ = "model1" | ||
data: str | ||
data2: str | ||
|
||
class DB2Model1(DataBaseModel): | ||
__tablename__ = "model1" | ||
data: str | ||
data2: str | ||
|
||
db1 = await Database.create("sqlite:///db1", tables=[DB1Model1]) | ||
db2 = await Database.create("sqlite:///db2", tables=[DB2Model1]) | ||
|
||
assert not await DB1Model1.all() | ||
assert not await DB2Model1.all() | ||
|
||
await DB1Model1.create(data="1", data2="2") | ||
assert await DB1Model1.all() | ||
assert not await DB2Model1.all() |