on master help sign in
add toDefineExpr to Tupleable to cut down on boilerplate rv creation
commit83d8a04c4e2cf712b8d758537814255874c4fb69 authorAgentM <agentm@themactionfaction.com> dateSat 26 Aug 2017, 07:20 (9 years ago) parent83f8002
1 file changed+8
src/lib/ProjectM36/Tupleable.hs+8
src/lib/ProjectM36/Tupleable.hs+8
@@ -42,6 +42,14 @@ toInsertExpr vals rvName = do
4242 tuples <- mkTupleSet attrs $ toList (fmap toTuple vals)
4343 let rel = MakeStaticRelation attrs tuples
4444 pure (Insert rvName rel)
45+
46+-- | Convert a 'Tupleable' to a create a 'Define' expression which can be used to create an empty relation variable. Use 'toInsertExpr' to insert the actual tuple data. This function is typically used with 'undefined'.
47+toDefineExpr :: Tupleable a => a -> RelVarName -> DatabaseContextExpr
48+toDefineExpr val rvName = Define rvName (map NakedAttributeExpr (V.toList attrs))
49+ where
50+ attrs = toAttributes val
51+
52+
4553
4654class Tupleable a where
4755 toTuple :: a -> RelationTuple