Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Never ending cleanup not ending...

  • Loading branch information...
commit 6ac94d0ef7e6a360855ccff39803ff72a9295263 1 parent 1a1e99e
@alsonkemp alsonkemp authored
View
10 Turbinado/Database/ORM/Output.hs
@@ -105,7 +105,7 @@ generateModelBase = unlines $
,""
,"class (DatabaseModel model) =>"
," IsModel model where"
- ," insert :: (HasEnvironment m) => model -> m Integer"
+ ," insert :: (HasEnvironment m) => model -> Bool -> m (Maybe Integer)"
," findAll :: (HasEnvironment m) => m [model]"
," findAllWhere :: (HasEnvironment m) => SelectString -> SelectParams -> m [model]"
," findAllOrderBy :: (HasEnvironment m) => OrderByParams -> m [model]"
@@ -128,13 +128,15 @@ generateModelBase = unlines $
generateIsModel :: TableName -> Columns -> TypeName -> [String]
generateIsModel t cs typeName =
["instance IsModel " ++ typeName ++ " where"
- ," insert m = do"
+ ," insert m returnId = do"
," conn <- getEnvironment >>= (return . fromJust . getDatabase )"
," res <- liftIO $ HDBC.handleSqlError $ HDBC.run conn \" INSERT INTO " ++ t ++ " (" ++ (concat $ intersperse "," $ M.keys cs) ++") VALUES (" ++ (intercalate "," (take (M.size cs) (repeat "?"))) ++ ")\""
," [" ++ (unwords $ intersperse "," $ map (\c -> "HDBC.toSql $ " ++ partiallyCapitalizeName c ++ " m") (M.keys cs) ) ++ "]"
," liftIO $ HDBC.handleSqlError $ HDBC.commit conn"
- ," i <- liftIO $ HDBC.catchSql (HDBC.handleSqlError $ HDBC.quickQuery' conn \"SELECT lastval()\" []) (\\_ -> HDBC.commit conn >> (return $ [[HDBC.toSql (0 :: Int)]]) ) "
- ," return $ HDBC.fromSql $ head $ head i"
+ ," if returnId"
+ ," then do i <- liftIO $ HDBC.catchSql (HDBC.handleSqlError $ HDBC.quickQuery' conn \"SELECT lastval()\" []) (\\_ -> HDBC.commit conn >> (return $ [[HDBC.toSql (0 :: Int)]]) ) "
+ ," return $ HDBC.fromSql $ head $ head i"
+ ," else return Nothing"
," findAll = do"
," conn <- getEnvironment >>= (return . fromJust . getDatabase )"
," res <- liftIO $ HDBC.handleSqlError $ HDBC.quickQuery' conn \"SELECT " ++ cols cs ++ " FROM " ++ t ++ "\" []"
View
13 Turbinado/Layout.hs
@@ -1,8 +1,8 @@
module Turbinado.Layout (
- insertView,
styleSheet,
javaScript,
- googleAnalytics
+ googleAnalytics,
+ module Turbinado.View
) where
import Control.Monad.State
import Control.Monad.Trans
@@ -14,15 +14,6 @@ import Turbinado.Environment.Logger
import Turbinado.Environment.Settings
import Turbinado.View
-insertView :: View XML
-insertView = do cl <- getView
- debugM $ " Layout: insertView : loading " ++ (fst cl) ++ " - " ++ (snd cl)
- c <- retrieveCode CTView cl
- case c of
- CodeLoadView v _ _ -> v
- CodeLoadController _ _ _ -> error "retrieveAndRunLayout called, but returned CodeLoadController"
- CodeLoadFailure e -> return $ cdata e
-
styleSheet :: String -> String -> View XML
styleSheet s m = return $ cdata $ "<link media=\"" ++ m ++"\" type=\"text/css\" rel=\"stylesheet\" href=\"/css/" ++ s ++".css\">"
View
2  Turbinado/View.hs
@@ -6,6 +6,8 @@ module Turbinado.View (
runView, runViewT,
-- * Functions
liftIO, catch,
+ insertView,
+ insertDefaultView,
insertComponent,
-- Module Exports
Please sign in to comment.
Something went wrong with that request. Please try again.