Skip to content

Commit

Permalink
Added jsonb type
Browse files Browse the repository at this point in the history
  • Loading branch information
mpscholten committed Sep 8, 2020
1 parent e33d60b commit 856b648
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions IHP/IDE/SchemaDesigner/Compiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ compilePostgresType (PVaryingN limit) = "CHARACTER VARYING(" <> show limit <> ")
compilePostgresType (PCharacterN length) = "CHARACTER(" <> show length <> ")"
compilePostgresType PSerial = "SERIAL"
compilePostgresType PBigserial = "BIGSERIAL"
compilePostgresType PJSONB = "JSONB"
compilePostgresType (PCustomType theType) = theType

compileIdentifier :: _ -> Text
Expand Down
5 changes: 5 additions & 0 deletions IHP/IDE/SchemaDesigner/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ sqlType = choice
, varchar
, serial
, bigserial
, jsonb
, customType
]
where
Expand Down Expand Up @@ -310,6 +311,10 @@ sqlType = choice
try (symbol' "BIGSERIAL")
pure PBigserial

jsonb = do
try (symbol' "JSONB")
pure PJSONB

customType = do
theType <- try (takeWhile1P (Just "Custom type") (\c -> isAlphaNum c || c == '_'))
pure (PCustomType theType)
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 @@ -89,5 +89,6 @@ data PostgresType
| PCharacterN Int
| PSerial
| PBigserial
| PJSONB
| PCustomType Text
deriving (Eq, Show)
4 changes: 4 additions & 0 deletions IHP/ModelSupport.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import Control.Applicative (Const)
import qualified GHC.Types as Type
import qualified Data.Text as Text
import Data.Aeson (ToJSON (..))
import qualified Data.Aeson as Aeson

-- | Provides the db connection and some IHP-specific db configuration
data ModelContext = ModelContext
Expand Down Expand Up @@ -455,3 +456,6 @@ data RecordNotFoundException
deriving (Show)

instance Exception RecordNotFoundException

instance Default Aeson.Value where
def = Aeson.Null
2 changes: 2 additions & 0 deletions IHP/SchemaCompiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ atomicType :: PostgresType -> Text
atomicType = \case
PInt -> "Int"
PBigInt -> "Integer"
PJSONB -> "Data.Aeson.Value"
PText -> "Text"
PBoolean -> "Bool"
PTimestampWithTimezone -> "UTCTime"
Expand Down Expand Up @@ -134,6 +135,7 @@ compileTypes options schema@(Schema statements) =
<> "import Data.Data\n"
<> "import qualified Data.String.Conversions\n"
<> "import qualified Data.Text.Encoding\n"
<> "import qualified Data.Aeson\n"
<> "import Database.PostgreSQL.Simple.Types (Query (Query), Binary ( .. ))\n"

compileStatementPreview :: [Statement] -> Statement -> Text
Expand Down

0 comments on commit 856b648

Please sign in to comment.