-
-
Notifications
You must be signed in to change notification settings - Fork 228
Rework ColumnRef and TableRef
#927
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
Conversation
| /// Table identifier with database and schema prefix and alias | ||
| DatabaseSchemaTableAlias(DynIden, DynIden, DynIden, DynIden), | ||
| /// A table identifier. Potentially qualified. Potentially remaned using an alias | ||
| Table(TableName, Option<DynIden>), |
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.
Ideally, I'd use named fields for clarity (alias: Option<DynIden> and so on).
But I chose to keep everything consistent with the other existing variants and not touch those. SeaQuery 1.0 breaks a lot of things already
|
Maybe we should also add corresponding borrowed types? if !from.is_empty()
&& let Some(table) = table
&& let TableRef::Table(table) = table.deref()
{
self.prepare_column_ref(&ColumnRef::TableColumn(table.clone(), column.clone()), sql);
} else {
self.prepare_iden(column, sql);
}Due to the lack of such a type, many places require unnecessary clones. |
|
I wouldn't worry too much about these clones. They were Even in the rare worst case with dynamic |
|
Oh, I forgot about that. |
There was some annoying repetition in this area. `TableName` and `ColumnName` each had three copy-pasted `From` impls. Now they have one, which will be easier to copy-paste when I add `TypeName` and `FunctionName`. I came up with this while re-doing #922 to add `TypeName`. Related to #927. `types.rs` is getting too long and starting to have visible disjoint "submodules", so I started splitting it. ## PR Info - Dependents: - #922 ## New Features - [x] The new traits are technically an addition, but I wouldn't advertise it. They are not meant to be used directly. I've documented this on the traits.
Extracted the
foo.bar.bazqualification logic that was duplicated across several variants ofColumnRefandTableRef.I need this to implement
schema.type: #827, #922I'll also need this to implement
schema.functionlater: #795 (reply in thread)There are also immediate benefits. IMO,
ColumnRefandTableRef(and their pattern-matching) look considerably cleaner now. Thedatabase.prefix is guaranteed to be supported everywhere where it may be needed.The detailed changelog is in the diff. I fully preserved (and documented) the existing codegen behavior, as evidenced by unchanged output in tests. If this documented behavior looks suspicious (it kinda does to me), let's fix that later in a separate PR. Here, the only changes in tests are the refactoring that's needed for the new variants to compile.
This is a relatively big breaking change for those users who dig within the internals of
ColumnRef,TableRef, andSchemaTable. But that's very low-level and should be rare. My work project never does that, despite depending on SeaORM/SeaQuery/SQLx very closely and frequently getting generic or low-level.PR Info
cast_as_quoted#922