mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-23 17:05:36 +01:00
add unique field to Column
This commit is contained in:
@@ -259,6 +259,7 @@ impl PseudoTable {
|
||||
is_rowid_alias: false,
|
||||
notnull: false,
|
||||
default: None,
|
||||
unique: false,
|
||||
});
|
||||
}
|
||||
pub fn get_column(&self, name: &str) -> Option<(usize, &Column)> {
|
||||
@@ -365,6 +366,7 @@ fn create_table(
|
||||
let mut primary_key = false;
|
||||
let mut notnull = false;
|
||||
let mut order = SortOrder::Asc;
|
||||
let mut unique = false;
|
||||
for c_def in &col_def.constraints {
|
||||
match &c_def.constraint {
|
||||
limbo_sqlite3_parser::ast::ColumnConstraint::PrimaryKey {
|
||||
@@ -382,6 +384,10 @@ fn create_table(
|
||||
limbo_sqlite3_parser::ast::ColumnConstraint::Default(expr) => {
|
||||
default = Some(expr.clone())
|
||||
}
|
||||
// TODO: for now we don't check Resolve type of unique
|
||||
limbo_sqlite3_parser::ast::ColumnConstraint::Unique(..) => {
|
||||
unique = true;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
@@ -403,6 +409,7 @@ fn create_table(
|
||||
is_rowid_alias: typename_exactly_integer && primary_key,
|
||||
notnull,
|
||||
default,
|
||||
unique,
|
||||
});
|
||||
}
|
||||
if options.contains(TableOptions::WITHOUT_ROWID) {
|
||||
@@ -456,6 +463,7 @@ pub struct Column {
|
||||
pub is_rowid_alias: bool,
|
||||
pub notnull: bool,
|
||||
pub default: Option<Expr>,
|
||||
pub unique: bool,
|
||||
}
|
||||
|
||||
impl Column {
|
||||
@@ -658,6 +666,7 @@ pub fn sqlite_schema_table() -> BTreeTable {
|
||||
is_rowid_alias: false,
|
||||
notnull: false,
|
||||
default: None,
|
||||
unique: false,
|
||||
},
|
||||
Column {
|
||||
name: Some("name".to_string()),
|
||||
@@ -667,6 +676,7 @@ pub fn sqlite_schema_table() -> BTreeTable {
|
||||
is_rowid_alias: false,
|
||||
notnull: false,
|
||||
default: None,
|
||||
unique: false,
|
||||
},
|
||||
Column {
|
||||
name: Some("tbl_name".to_string()),
|
||||
@@ -676,6 +686,7 @@ pub fn sqlite_schema_table() -> BTreeTable {
|
||||
is_rowid_alias: false,
|
||||
notnull: false,
|
||||
default: None,
|
||||
unique: false,
|
||||
},
|
||||
Column {
|
||||
name: Some("rootpage".to_string()),
|
||||
@@ -685,6 +696,7 @@ pub fn sqlite_schema_table() -> BTreeTable {
|
||||
is_rowid_alias: false,
|
||||
notnull: false,
|
||||
default: None,
|
||||
unique: false,
|
||||
},
|
||||
Column {
|
||||
name: Some("sql".to_string()),
|
||||
@@ -694,6 +706,7 @@ pub fn sqlite_schema_table() -> BTreeTable {
|
||||
is_rowid_alias: false,
|
||||
notnull: false,
|
||||
default: None,
|
||||
unique: false,
|
||||
},
|
||||
],
|
||||
}
|
||||
@@ -775,6 +788,8 @@ impl Index {
|
||||
));
|
||||
}
|
||||
|
||||
// let unique_columns =
|
||||
|
||||
let index_columns = table
|
||||
.primary_key_columns
|
||||
.iter()
|
||||
@@ -1188,6 +1203,7 @@ mod tests {
|
||||
is_rowid_alias: false,
|
||||
notnull: false,
|
||||
default: None,
|
||||
unique: false,
|
||||
}],
|
||||
};
|
||||
|
||||
|
||||
@@ -216,6 +216,7 @@ pub fn group_by_create_pseudo_table(
|
||||
is_rowid_alias: false,
|
||||
notnull: false,
|
||||
default: None,
|
||||
unique: false,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
|
||||
@@ -72,6 +72,7 @@ pub fn emit_order_by(
|
||||
is_rowid_alias: false,
|
||||
notnull: false,
|
||||
default: None,
|
||||
unique: false,
|
||||
});
|
||||
}
|
||||
for i in 0..result_columns.len() {
|
||||
@@ -90,6 +91,7 @@ pub fn emit_order_by(
|
||||
is_rowid_alias: false,
|
||||
notnull: false,
|
||||
default: None,
|
||||
unique: false,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -597,6 +597,7 @@ impl TableReference {
|
||||
primary_key: false,
|
||||
notnull: false,
|
||||
default: None,
|
||||
unique: false,
|
||||
})
|
||||
.collect(),
|
||||
)));
|
||||
|
||||
@@ -358,7 +358,7 @@ fn check_automatic_pk_index_required(
|
||||
is_descending,
|
||||
} => {
|
||||
let is_integer =
|
||||
typename.is_some() && typename.unwrap().to_uppercase() == "INTEGER";
|
||||
typename.is_some() && typename.unwrap().eq_ignore_ascii_case("INTEGER"); // Should match on any case of INTEGER
|
||||
!is_integer || *is_descending
|
||||
}
|
||||
PrimaryKeyDefinitionType::Composite => true,
|
||||
|
||||
@@ -121,7 +121,7 @@ pub fn parse_schema_rows(
|
||||
});
|
||||
}
|
||||
_ => {
|
||||
// Automatic index on primary key, e.g.
|
||||
// Automatic index on primary key and/or unique constraint, e.g.
|
||||
// table|foo|foo|2|CREATE TABLE foo (a text PRIMARY KEY, b)
|
||||
// index|sqlite_autoindex_foo_1|foo|3|
|
||||
let index_name = row.get::<&str>(1)?.to_string();
|
||||
@@ -559,6 +559,12 @@ pub fn columns_from_create_table_body(body: &ast::CreateTableBody) -> crate::Res
|
||||
)
|
||||
}),
|
||||
is_rowid_alias: false,
|
||||
unique: column_def.constraints.iter().any(|c| {
|
||||
matches!(
|
||||
c.constraint,
|
||||
limbo_sqlite3_parser::ast::ColumnConstraint::Unique(..)
|
||||
)
|
||||
}),
|
||||
};
|
||||
Some(column)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user