Repository: diesel-rs/diesel
File: diesel_cli/src/infer_schema_internals/sqlite.rs (Rust)

Code before:
    // and ensure that the rowid column uses the right type.
    let primary_key = get_primary_keys(conn, table)?;
    if primary_key.len() == 1 {
        let primary_key = primary_key.first().expect("guaranteed to have one element");
        if !result.iter_mut().any(|x| {
            if &x.column_name == primary_key {
                if x.nullable && x.type_name.eq_ignore_ascii_case("Integer") {
                    // A rowid column with type Integer was found, since rowid
                    // is signed 64-bit integer, we should force that but for
                    // now this gives type issues with foreign keys, so let's
                    // leave it as is.
                    x.type_name = String::from(ROWID_TYPE_NAME);
                }
                true
            } else {
                false
            }
        }) {
            // Prepend implicit rowid column for the rowid implicit primary key.
            result.insert(
                0,
                ColumnInformation {
                    column_name: String::from(primary_key),
                    type_name: String::from(ROWID_TYPE_NAME),
                    type_schema: None,
                    nullable: true,
                    max_length: None,
                    comment: None,
                },
            );
        }
    }

    match column_sorting {
        ColumnSorting::OrdinalPosition => {}
        ColumnSorting::Name => {
            result.sort_by(|a: &ColumnInformation, b: &ColumnInformation| {
                a.column_name.cmp(&b.column_name)
            });
        }
    };
    Ok(result)
}

impl QueryableByName<Sqlite> for ColumnInformation {
    fn build<'a>(row: &impl NamedRow<'a, Sqlite>) -> deserialize::Result<Self> {
        let column_name = NamedRow::get::<Text, String>(row, "name")?;
        let type_name = NamedRow::get::<Text, String>(row, "type")?;
        let notnull = NamedRow::get::<Bool, bool>(row, "notnull")?;

        Ok(Self::new(

Review comment (suggestion):
```suggestion
                    nullable: false,
```

I think rowid cannot ever by null, right? (At least that what's stated [here](https://sqlite.org/rowidtable.html))

Code after:
    // and ensure that the rowid column uses the right type.
    let primary_key = get_primary_keys(conn, table)?;
    if primary_key.len() == 1 {
        let primary_key = primary_key.first().expect("guaranteed to have one element");
        if !result.iter_mut().any(|x| &x.column_name == primary_key) {
            // Prepend implicit rowid column for the rowid implicit primary key.
            result.insert(
                0,
                ColumnInformation {
                    column_name: String::from(primary_key),
                    type_name: String::from(ROWID_TYPE_NAME),
                    type_schema: None,
                    nullable: false,
                    max_length: None,
                    comment: None,
                },
            );
        }
    }

    match column_sorting {
        ColumnSorting::OrdinalPosition => {}
        ColumnSorting::Name => {
            result.sort_by(|a: &ColumnInformation, b: &ColumnInformation| {
                a.column_name.cmp(&b.column_name)
            });
        }
    };
    Ok(result)
}

impl QueryableByName<Sqlite> for ColumnInformation {
    fn build<'a>(row: &impl NamedRow<'a, Sqlite>) -> deserialize::Result<Self> {
        let column_name = NamedRow::get::<Text, String>(row, "name")?;
        let type_name = NamedRow::get::<Text, String>(row, "type")?;
        let notnull = NamedRow::get::<Bool, bool>(row, "notnull")?;

        Ok(Self::new(
            column_name,
            type_name,
            None,
            !notnull,
            None,
            None,
        ))
    }
}

struct PrimaryKeyInformation {
    name: String,
    primary_key: bool,