Repository navigation
feat(dialect): add pluggable SqlDialect trait and DynDialect - #404
Merged
Merged
Conversation
KKould
reviewed
Nov 21, 2026
KKould
reviewed
Nov 21, 2026
KKould
reviewed
Nov 21, 2026
KKould
reviewed
Nov 21, 2026
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #404 +/- ##
==========================================
+ Coverage 92.97% 92.99% +0.01%
==========================================
Files 274 275 +1
Lines 38990 39243 +253
==========================================
+ Hits 36252 36495 +243
- Misses 2738 2748 +10
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
cursor
Bot
force-pushed
the
upstream/dialect-registry
branch
from
November 21, 2026 13:38
201ede3 to
f9b242d
Compare
This was referenced Nov 21, 2026
cursor
Bot
force-pushed
the
upstream/dialect-registry
branch
from
November 21, 2026 16:37
f9b242d to
690ea32
Compare
KKould
reviewed
Nov 21, 2026
KKould
reviewed
Nov 21, 2026
KKould
reviewed
Nov 21, 2026
Member
|
@alexskinner I think it’s nearly complete—just a few minor details left to address. It’s looking very good. Once this PR is merged, I’ll take a look at the subsequent PRs. Thanks for your patience in making these revisions. |
cursor
Bot
force-pushed
the
upstream/dialect-registry
branch
from
November 21, 2026 17:41
690ea32 to
f51be4f
Compare
Co-authored-by: Alex Skinner <alexskinner@users.noreply.github.com>
cursor
Bot
force-pushed
the
upstream/dialect-registry
branch
from
November 21, 2026 19:08
f51be4f to
7b10cf2
Compare
KKould
approved these changes
Nov 21, 2026
KKould
left a comment
Member
There was a problem hiding this comment.
Our discussion was very pleasant and meaningful; thank you so much for your contributions.
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.
Part of #403.
What
src/dialect/mod.rswith theSqlDialecttrait (name,parser_dialect,rewrite,map_data_type,map_column_type),GenericSqlDialectandDynDialect.Database<S, D: SqlDialect = GenericSqlDialect>(andTransaction<'a, S, D = GenericSqlDialect>,DataBaseBuilder<D = GenericSqlDialect>) own one dialect, set at build time withDataBaseBuilder::dialect(d)and fixed after that. Without.dialect(..), a database usesGenericSqlDialect, statically dispatched, and behaves exactly as on main. Parsing uses its parser dialect and runs itsrewriteon each statement. The binder gets it by reference: column definitions resolve types throughmap_column_type, andCASTand typed literals throughmap_data_type.DynDialectis an opt-in for choosing the dialect at runtime, passed with.dialect(dynamic). It follows your sketch:new()starts with the generic dialect registered and current,register<D: SqlDialect + Send + Sync + 'static>(d)adds or replaces one by name,switch(&mut self, name) -> boolpicks the current one, andcurrent() -> &dyn SqlDialectreturns it. It implementsSqlDialectby forwarding every hook tocurrent().Database, andDatabasestaysSend + Sync.GenericSqlDialect. Every hook defaults to current behaviour.SqlDialect,DynDialect,DataBaseBuilder::dialect) and a section indocs/features.md.Why
This lets an external crate supply dialect behaviour without changing core. A host that knows its dialect at compile time passes the concrete type. A host that picks it from configuration, for example one
Databaseper datasource, opts in toDynDialect, registers its dialects and switches before building. See #403.Testing
src/dialect/mod.rs: one builds a database with a test dialect via.dialect(..)and checks column-type mapping and statement rewriting end to end (and that the generic build rejects the custom type); the other checksDynDialectregister/switch, including an unknown name, and runs a query through the switched dialect. Parser and generic behaviour stay covered by the existing sqllogictest files.make test(649 passed, 2 ignored),make test-async(594 passed),make test-sltandmake test-slt-async(198 files each),make fmtand all fourmake clippyinvocations pass.make test-wasmpasses too.Notes for review
&dyn SqlDialectrather than a third type parameter, soBinderand its many impls aren't monomorphised per dialect. Hooks run once per bound item, not per row, so that costs one virtual call each. Parsing andrewriteare called onDdirectly.DataBaseBuilder::pathbuilds the default (generic) builder, and.dialect(d)turns it into aDataBaseBuilder<D>. All other builder methods andbuild_*work for anyD.switchtakes&mut self, so aDynDialect's dialect is chosen before the database is built. A&mut selfmethod onDatabasecould expose it later if that's useful.