hasqlator-mysql 0.0.3 → 0.0.4
raw patch · 2 files changed
+25/−18 lines, 2 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Database.MySQL.Hasqlator.Typed.Schema: [includeSchema] :: Properties -> Bool
- Database.MySQL.Hasqlator.Typed.Schema: Properties :: (String -> String) -> (String -> String) -> (String -> String) -> Bool -> (String -> String) -> (String -> String) -> (String -> String) -> Properties
+ Database.MySQL.Hasqlator.Typed.Schema: Properties :: (String -> String) -> (String -> String) -> (String -> String) -> Bool -> Bool -> (String -> String) -> (String -> String) -> (String -> String) -> Properties
Files
hasqlator-mysql.cabal view
@@ -1,5 +1,5 @@ Name: hasqlator-mysql-Version: 0.0.3+Version: 0.0.4 Synopsis: composable SQL generation Category: Database Copyright: Kristof Bastiaensen (2020)
src/Database/MySQL/Hasqlator/Typed/Schema.hs view
@@ -24,11 +24,9 @@ import Data.Int import Data.Scientific import Data.Time-import Control.Monad import qualified Data.ByteString as StrictBS import Data.Aeson(Value) import Data.Char-import Data.List import GHC.TypeLits(Symbol) import Text.Pretty.Simple @@ -245,6 +243,7 @@ , tableNameModifier :: String -> String , classNameModifier :: String -> String , includeInsertor :: Bool+ , includeSchema :: Bool , insertorTypeModifier :: String -> String , insertorNameModifier :: String -> String , insertorFieldModifier :: String -> String@@ -278,6 +277,7 @@ downcase n <> (if downcase n `elem` reserved then "_" else mempty) <> "_tbl" , classNameModifier = \n -> "Has_" <> n <> "_Field" , includeInsertor = True+ , includeSchema = True , insertorTypeModifier = \n -> removeUnderscore (upcase n) <> "Fields" , insertorNameModifier = \n -> downcase (removeUnderscore n) <> "Insertor"@@ -286,11 +286,16 @@ where reserved :: [String] reserved = ["id", "class", "data", "type", "foreign", "import", "default", "case"]- ++getColumnTableName :: Properties -> ColumnInfo -> String+getColumnTableName Properties{includeSchema}+ ColumnInfo{columnTableSchema, columnTableName}+ | includeSchema = Text.unpack columnTableSchema <> Text.unpack columnTableName+ | otherwise = Text.unpack columnTableName+ makeField :: Properties -> Name -> ColumnInfo -> Q [Dec]-makeField props dbName ci@ColumnInfo{columnTableName,- columnName,- columnNullable} =+makeField props dbName ci@ColumnInfo{columnName+ ,columnNullable} = sequence [ sigD (mkName $ fieldNameModifier props fieldName) [t| T.Field@@ -309,24 +314,28 @@ [] ] where fieldName = Text.unpack columnName- tableName = Text.unpack columnTableName+ tableName = getColumnTableName props ci makeTable :: Properties -> Name -> TableInfo -> Q [Dec]-makeTable props dbname TableInfo{tableName} =+makeTable Properties{tableNameModifier, includeSchema}+ dbname+ TableInfo{tableSchema, tableName} = sequence [ sigD- (mkName $ tableNameModifier props tableString)+ (mkName $ tableNameModifier tableString) [t| T.Table $(litT $ strTyLit tableString) $(conT dbname) |]- , valD (varP $ mkName $ tableNameModifier props tableString)+ , valD (varP $ mkName $ tableNameModifier tableString) (normalB [e| T.Table $(conE 'Nothing) $(litE $ stringL tableString) |]) [] ]- where tableString = Text.unpack tableName+ where tableString+ | includeSchema = Text.unpack tableSchema <> Text.unpack tableName+ | otherwise = Text.unpack tableName fieldClass :: Properties -> Name -> String -> Q Dec fieldClass props dbName columnName =@@ -346,12 +355,11 @@ fieldInstance :: Properties -> ColumnInfo -> Q Dec fieldInstance props ci@ColumnInfo{columnName,- columnNullable,- columnTableName} =+ columnNullable} = instanceD (pure []) [t| $(conT $ mkName $ classNameModifier props $ fieldNameModifier props $ Text.unpack columnName)- $(litT $ strTyLit $ Text.unpack columnTableName)+ $(litT $ strTyLit tableName) $(promotedT $ if columnNullable then 'T.Nullable else 'T.NotNull) $(columnTHType True ci) |]@@ -362,7 +370,7 @@ |]) []] where fieldName = Text.unpack columnName- tableName = Text.unpack columnTableName+ tableName = getColumnTableName props ci insertorType :: Properties -> TableInfo -> Q Dec@@ -379,8 +387,7 @@ , Bang NoSourceUnpackedness NoSourceStrictness , ) <$> columnTHType False ci- - + insertor :: Properties -> Name -> TableInfo -> Q [Dec] insertor props dbName ti = sequence [ sigD