fix: Correct the AUTOINCREMENT statement and PRIMARY KEY place in declaration
Some checks failed
Build project / SonarQube Trigger (push) Has been cancelled
Build project / quality-and-build (push) Has been cancelled

This commit is contained in:
Namu
2026-06-16 21:19:11 +02:00
parent e77d8e672d
commit f922ca16f9
6 changed files with 42 additions and 15 deletions

View File

@@ -20,8 +20,12 @@ impl ColumnSqlSerializer {
query += "UNIQUE " // Notice the space at the end
}
if column.primary_key {
query += "PRIMARY KEY ";
}
if column.auto_increment {
query += "AUTO_INCREMENT " // Notice the space at the end
query += "AUTOINCREMENT " // Notice the space at the end
}
if let Some(default) = column.default {
@@ -42,10 +46,6 @@ impl ColumnSqlSerializer {
query += &format!("CHECK {} ", check_constraint);
}
if column.primary_key {
query += "PRIMARY KEY ";
}
Ok(query.trim_end().to_string())
}
}
@@ -69,7 +69,7 @@ mod tests {
let serializer = ColumnSqlSerializer{};
let result = serializer.serialize(column).unwrap();
assert_eq!(result, "id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY".to_string());
assert_eq!(result, "id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT".to_string());
}
#[test]

View File

@@ -40,6 +40,6 @@ mod test {
let result = serializer.serialize(table);
assert_eq!(result, "CREATE TABLE test (id INTEGER NOT NULL AUTO_INCREMENT);".to_string());
assert_eq!(result, "CREATE TABLE test (id INTEGER NOT NULL AUTOINCREMENT);".to_string());
}
}

View File

@@ -13,8 +13,8 @@ pub struct ColumnBuilder {
}
impl ColumnBuilder {
pub fn new() -> ColumnBuilder {
ColumnBuilder {
pub fn new() -> Self {
Self {
name: String::new(),
datatype: SQLiteDatatypes::Text,
nullable: false,
@@ -68,7 +68,7 @@ impl ColumnBuilder {
pub fn build(self) -> Result<Column, String> {
if self.auto_increment && self.datatype != SQLiteDatatypes::Integer {
return Err("Cannot set AUTO_INCREMENT on non-INTEGER column".to_string());
return Err("Cannot set AUTOINCREMENT on non-INTEGER column".to_string());
}
Ok(Column {
@@ -97,8 +97,8 @@ pub struct TableBuilder {
}
impl TableBuilder {
pub fn new() -> TableBuilder {
TableBuilder {
pub fn new() -> Self {
Self {
name: String::new(),
columns: Vec::new(),
strict: false,