fix: Correct the AUTOINCREMENT statement and PRIMARY KEY place in declaration
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user