Repository navigation
feat: rewrote dialect as a subclass of sqlalchemy-cloudflare-d1 (0.2.0) - #1
Merged
Merged
Conversation
Moved to SQLAlchemy 2.0, dropped dbapi-d1 and lifted the python cap. The dialect keeps the d1 name and adds date and boolean type names, date and boolean reflection, autoincrement, schema and view listing and _cf_ filtering on top of upstream.
- Reflected DECIMAL as numeric and matched declared types on the first word - Reported autoincrement only for a single INTEGER primary key column in a table that is not WITHOUT ROWID - Reflected composite primary keys in key order - Ignored URL query parameters so base_url cannot reach the driver - Let get_view_names errors propagate instead of raising RuntimeError - Added get_view_definition, get_table_comment and get_check_constraints - Made has_table true for views - Replaced the visit method overrides with reflection-only types in sqlalchemy_d1.types, so generic types compile the same as upstream - Fell back to a placeholder version when package metadata is missing - Moved the get_columns tests to an in-memory SQLite suite
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Version 0.2.0.
D1Dialectis now a subclass ofCloudflareD1Dialectfrom sqlalchemy-cloudflare-d1. Thed1://connection string and thed1entry point stay the same, so nothing changes for existing Superset connections.Superset has moved to SQLAlchemy 2.0. Version 0.1.0 pins
sqlalchemy<2, so thed1extra in Superset is blocked today. This removes the block.Still a draft, but ready for review. The end-to-end check inside Superset has passed on this exact code, and so has a code review. Nothing is on PyPI yet. Merging and tagging
v0.2.0is what publishes it.What changed
sqlalchemy>=2.0,<2.1andsqlalchemy-cloudflare-d1>=0.3.11,<0.5.dbapi-d1is dropped.>=3.11. The<3.12cap is gone. Tested on 3.11 to 3.14.dialect.pyandtypes.py, about 220 lines. The emptycompiler.pyandtype_compiler.pyare deleted.LICENSEfile andlicense = "Apache-2.0"inpyproject.toml.release.yml. Av*tag builds the package and publishes it to PyPI with trusted publishing.README.mdandCHANGELOG.md.What the dialect adds on top of upstream
DATETIME,TIMESTAMP,DATE,TIME,BOOLEANorBOOLare reflected as the types insqlalchemy_d1.types. They behave like the upstream date and boolean types and keep the declared name. Superset reads that name to decide if a column is a date. Upstream reflects these columns asTEXT.DECIMALcolumns are reflected as numeric.autoincrementon reflected columns. It is true only for the column SQLite fills in by itself.get_schema_names,get_view_namesandget_view_definition. Upstream has none of these, and Superset needs the first two.has_tableis also true for a view._cf_filtering for tables and views.Everything else comes from upstream unchanged. That includes the connection, the cursor, the SQL compiler, and the reflection of foreign keys, indexes and unique constraints.
Tables created through SQLAlchemy are identical to the ones upstream creates. A
DateTimecolumn is still declared asTEXT, so it reads back as text. A table reflected from D1 keeps its declared types when it is created again on D1. On another database the same columns compile like SQLAlchemy's generic types. The known limits are in the README.Testing
ruff check,ruff format --checkandmypy srcare clean.python -m buildandtwine checkpass.superset-engine-d1ordbapi-d1, against a real D1 database. All of these passed:_cf_KVis hidden.Notes for review
autoincrementand the key order exact, and added the view methods. Its commits are on this branch.get_columnsandget_pk_constraintreadPRAGMA table_infothemselves, because upstream throws away the declared type and the position in the key. Worth a second look whenever the upstream pin moves.licenseis set, so only thelicensefield is used._cf_withSQLITE_AUTH. The_cf_view filter is covered by a unit test with a fake connection.devextra so thatpip install -e ".[dev]"works. With Poetry, usepoetry install --all-extras.integrationCI job only runs on manual dispatch. It needs the repo secretsCF_ACCOUNT_ID,CF_API_TOKENandCF_D1_DATABASE_ID.sqlalchemy-cf-d1, repositorysqlalchemy-d1, workflowrelease.yml, environmentpypi). Only a project Owner on PyPI can add it.