Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable use of generators without engine #323

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kozlek
Copy link

@kozlek kozlek commented Apr 23, 2024

sqlacodegen is a great tool that does two things when used as cli:

  1. generate a MetaData object using SQLAlchemy built-in reflection
  2. generate code using the generated MetaData from step 1

While most of users use the CLI, the core value of sqlacodegen is the code generator.

This PR eases the standalone usage of the code generator by removing the need of an engine (and the associated driver). Actually, the engine+driver is only needed for the reflection (step 1), while a dialect is enough for step 2.

Example usage

from sqlacodegen.generators import DeclarativeGenerator
from sqlalchemy import Dialect
from sqlalchemy.dialects import postgresql

metadata = sa.MetaData()
generator = DeclarativeGenerator(metadata, dialect=postgresql.dialect(), options=set())
print(generator.generate())

@kozlek kozlek force-pushed the remove-engine-dependency branch from 43e6c4d to bc68197 Compare April 23, 2024 20:21
@kozlek kozlek force-pushed the remove-engine-dependency branch from 8de0a1f to a6faddd Compare April 23, 2024 20:51
@coveralls
Copy link

Coverage Status

coverage: 97.02% (-0.005%) from 97.025%
when pulling 9a2e003 on kozlek:remove-engine-dependency
into e776bb7 on agronholm:master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants