Skip to content

Commit

Permalink
Initial Postgresql tsvector Type Support
Browse files Browse the repository at this point in the history
  • Loading branch information
s0kil committed Jun 24, 2021
1 parent a5f7dc6 commit bc1308b
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 5 deletions.
1 change: 1 addition & 0 deletions IHP/IDE/SchemaDesigner/Compiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ compilePostgresType PSerial = "SERIAL"
compilePostgresType PBigserial = "BIGSERIAL"
compilePostgresType PJSONB = "JSONB"
compilePostgresType PInet = "INET"
compilePostgresType PTSVector = "TSVECTOR"
compilePostgresType (PArray type_) = compilePostgresType type_ <> "[]"
compilePostgresType (PCustomType theType) = theType

Expand Down
9 changes: 7 additions & 2 deletions IHP/IDE/SchemaDesigner/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ sqlType = choice $ map optionalArray
, bigserial
, jsonb
, inet
, tsvector
, customType
]
where
Expand Down Expand Up @@ -336,6 +337,10 @@ sqlType = choice $ map optionalArray
try (symbol' "INET")
pure PInet

tsvector = do
try (symbol' "TSVECTOR")
pure PTSVector

optionalArray typeParser= do
arrayType <- typeParser;
(try do symbol' "[]"; pure $ PArray arrayType) <|> pure arrayType
Expand All @@ -356,7 +361,7 @@ table = [
, binary "<" LessThanExpression
, binary ">=" GreaterThanOrEqualToExpression
, binary ">" GreaterThanExpression

, binary "IS" IsExpression
, prefix "NOT" NotExpression
],
Expand Down Expand Up @@ -436,4 +441,4 @@ createTrigger = do
lexeme "CREATE"
lexeme "TRIGGER"
raw <- cs <$> someTill (anySingle) (char ';')
pure UnknownStatement { raw = "CREATE TRIGGER " <> raw }
pure UnknownStatement { raw = "CREATE TRIGGER " <> raw }
1 change: 1 addition & 0 deletions IHP/IDE/SchemaDesigner/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ data PostgresType
| PBigserial
| PJSONB
| PInet
| PTSVector
| PArray PostgresType
| PCustomType Text
deriving (Eq, Show)
4 changes: 3 additions & 1 deletion IHP/ModelSupport.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module IHP.ModelSupport
( module IHP.ModelSupport
, module IHP.Postgres.Point
, module IHP.Postgres.Inet
, module IHP.Postgres.TSVector
) where

import IHP.HaskellSupport
Expand Down Expand Up @@ -46,6 +47,7 @@ import qualified Data.Pool as Pool
import qualified GHC.Conc
import IHP.Postgres.Point
import IHP.Postgres.Inet
import IHP.Postgres.TSVector
import qualified Data.ByteString.Char8 as ByteString
import IHP.Log.Types
import qualified IHP.Log as Log
Expand Down Expand Up @@ -747,7 +749,7 @@ instance (FromField value, Typeable value) => FromField [value] where
-- > action MyAction = autoRefresh do
-- > users <- sqlQuery "SELECT * FROM users WHERE .."
-- > trackTableRead "users"
-- >
-- >
-- > render MyView { .. }
--
--
Expand Down
2 changes: 1 addition & 1 deletion IHP/Postgres/Inet.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{-# LANGUAGE TemplateHaskell #-}
{-|
Module: IHP.Postgres.Inet
Description: Adds support for storing IP addresses in INET fields. CIDR Notation is not suppported at the moment.
Description: Adds support for storing IP addresses in INET fields. CIDR Notation is not supported at the moment.
Copyright: (c) digitally induced GmbH, 2020
-}
module IHP.Postgres.Inet where
Expand Down
2 changes: 1 addition & 1 deletion IHP/Postgres/Point.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ instance ToField Point where
(toField x) :
(Plain (char8 ',')) :
(toField y) :
[Plain (char8 ')')]
[Plain (char8 ')')]
13 changes: 13 additions & 0 deletions IHP/Postgres/TSVector.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{-|
Module: IHP.Postgres.TSVector
Description: Adds support for the Postgres tsvector type
Copyright: (c) digitally induced GmbH, 2021
-}
module IHP.Postgres.TSVector where

import BasicPrelude

-- | Represents a Postgres tsvector
--
-- See https://www.postgresql.org/docs/current/datatype-textsearch.html
data TSVector = TSVector deriving (Eq, Show, Ord)
1 change: 1 addition & 0 deletions IHP/SchemaCompiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ atomicType = \case
PArray type_ -> "[" <> atomicType type_ <> "]"
PPoint -> "Point"
PInet -> "Net.IP.IP"
PTSVector -> "TSVector"

haskellType :: (?schema :: Schema) => CreateTable -> Column -> Text
haskellType table@CreateTable { name = tableName, primaryKeyConstraint } column@Column { name, columnType, notNull }
Expand Down
1 change: 1 addition & 0 deletions ihp.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ library
, IHP.Version
, IHP.Postgres.Point
, IHP.Postgres.Inet
, IHP.Postgres.TSVector
, Paths_ihp
, IHP.Job.Queue
, IHP.Job.Runner
Expand Down

0 comments on commit bc1308b

Please sign in to comment.