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

Bug/postgres array detection #377

Merged
merged 3 commits into from
Aug 31, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions generator/postgres/query_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ select
not attr.attnotnull as "column.isNullable",
attr.attgenerated = 's' as "column.isGenerated",
attr.atthasdef as "column.hasDefault",
(case tp.typtype
when 'b' then 'base'
when 'd' then 'base'
when 'e' then 'enum'
when 'r' then 'range'
(case
when tp.typtype = 'b' AND tp.typcategory <> 'A' then 'base'
when tp.typtype = 'b' AND tp.typcategory = 'A' then 'array'
when tp.typtype = 'd' then 'base'
when tp.typtype = 'e' then 'enum'
when tp.typtype = 'r' then 'range'
end) as "dataType.Kind",
(case when tp.typtype = 'd' then (select pg_type.typname from pg_catalog.pg_type where pg_type.oid = tp.typbasetype)
when tp.typcategory = 'A' then pg_catalog.format_type(attr.atttypid, attr.atttypmod)
Expand Down
9 changes: 9 additions & 0 deletions tests/postgres/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,18 @@ func TestGenerator_TableMetadata(t *testing.T) {
// Spot check the actor table and assert that the emitted
// properties are as expected.
var got metadata.Table
var specialFeatures metadata.Column
for _, table := range schema.TablesMetaData {
if table.Name == "actor" {
got = table
}
if table.Name == "film" {
for _, column := range table.Columns {
if column.Name == "special_features" {
specialFeatures = column
}
}
}
}

want := metadata.Table{
Expand All @@ -238,6 +246,7 @@ func TestGenerator_TableMetadata(t *testing.T) {
},
}
require.Equal(t, want, got)
require.Equal(t, metadata.ArrayType, specialFeatures.DataType.Kind)
}

func TestGeneratorSpecialCharacters(t *testing.T) {
Expand Down
Loading