Skip to content

Commit

Permalink
Use aiomyql driver to generate models
Browse files Browse the repository at this point in the history
  • Loading branch information
garryod committed Apr 18, 2024
1 parent 2da5347 commit 6fd6ce1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ requires = [
"setuptools_scm[toml]>=6.2",
"sqlacodegen-v2",
"sqlalchemy",
"pymysql",
"aiomysql",
]
build-backend = "setuptools.build_meta"

Expand All @@ -25,7 +25,7 @@ dependencies = [
"uvicorn",
"starlette",
"strawberry-graphql[asgi]",
"sqlalchemy",
"sqlalchemy[asyncio]",
"aiomysql",
"opentelemetry-api",
"opentelemetry-sdk",
Expand Down
22 changes: 17 additions & 5 deletions setup.py
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()

0 comments on commit 6fd6ce1

Please sign in to comment.