Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recognize int as Integer on Sqlite #553

Merged
merged 1 commit into from Mar 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -13,7 +13,8 @@ async fn introspecting_a_simple_table_with_gql_types_must_work(api: &TestApi) {
t.add_column("float", types::float());
t.add_column("date", types::date());
t.add_column("id", types::primary());
t.add_column("int", types::integer());
t.add_column("integer", types::integer());
t.inject_custom("int int not null");
t.add_column("string", types::text());
});
})
Expand All @@ -25,6 +26,7 @@ async fn introspecting_a_simple_table_with_gql_types_must_work(api: &TestApi) {
float Float
id Int @id @default(autoincrement())
int Int
integer Int
string String
}
"#;
Expand Down
2 changes: 2 additions & 0 deletions libs/sql-schema-describer/src/sqlite.rs
Expand Up @@ -341,6 +341,7 @@ fn get_column_type(tpe: &str, arity: ColumnArity) -> ColumnType {
let family = match tpe_lower.as_ref() {
// SQLite only has a few native data types: https://www.sqlite.org/datatype3.html
// It's tolerant though, and you can assign any data type you like to columns
"int" => ColumnTypeFamily::Int,
"integer" => ColumnTypeFamily::Int,
"real" => ColumnTypeFamily::Float,
"float" => ColumnTypeFamily::Float,
Expand All @@ -359,6 +360,7 @@ fn get_column_type(tpe: &str, arity: ColumnArity) -> ColumnType {
"datetime[]" => ColumnTypeFamily::DateTime,
"double[]" => ColumnTypeFamily::Float,
"float[]" => ColumnTypeFamily::Float,
"int[]" => ColumnTypeFamily::Int,
"integer[]" => ColumnTypeFamily::Int,
"text[]" => ColumnTypeFamily::String,
_ => ColumnTypeFamily::Unknown,
Expand Down
17 changes: 16 additions & 1 deletion libs/sql-schema-describer/tests/sqlite_introspection_tests.rs
Expand Up @@ -12,6 +12,7 @@ use sqlite::*;
async fn sqlite_column_types_must_work() {
let mut migration = Migration::new().schema(SCHEMA);
migration.create_table("User", move |t| {
t.inject_custom("int_col int not null");
t.add_column("int4_col", types::integer());
t.add_column("text_col", types::text());
t.add_column("real_col", types::float());
Expand All @@ -23,6 +24,16 @@ async fn sqlite_column_types_must_work() {
let result = inspector.describe(SCHEMA).await.expect("describing");
let table = result.get_table("User").expect("couldn't get User table");
let mut expected_columns = vec![
Column {
name: "int_col".to_string(),
tpe: ColumnType {
raw: "int".to_string(),
family: ColumnTypeFamily::Int,
arity: ColumnArity::Required,
},
default: None,
auto_increment: false,
},
Column {
name: "int4_col".to_string(),
tpe: ColumnType {
Expand Down Expand Up @@ -227,7 +238,11 @@ async fn sqlite_text_primary_keys_must_be_inferred_on_table_and_not_as_separate_
});
let full_sql = migration.make::<barrel::backend::Sqlite>();

let inspector = get_sqlite_describer(&full_sql, "sqlite_text_primary_keys_must_be_inferred_on_table_and_not_as_separate_indexes").await;
let inspector = get_sqlite_describer(
&full_sql,
"sqlite_text_primary_keys_must_be_inferred_on_table_and_not_as_separate_indexes",
)
.await;
let result = inspector.describe(SCHEMA).await.expect("describing");

let table = result.get_table("User").expect("couldn't get User table");
Expand Down