-
-
Notifications
You must be signed in to change notification settings - Fork 12
feat: Add SQLAlchemy models for Chancy tables #83
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
base: 26_ux
Are you sure you want to change the base?
Conversation
This adds a new contrib module with SQLAlchemy models that mirror the existing Django models. Users can now query Chancy data using SQLAlchemy's ORM without managing the table schema. New files: - chancy/contrib/sqlalchemy/__init__.py - Module docstring - chancy/contrib/sqlalchemy/models.py - Job, Worker, Queue models - tests/contrib/sqlalchemy/test_models.py - Integration tests The models support: - Table prefix customization via CHANCY_PREFIX environment variable - Full SQLAlchemy 2.0 style with mapped_column and Mapped types - PostgreSQL-specific types (JSONB, ARRAY, UUID) - Comprehensive docstrings with usage examples Closes TkTech#75
PaulM5406
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
|
||
| with Session(engine) as session: | ||
| # Get all pending jobs | ||
| pending_jobs = session.query(Job).filter(Job.state == "pending").all() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this documentation uses the former SQLA syntaxe, i.e. session.query.
test_models.py uses modern syntaxe session.execute though.
| PG_UUID(as_uuid=True), | ||
| primary_key=True, | ||
| ) | ||
| queue: Mapped[str] = mapped_column(Text, nullable=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: For the whole file, nullable can be inferred from the type.
| queue: Mapped[str] = mapped_column(Text, nullable=False) | |
| queue: Mapped[str] = mapped_column(Text) |
If Optional is used, nullable=True is inferred.
| """ | ||
|
|
||
| __tablename__ = f"{PREFIX}jobs" | ||
| __table_args__ = {"extend_existing": True} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is really useful ?
Summary
This PR adds SQLAlchemy models as a new contrib module, mirroring the existing Django models. This addresses #75.
Changes
Features
mapped_columnandMappedtypesCHANCY_PREFIXenvironment variableUsage Example
Closes #75