This repository has been archived by the owner on Oct 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use aiomyql driver to generate models
- Loading branch information
Showing
7 changed files
with
26 additions
and
14 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
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 |
---|---|---|
@@ -1,14 +1,26 @@ | ||
import asyncio | ||
import os | ||
|
||
import setuptools | ||
from sqlacodegen_v2.generators import DeclarativeGenerator | ||
from sqlalchemy import MetaData, create_engine | ||
from sqlalchemy import MetaData | ||
from sqlalchemy.ext.asyncio import create_async_engine | ||
|
||
if __name__ == "__main__": | ||
engine = create_engine(os.environ["DATABASE_URL"]) | ||
|
||
async def generate_models(): | ||
engine = create_async_engine(os.environ["DATABASE_URL"]) | ||
metadata = MetaData() | ||
metadata.reflect(engine, only=["EnergyScan"]) | ||
generator = DeclarativeGenerator(metadata, engine, set()) | ||
async with engine.begin() as connection: | ||
await connection.run_sync( | ||
lambda connection: metadata.reflect(connection, only=["EnergyScan"]) | ||
) | ||
generator = await connection.run_sync( | ||
lambda connection: DeclarativeGenerator(metadata, connection, set()) | ||
) | ||
with open("src/graph_energy_scan/models.py", "w") as models_file: | ||
models_file.write(generator.generate()) | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(generate_models()) | ||
setuptools.setup() |