packages feed

postgresql-query 3.1.0 → 3.2.0

raw patch · 4 files changed

+28/−29 lines, 4 files

Files

CHANGELOG.md view
@@ -1,5 +1,10 @@ # CHANGELOG +## 3.2.0+### Changed+* Change interface of `deriveEntity`: now you can state the schema of+  table of entity. (by @4e6)+ ## 3.1.0 ### Changed * Support for inflections-0.3 (fixed buildability). Tested with LTS 8.5
postgresql-query.cabal view
@@ -1,5 +1,5 @@ name:                postgresql-query-version:             3.1.0+version:             3.2.0  synopsis: Sql interpolating quasiquote plus some kind of primitive ORM           using it
src/Database/PostgreSQL/Query/TH.hs view
@@ -25,8 +25,8 @@  $(deriveEverything   def { eoIdType        = ''Id-      , eoTableName     = toUnderscore-      , eoColumnNames   = toUnderscore . drop 1+      , eoTableName     = textFN . toUnderscore'+      , eoColumnNames   = textFN . toUnderscore' . drop 1       , eoDeriveClasses =         [''Show, ''Read, ''Ord, ''Eq         , ''FromField, ''ToField, ''PathPiece]
src/Database/PostgreSQL/Query/TH/Entity.hs view
@@ -7,10 +7,10 @@  import Data.Default import Data.String-import Data.Text (pack, unpack)+import Data.Text (Text, pack, unpack) import Database.PostgreSQL.Query.Entity.Class import Database.PostgreSQL.Query.TH.Common-import Database.PostgreSQL.Query.Types ( FN(..) )+import Database.PostgreSQL.Query.Types ( FN(..), textFN ) import Database.PostgreSQL.Simple.FromField import Database.PostgreSQL.Simple.ToField import GHC.Generics (Generic)@@ -24,37 +24,31 @@  -- | Options for deriving `Entity` data EntityOptions = EntityOptions-    { eoTableName      :: String -> String -- ^ Type name to table name converter-    , eoColumnNames    :: String -> String -- ^ Record field to column name converter-    , eoDeriveClasses  :: [Name]           -- ^ Typeclasses to derive for Id-    , eoIdType         :: Name             -- ^ Base type for Id+    { eoTableName      :: Text -> FN -- ^ Type name to table name converter+    , eoColumnNames    :: Text -> FN -- ^ Record field to column name converter+    , eoDeriveClasses  :: [Name]     -- ^ Typeclasses to derive for Id+    , eoIdType         :: Name       -- ^ Base type for Id     } deriving (Generic)  #if !MIN_VERSION_inflections(0,3,0)-instance Default EntityOptions where-  def = EntityOptions-        { eoTableName     = toUnderscore-        , eoColumnNames   = toUnderscore-        , eoDeriveClasses = [ ''Ord, ''Eq, ''Show-                            , ''FromField, ''ToField ]-        , eoIdType        = ''Integer-        }+toUnderscore' :: Text -> Text+toUnderscore' = pack . toUnderscore . unpack #else+toUnderscore' :: Text -> Text+toUnderscore' = either error' id . toUnderscore+  where+    error' er = error $ "toUnderscore: " ++ show er+#endif+ instance Default EntityOptions where   def = EntityOptions-        { eoTableName     = toUnderscore'-        , eoColumnNames   = toUnderscore'+        { eoTableName     = textFN . toUnderscore'+        , eoColumnNames   = textFN . toUnderscore'         , eoDeriveClasses = [ ''Ord, ''Eq, ''Show                             , ''FromField, ''ToField ]         , eoIdType        = ''Integer         } -toUnderscore' :: String -> String-toUnderscore' s = case toUnderscore $ pack s of-  Left er -> error $ "toUnderscore: " ++ show er-  Right a -> unpack a-#endif- {- | Derives instance for 'Entity' using type name and field names. Also generates type synonim for ID. E.g. code like this: @@ -67,8 +61,8 @@  $(deriveEntity   def { eoIdType        = ''Id-      , eoTableName     = toUnderscore-      , eoColumnNames   = toUnderscore . drop 1+      , eoTableName     = textFN . toUnderscore'+      , eoColumnNames   = textFN . toUnderscore' . drop 1       , eoDeriveClasses =         [''Show, ''Read, ''Ord, ''Eq         , ''FromField, ''ToField, ''PathPiece]@@ -115,8 +109,8 @@         iddec = NewtypeInstD [] entityIdName [ConT tname]                 idcon (eoDeriveClasses opts) #endif-        tblName = fromString $ eoTableName opts tnames-        fldNames = map (fromString . eoColumnNames opts . nameBase)+        tblName = eoTableName opts $ pack tnames+        fldNames = map (eoColumnNames opts . pack . nameBase)                    $ cFieldNames tcon     VarE ntableName  <- [e|tableName|]     VarE nfieldNames <- [e|fieldNames|]