Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/backend/query_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,19 @@ pub trait QueryBuilder:
}
sql.write_str("*").unwrap();
}
ColumnRef::New(column) => {
sql.write_str("NEW.").unwrap();
self.prepare_iden(column, sql);
}
ColumnRef::Old(column) => {
sql.write_str("OLD.").unwrap();
self.prepare_iden(column, sql);
}
#[cfg(feature = "backend-postgres")]
ColumnRef::Excluded(column) => {
sql.write_str("excluded.").unwrap();
self.prepare_iden(column, sql);
}
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/types/iden/compound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ pub enum ColumnRef {
Column(ColumnName),
/// An `*` expression, potentially qualified as `(database.)(schema.)(table.)*`.
Asterisk(Option<TableName>),
/// NEW.*
New(DynIden),
/// Old.*
Old(DynIden),
#[cfg(feature = "backend-postgres")]
/// excluded.*
Excluded(DynIden),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To we really need these special variants? These table names look like they can be already expressed as "regular" table names: ColumnRef::from(("OLD", MyColumn))

It may be enough to define some unit-struct idens for these tables and document the approach.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prepare_iden will quote them, but they cannot be quoted.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I see. Then, I wouldn't change ColumnRef at all. We don't need to do anything with the "column basename" part. We need to somehow allow unquoted TableNames (which would then be stored in ColumnRef as usual) and provide a way to construct unquoted TableNames ergonomically

}

impl ColumnRef {
Expand All @@ -144,6 +151,10 @@ impl ColumnRef {
match self {
ColumnRef::Column(ColumnName(_table_ref, column_itself)) => Some(column_itself),
ColumnRef::Asterisk(..) => None,
ColumnRef::New(column_itself) => Some(column_itself),
ColumnRef::Old(column_itself) => Some(column_itself),
#[cfg(feature = "backend-postgres")]
ColumnRef::Excluded(column_itself) => Some(column_itself),
}
}
}
Expand Down
Loading