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

add showSqlTypeWithSchema for types in a schema #589

Closed
wants to merge 5 commits into from
Closed
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
3 changes: 2 additions & 1 deletion src/Opaleye/Experimental/Enum.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module Opaleye.Experimental.Enum

import Opaleye.Field (Field)
import qualified Opaleye as O
import qualified Opaleye.Internal.PGTypes as IPT
import qualified Opaleye.Internal.RunQuery as RQ

import Data.ByteString.Char8 (unpack)
Expand Down Expand Up @@ -115,7 +116,7 @@ enumMapperWithSchema :: String
-- ^ The @sqlEnum@ type variable is phantom. To protect
-- yourself against type mismatches you should set it to
-- the Haskell type that you use to represent the @ENUM@.
enumMapperWithSchema schema type_ = enumMapper' (render (doubleQuotes (text schema) <> text "." <> doubleQuotes (text type_)))
enumMapperWithSchema schema type_ = enumMapper' $ IPT.sqlTypeWithSchema schema type_

enumMapper' :: String
-- ^ The name of the @ENUM@ type
Expand Down
5 changes: 5 additions & 0 deletions src/Opaleye/Internal/PGTypes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import qualified Data.Text.Lazy.Encoding as LTextEncoding
import qualified Data.ByteString as SByteString
import qualified Data.ByteString.Lazy as LByteString
import qualified Data.Time.Format.ISO8601.Compat as Time
import Text.PrettyPrint.HughesPJ ((<>), doubleQuotes, render, text)
import Prelude hiding ((<>))

unsafePgFormatTime :: Time.ISO8601 t => HPQ.Name -> t -> Field c
unsafePgFormatTime typeName = castToType typeName . format
Expand All @@ -35,6 +37,9 @@ strictDecodeUtf8 = SText.unpack . STextEncoding.decodeUtf8
lazyDecodeUtf8 :: LByteString.ByteString -> String
lazyDecodeUtf8 = LText.unpack . LTextEncoding.decodeUtf8

sqlTypeWithSchema :: String -> String -> String
sqlTypeWithSchema schema type_ = render (doubleQuotes (text schema) <> text "." <> doubleQuotes (text type_))

class IsSqlType sqlType where
showSqlType :: proxy sqlType -> String

Expand Down
Loading