Skip to content

Commit

Permalink
added support for smallint and brought existing support for bigint (a…
Browse files Browse the repository at this point in the history
…nd smallint) to the IDE
  • Loading branch information
fegu committed Jan 10, 2021
1 parent 2a206af commit 3b1c594
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 5 deletions.
3 changes: 2 additions & 1 deletion IHP/IDE/SchemaDesigner/Compiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ compilePostgresType :: PostgresType -> Text
compilePostgresType PUUID = "UUID"
compilePostgresType PText = "TEXT"
compilePostgresType PInt = "INT"
compilePostgresType PSmallInt = "SMALLINT"
compilePostgresType PBigInt = "BIGINT"
compilePostgresType PBoolean = "BOOLEAN"
compilePostgresType PTimestamp = "TIMESTAMP WITHOUT TIME ZONE"
Expand Down Expand Up @@ -358,4 +359,4 @@ compileIdentifier identifier = if identifierNeedsQuoting then tshow identifier e
, "VARCHAR"
]

indent text = " " <> text
indent text = " " <> text
7 changes: 6 additions & 1 deletion IHP/IDE/SchemaDesigner/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,9 @@ sqlType :: Parser PostgresType
sqlType = choice $ map optionalArray
[ uuid
, text
, bigint
, smallint
, int
, bigint
, bool
, timestamp
, timestampZ
Expand Down Expand Up @@ -234,6 +235,10 @@ sqlType = choice $ map optionalArray
try (symbol' "TEXT")
pure PText

smallint = do
try (symbol' "SMALLINT") <|> try (symbol' "INT2")
pure PSmallInt

int = do
try (symbol' "INTEGER") <|> try (symbol' "INT4") <|> try (symbol' "INT")
pure PInt
Expand Down
1 change: 1 addition & 0 deletions IHP/IDE/SchemaDesigner/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ data PostgresType
= PUUID
| PText
| PInt
| PSmallInt
| PBigInt
| PBoolean
| PTimestampWithTimezone
Expand Down
4 changes: 3 additions & 1 deletion IHP/IDE/SchemaDesigner/View/Columns/Edit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ typeSelector :: Maybe PostgresType -> [Text] -> Html
typeSelector postgresType enumNames = [hsx|
<select id="typeSelector" name="columnType" class="form-control select2-simple">
{option selected "TEXT" "Text"}
{option selected "INT" "Int"}
{option selected "SMALLINT" "Int (16bit)"}
{option selected "INT" "Int (32bit)"}
{option selected "BIGINT" "Int (64bit)"}
{option selected "UUID" "UUID"}
{option selected "BOOLEAN" "Bool"}
{option selected "TIMESTAMP WITH TIME ZONE" "Timestamp (UTCTime)"}
Expand Down
1 change: 1 addition & 0 deletions IHP/SchemaCompiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ previewCompilerOptions = CompilerOptions { compileGetAndSetFieldInstances = Fals

atomicType :: PostgresType -> Text
atomicType = \case
PSmallInt -> "Int"
PInt -> "Int"
PBigInt -> "Integer"
PJSONB -> "Data.Aeson.Value"
Expand Down
6 changes: 4 additions & 2 deletions Test/IDE/SchemaDesigner/ParserSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,17 @@ tests = do
it "should parse CREATE TYPE .. AS ENUM without values" do
parseSql "CREATE TYPE colors AS ENUM ();" `shouldBe` CreateEnumType { name = "colors", values = [] }

it "should parse a CREATE TABLE with INTEGER / INT / INT4 / BIGINT / INT 8 columns" do
parseSql "CREATE TABLE ints (int_a INTEGER, int_b INT, int_c int4, bigint_a BIGINT, bigint_b int8);" `shouldBe` StatementCreateTable CreateTable
it "should parse a CREATE TABLE with INTEGER / INT / INT4 / SMALLINT / INT2 / BIGINT / INT 8 columns" do
parseSql "CREATE TABLE ints (int_a INTEGER, int_b INT, int_c int4, bigint_a BIGINT, bigint_b int8, smallint_a SMALLINT, smallint_b INT2);" `shouldBe` StatementCreateTable CreateTable
{ name = "ints"
, columns =
[ col { name = "int_a", columnType = PInt }
, col { name = "int_b", columnType = PInt }
, col { name = "int_c", columnType = PInt }
, col { name = "bigint_a", columnType = PBigInt }
, col { name = "bigint_b", columnType = PBigInt }
, col { name = "smallint_a", columnType = PSmallInt }
, col { name = "smallint_b", columnType = PSmallInt }
]
, primaryKeyConstraint = PrimaryKeyConstraint []
, constraints = []
Expand Down

0 comments on commit 3b1c594

Please sign in to comment.