MySQL scaffolding support (#247)
This commit is contained in:
parent
8155a5c45b
commit
d10912cf0f
@ -32,7 +32,7 @@ qq = ""
|
|||||||
qq = "$"
|
qq = "$"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
data Backend = Sqlite | Postgresql | MongoDB | Tiny
|
data Backend = Sqlite | Postgresql | Mysql | MongoDB | Tiny
|
||||||
deriving (Eq, Read, Show, Enum, Bounded)
|
deriving (Eq, Read, Show, Enum, Bounded)
|
||||||
|
|
||||||
puts :: String -> IO ()
|
puts :: String -> IO ()
|
||||||
@ -63,18 +63,20 @@ scaffold = do
|
|||||||
|
|
||||||
puts $(codegenDir "input" "database")
|
puts $(codegenDir "input" "database")
|
||||||
|
|
||||||
backendC <- prompt $ flip elem $ map (return . toLower . head . show) backends
|
backendC <- prompt $ flip elem $ words "s p mysql mongo t"
|
||||||
let (backend, importGenericDB, dbMonad, importPersist, mkPersistSettings) =
|
let (backend, importGenericDB, dbMonad, importPersist, mkPersistSettings) =
|
||||||
case backendC of
|
case backendC of
|
||||||
"s" -> (Sqlite, "GenericSql", "SqlPersist", "Sqlite", "sqlSettings")
|
"s" -> (Sqlite, "GenericSql", "SqlPersist", "Sqlite", "sqlSettings")
|
||||||
"p" -> (Postgresql, "GenericSql", "SqlPersist", "Postgresql", "sqlSettings")
|
"p" -> (Postgresql, "GenericSql", "SqlPersist", "Postgresql", "sqlSettings")
|
||||||
"m" -> (MongoDB, "MongoDB", "Action", "MongoDB", "MkPersistSettings { mpsBackend = ConT ''Action }")
|
"mysql" -> (Mysql, "GenericSql", "SqlPersist", "MySQL", "sqlSettings")
|
||||||
|
"mongo" -> (MongoDB, "MongoDB", "Action", "MongoDB", "MkPersistSettings { mpsBackend = ConT ''Action }")
|
||||||
"t" -> (Tiny, "","","",undefined)
|
"t" -> (Tiny, "","","",undefined)
|
||||||
_ -> error $ "Invalid backend: " ++ backendC
|
_ -> error $ "Invalid backend: " ++ backendC
|
||||||
(modelImports) = case backend of
|
(modelImports) = case backend of
|
||||||
MongoDB -> "import Database.Persist." ++ importGenericDB ++ "\nimport Language.Haskell.TH.Syntax"
|
MongoDB -> "import Database.Persist." ++ importGenericDB ++ "\nimport Language.Haskell.TH.Syntax"
|
||||||
Sqlite -> ""
|
Sqlite -> ""
|
||||||
Postgresql -> ""
|
Postgresql -> ""
|
||||||
|
Mysql -> ""
|
||||||
Tiny -> undefined
|
Tiny -> undefined
|
||||||
|
|
||||||
uncapitalize s = toLower (head s) : tail s
|
uncapitalize s = toLower (head s) : tail s
|
||||||
@ -96,6 +98,7 @@ scaffold = do
|
|||||||
MongoDB -> "mongoDB"
|
MongoDB -> "mongoDB"
|
||||||
Sqlite -> "sqlite"
|
Sqlite -> "sqlite"
|
||||||
Postgresql -> "postgresql"
|
Postgresql -> "postgresql"
|
||||||
|
Mysql -> "mysql"
|
||||||
Tiny -> error "Accessing dbConfigFile for Tiny"
|
Tiny -> error "Accessing dbConfigFile for Tiny"
|
||||||
|
|
||||||
let configPersist =
|
let configPersist =
|
||||||
@ -103,6 +106,7 @@ scaffold = do
|
|||||||
MongoDB -> "MongoConf"
|
MongoDB -> "MongoConf"
|
||||||
Sqlite -> "SqliteConf"
|
Sqlite -> "SqliteConf"
|
||||||
Postgresql -> "PostgresConf"
|
Postgresql -> "PostgresConf"
|
||||||
|
Mysql -> "MySQLConf"
|
||||||
Tiny -> error "Accessing configPersist for Tiny"
|
Tiny -> error "Accessing configPersist for Tiny"
|
||||||
|
|
||||||
putStrLn "That's it! I'm creating your files now..."
|
putStrLn "That's it! I'm creating your files now..."
|
||||||
@ -110,6 +114,7 @@ scaffold = do
|
|||||||
let withConnectionPool = case backend of
|
let withConnectionPool = case backend of
|
||||||
Sqlite -> $(codegen $ "sqliteConnPool")
|
Sqlite -> $(codegen $ "sqliteConnPool")
|
||||||
Postgresql -> $(codegen $ "postgresqlConnPool")
|
Postgresql -> $(codegen $ "postgresqlConnPool")
|
||||||
|
Mysql -> ""
|
||||||
MongoDB -> $(codegen $ "mongoDBConnPool")
|
MongoDB -> $(codegen $ "mongoDBConnPool")
|
||||||
Tiny -> ""
|
Tiny -> ""
|
||||||
|
|
||||||
@ -146,6 +151,7 @@ scaffold = do
|
|||||||
Sqlite -> writeFile' ("config/" ++ backendLower ++ ".yml") $(codegen ("config/sqlite.yml"))
|
Sqlite -> writeFile' ("config/" ++ backendLower ++ ".yml") $(codegen ("config/sqlite.yml"))
|
||||||
Postgresql -> writeFile' ("config/" ++ backendLower ++ ".yml") $(codegen ("config/postgresql.yml"))
|
Postgresql -> writeFile' ("config/" ++ backendLower ++ ".yml") $(codegen ("config/postgresql.yml"))
|
||||||
MongoDB -> writeFile' ("config/" ++ backendLower ++ ".yml") $(codegen ("config/mongoDB.yml"))
|
MongoDB -> writeFile' ("config/" ++ backendLower ++ ".yml") $(codegen ("config/mongoDB.yml"))
|
||||||
|
Mysql -> writeFile' ("config/" ++ backendLower ++ ".yml") $(codegen ("config/mysql.yml"))
|
||||||
Tiny -> return ()
|
Tiny -> return ()
|
||||||
|
|
||||||
let isTiny = backend == Tiny
|
let isTiny = backend == Tiny
|
||||||
|
|||||||
24
yesod/scaffold/config/mysql.yml.cg
Normal file
24
yesod/scaffold/config/mysql.yml.cg
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
Default: &defaults
|
||||||
|
user: ~project~
|
||||||
|
password: ~project~
|
||||||
|
host: localhost
|
||||||
|
port: 3306
|
||||||
|
database: ~project~
|
||||||
|
poolsize: 10
|
||||||
|
|
||||||
|
Development:
|
||||||
|
<<: *defaults
|
||||||
|
|
||||||
|
Test:
|
||||||
|
database: ~project~_test
|
||||||
|
<<: *defaults
|
||||||
|
|
||||||
|
Staging:
|
||||||
|
database: ~project~_staging
|
||||||
|
poolsize: 100
|
||||||
|
<<: *defaults
|
||||||
|
|
||||||
|
Production:
|
||||||
|
database: ~project~_production
|
||||||
|
poolsize: 100
|
||||||
|
<<: *defaults
|
||||||
@ -1,4 +1,4 @@
|
|||||||
Michael
|
Michael
|
||||||
foobar
|
foobar
|
||||||
Foobar
|
Foobar
|
||||||
m
|
mongo
|
||||||
|
|||||||
4
yesod/test/mysql-input.txt
Normal file
4
yesod/test/mysql-input.txt
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
Michael
|
||||||
|
foobar
|
||||||
|
Foobar
|
||||||
|
mysql
|
||||||
@ -51,6 +51,7 @@ extra-source-files:
|
|||||||
scaffold/config/settings.yml.cg
|
scaffold/config/settings.yml.cg
|
||||||
scaffold/config/favicon.ico.cg
|
scaffold/config/favicon.ico.cg
|
||||||
scaffold/config/postgresql.yml.cg
|
scaffold/config/postgresql.yml.cg
|
||||||
|
scaffold/config/mysql.yml.cg
|
||||||
scaffold/config/mongoDB.yml.cg
|
scaffold/config/mongoDB.yml.cg
|
||||||
scaffold/config/routes.cg
|
scaffold/config/routes.cg
|
||||||
scaffold/config/robots.txt.cg
|
scaffold/config/robots.txt.cg
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user