CurryInfo: spicey-4.2.0 / Spicey.ControllerGeneration.createTransaction

definition: Info
 
createTransaction :: ControllerGenerator
createTransaction erdname (Entity entityName attrList)
                  relationships allEntities = stCmtFunc
  ("Transaction to persist a new " ++ entityName ++ " entity to the database.")
  (transFunctionName entityName "create")
  1 Private
    (baseType (newEntityTypeName entityName)
      ~> applyTC (dbconn "DBAction") [baseType (model erdname,entityName)])
  [simpleRule 
    [tuplePattern
      (map (\ (param, varId) -> CPVar (varId, param)) 
           (zip (parameterList ++ map lowerFirst manyToOneEntities ++
                 map (\ (e,r) -> lowerFirst r ++ e ++ "s") manyToManyEntities)
                 [1..]))
    ] -- parameter list for controller
    (doExpr $
       CSPat (cpvar "newentity")
         (applyF (entityConstructorFunction erdname
                    (Entity entityName attrList) relationships)
                 (map (\ ((Attribute name dom key null), varId) -> 
                     if (isForeignKey (Attribute name dom key null))
                       then applyF (model erdname,
                              lowerFirst (getReferencedEntityName dom) ++ "Key")
                                   [CVar (varId,
                                       lowerFirst (getReferencedEntityName dom))]
                       else let cv = CVar (varId, lowerFirst name)
                            in if hasDefault dom && not (isStringDom dom)
                                  && not null
                                 then applyF (pre "Just") [cv]
                                 else cv)
                     (zip noPKeys [1..])
                  )) :
       map (\ (en,rel) -> CSExpr $
                          applyF (controllerModuleName entityName, "add" ++ rel)
                                 [cvar (lowerFirst rel ++ en ++ "s"),
                                  cvar "newentity"])
           manyToManyEntities ++
       [CSExpr $ applyF (pre "return") [cvar "newentity"]])
  ]
 where
  noPKeys            = (filter notPKey attrList)
  -- foreignKeys = (filter isForeignKey attrList)
  -- notGeneratedAttributes = filter (\attr -> (not (isForeignKey attr))
  --                                          && (notPKey attr))     attrList
  parameterList      = map (\(Attribute name _ _ _) -> lowerFirst name)
                           (filter (not . isForeignKey) noPKeys)
  manyToManyEntities = manyToMany allEntities (Entity entityName attrList)
  manyToOneEntities  = manyToOne (Entity entityName attrList) relationships
demand: Info
 argument 2
deterministic: Info
 deterministic operation
documentation: Info
 
Generates a transaction to store a new entity.
failfree: Info
 <FAILING>
indeterministic: Info
 referentially transparent operation
infix: Info
 no fixity defined
iotype: Info
 {(_,{Entity},_,_) |-> _}
name: Info
 createTransaction
precedence: Info
 no precedence defined
result-values: Info
 _
signature: Info
 String -> Database.ERD.Entity -> [Database.ERD.Relationship]
-> [Database.ERD.Entity] -> AbstractCurry.Types.CFuncDecl
solution-complete: Info
 operation might suspend on free variables
terminating: Info
 possibly non-terminating
totally-defined: Info
 possibly non-reducible on same data term