MySQL scaffolding support (#247)

This commit is contained in:
Michael Snoyman 2012-01-31 07:16:14 +02:00
parent 8155a5c45b
commit d10912cf0f
5 changed files with 39 additions and 4 deletions

View File

@ -32,7 +32,7 @@ qq = ""
qq = "$"
#endif
data Backend = Sqlite | Postgresql | MongoDB | Tiny
data Backend = Sqlite | Postgresql | Mysql | MongoDB | Tiny
deriving (Eq, Read, Show, Enum, Bounded)
puts :: String -> IO ()
@ -63,18 +63,20 @@ scaffold = do
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) =
case backendC of
"s" -> (Sqlite, "GenericSql", "SqlPersist", "Sqlite", "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)
_ -> error $ "Invalid backend: " ++ backendC
(modelImports) = case backend of
MongoDB -> "import Database.Persist." ++ importGenericDB ++ "\nimport Language.Haskell.TH.Syntax"
Sqlite -> ""
Postgresql -> ""
Mysql -> ""
Tiny -> undefined
uncapitalize s = toLower (head s) : tail s
@ -96,6 +98,7 @@ scaffold = do
MongoDB -> "mongoDB"
Sqlite -> "sqlite"
Postgresql -> "postgresql"
Mysql -> "mysql"
Tiny -> error "Accessing dbConfigFile for Tiny"
let configPersist =
@ -103,6 +106,7 @@ scaffold = do
MongoDB -> "MongoConf"
Sqlite -> "SqliteConf"
Postgresql -> "PostgresConf"
Mysql -> "MySQLConf"
Tiny -> error "Accessing configPersist for Tiny"
putStrLn "That's it! I'm creating your files now..."
@ -110,6 +114,7 @@ scaffold = do
let withConnectionPool = case backend of
Sqlite -> $(codegen $ "sqliteConnPool")
Postgresql -> $(codegen $ "postgresqlConnPool")
Mysql -> ""
MongoDB -> $(codegen $ "mongoDBConnPool")
Tiny -> ""
@ -146,6 +151,7 @@ scaffold = do
Sqlite -> writeFile' ("config/" ++ backendLower ++ ".yml") $(codegen ("config/sqlite.yml"))
Postgresql -> writeFile' ("config/" ++ backendLower ++ ".yml") $(codegen ("config/postgresql.yml"))
MongoDB -> writeFile' ("config/" ++ backendLower ++ ".yml") $(codegen ("config/mongoDB.yml"))
Mysql -> writeFile' ("config/" ++ backendLower ++ ".yml") $(codegen ("config/mysql.yml"))
Tiny -> return ()
let isTiny = backend == Tiny

View 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

View File

@ -1,4 +1,4 @@
Michael
foobar
Foobar
m
mongo

View File

@ -0,0 +1,4 @@
Michael
foobar
Foobar
mysql

View File

@ -51,6 +51,7 @@ extra-source-files:
scaffold/config/settings.yml.cg
scaffold/config/favicon.ico.cg
scaffold/config/postgresql.yml.cg
scaffold/config/mysql.yml.cg
scaffold/config/mongoDB.yml.cg
scaffold/config/routes.cg
scaffold/config/robots.txt.cg