aliasing3
This commit is contained in:
@@ -664,11 +664,22 @@ impl ColumnDraft {
|
||||
/// compound one. This is what the column list shows underneath it, so the
|
||||
/// columns a definition row brings are visible while the table is still
|
||||
/// being described.
|
||||
pub(crate) fn generated_columns_of(&self, index: usize) -> &[GeneratedColumn] {
|
||||
self.added
|
||||
.get(index)
|
||||
.map(|column| self.catalog.generated_columns(&column.data_type))
|
||||
.unwrap_or_default()
|
||||
pub(crate) fn generated_columns_of(&self, index: usize) -> Vec<GeneratedColumn> {
|
||||
let Some(column) = self.added.get(index) else {
|
||||
return Vec::new();
|
||||
};
|
||||
let generated = self.catalog.generated_columns(&column.data_type);
|
||||
let default_prefix = format!("{}_", column.data_type);
|
||||
generated
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(|mut companion| {
|
||||
if let Some(suffix) = companion.name.strip_prefix(&default_prefix) {
|
||||
companion.name = format!("{}_{}", column.name, suffix);
|
||||
}
|
||||
companion
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Whether a column can be indexed or identify a row. A compound column
|
||||
@@ -1115,7 +1126,23 @@ pub(crate) mod tests {
|
||||
grouped("gtin_12", "gtin"),
|
||||
grouped("gtin_13", "gtin"),
|
||||
grouped("gtin_14", "gtin"),
|
||||
declarable("iban"),
|
||||
ColumnType {
|
||||
generated_columns: vec![
|
||||
generated_column("iban_country", "iban_country", false),
|
||||
generated_column("iban_bban", "iban_bban", false),
|
||||
generated_column(
|
||||
"iban_bank_identifier",
|
||||
"iban_bank_identifier",
|
||||
false,
|
||||
),
|
||||
generated_column(
|
||||
"iban_branch_identifier",
|
||||
"iban_branch_identifier",
|
||||
false,
|
||||
),
|
||||
],
|
||||
..declarable("iban")
|
||||
},
|
||||
ColumnType {
|
||||
declarable: false,
|
||||
..declarable("iban_bban")
|
||||
@@ -1135,7 +1162,19 @@ pub(crate) mod tests {
|
||||
..declarable("numeric")
|
||||
},
|
||||
declarable("period"),
|
||||
declarable("phone"),
|
||||
ColumnType {
|
||||
generated_columns: vec![
|
||||
generated_column("phone_ext", "phone_extension", false),
|
||||
generated_column("phone_type", "phone_type", false),
|
||||
generated_column("phone_country", "phone_country", false),
|
||||
generated_column(
|
||||
"phone_calling_code",
|
||||
"phone_calling_code",
|
||||
false,
|
||||
),
|
||||
],
|
||||
..declarable("phone")
|
||||
},
|
||||
ColumnType {
|
||||
declarable: false,
|
||||
sql_type: "INTEGER".to_string(),
|
||||
|
||||
Reference in New Issue
Block a user