on dev help sign in
factor out renderSet
commitca368347661ae4e3d90659744c5d23f2a07e22a7 authorEitan Chatav <eitan.chatav@gmail.com> dateTue 18 Jul 2017, 18:30 (9 years ago) parent9cc9139
1 file changed+12−21
squeel-postgresql/src/Squeel/PostgreSQL/Statement.hs+12−21
squeel-postgresql/src/Squeel/PostgreSQL/Statement.hs+12−21
@@ -783,6 +783,17 @@ set = Comp . Just
783783same :: (Maybe :.: Expression params tables) x
784784same = Comp Nothing
785785
786+renderSet
787+ :: Aliased (Maybe :.: Expression params '[table ::: columns]) column
788+ -> Maybe ByteString
789+renderSet = \case
790+ Comp (Just expression) `As` Alias column -> Just $ mconcat
791+ [ fromString $ symbolVal' column
792+ , " = "
793+ , renderExpression expression
794+ ]
795+ Comp Nothing `As` _ -> Nothing
796+
786797update
787798 :: (HasTable table schema columns, SListI columns)
788799 => Alias table
@@ -796,17 +807,7 @@ update (Alias table) columns wh = UnsafeStatement $ mconcat
796807 , ByteString.intercalate ", " . catMaybes . hcollapse $
797808 hmap (K . renderSet) columns
798809 , " WHERE ", renderExpression wh, ";"
799− ] where
800− renderSet
801− :: Aliased (Maybe :.: Expression params tables) column
802− -> Maybe ByteString
803− renderSet = \case
804− Comp (Just expression) `As` Alias column -> Just $ mconcat
805− [ fromString $ symbolVal' column
806− , " = "
807− , renderExpression expression
808− ]
809− Comp Nothing `As` _ -> Nothing
810+ ]
810811
811812upsertInto
812813 :: (SListI columns, HasTable table schema columns)
@@ -828,16 +829,6 @@ upsertInto (Alias table) inserts updates wh = UnsafeStatement . mconcat $
828829 hmap (K . renderSet) updates
829830 , " WHERE ", renderExpression wh, ";"
830831 ] where
831− renderSet
832− :: Aliased (Maybe :.: Expression params '[table ::: columns]) column
833− -> Maybe ByteString
834− renderSet = \case
835− Comp (Just expression) `As` Alias column -> Just $ mconcat
836− [ fromString $ symbolVal' column
837− , " = "
838− , renderExpression expression
839− ]
840− Comp Nothing `As` _ -> Nothing
841832 aliases = hcollapse $ hmap
842833 (\ (_ `As` Alias name) -> K (fromString (symbolVal' name)))
843834 inserts