@@ -20,8 +20,7 @@ import Data.ByteString (ByteString)
20import Data.Maybe
20import Data.Maybe
21import Data.Monoid
21import Data.Monoid
22import Data.String
22import Data.String
23−import Data.Vinyl
23+import Generics.SOP
24−import Data.Vinyl.Functor
25import GHC.Exts
24import GHC.Exts
26import GHC.OverloadedLabels
25import GHC.OverloadedLabels
27import GHC.TypeLits
26import GHC.TypeLits
@@ -117,8 +116,8 @@ unsafeFunction
117 :: ByteString
116 :: ByteString
118 -> Expression params tables xty
117 -> Expression params tables xty
119 -> Expression params tables yty
118 -> Expression params tables yty
120−unsafeFunction fn x = UnsafeExpression $ mconcat
119+unsafeFunction fun x = UnsafeExpression $ mconcat
121− [fn, "(", renderExpression x, ")"]
120+ [fun, "(", renderExpression x, ")"]
123instance PGNum ty => Num (Expression params tables ('Required (nullity ty))) where
122instance PGNum ty => Num (Expression params tables ('Required (nullity ty))) where
124 (+) = unsafeBinaryOp "+"
123 (+) = unsafeBinaryOp "+"
@@ -407,7 +406,8 @@ Alias tab `dotStarFrom` tabs = UnsafeSelection $
407 fromString (symbolVal' tab) <> ".* FROM " <> renderFrom tabs
406 fromString (symbolVal' tab) <> ".* FROM " <> renderFrom tabs
410− :: Rec (Aliased (Expression params tables)) columns
410+ => NP (Aliased (Expression params tables)) columns
411 -> From params schema tables
411 -> From params schema tables
412 -> Selection params schema columns
412 -> Selection params schema columns
413list `from` tabs = UnsafeSelection $
413list `from` tabs = UnsafeSelection $
@@ -415,8 +415,8 @@ list `from` tabs = UnsafeSelection $
416 renderList
416 renderList
417 = ByteString.intercalate ", "
417 = ByteString.intercalate ", "
418− . recordToList
418+ . hcollapse
419− . rmap (Const . renderAliased renderExpression)
419+ . hmap (K . renderAliased renderExpression)
422 :: Selection params schema columns
422 :: Selection params schema columns
@@ -436,9 +436,9 @@ INSERT statements
436-----------------------------------------}
436-----------------------------------------}
438insertInto
438insertInto
439− :: HasTable table schema columns
439+ :: (SListI columns, HasTable table schema columns)
440 => Alias table
440 => Alias table
441− -> Rec (Aliased (Expression params '[])) columns
441+ -> NP (Aliased (Expression params '[])) columns
442 -> Statement params '[] schema schema
442 -> Statement params '[] schema schema
443insertInto (Alias table) expressions = UnsafeStatement $ "INSERT INTO "
443insertInto (Alias table) expressions = UnsafeStatement $ "INSERT INTO "
444 <> fromString (symbolVal' table)
444 <> fromString (symbolVal' table)
@@ -447,11 +447,11 @@ insertInto (Alias table) expressions = UnsafeStatement $ "INSERT INTO "
447 <> ByteString.intercalate ", " values
447 <> ByteString.intercalate ", " values
450− aliases = recordToList $ rmap
450+ aliases = hcollapse $ hmap
451− (\ (_ `As` Alias name) -> Const (fromString (symbolVal' name)))
451+ (\ (_ `As` Alias name) -> K (fromString (symbolVal' name)))
452 expressions
452 expressions
453− values = recordToList $ rmap
453+ values = hcollapse $ hmap
454− (\ (expression `As` _) -> Const (renderExpression expression))
454+ (\ (expression `As` _) -> K (renderExpression expression))
455 expressions
455 expressions
457{-----------------------------------------
457{-----------------------------------------
@@ -486,16 +486,16 @@ serial :: TypeExpression ('Optional ('NotNull 'PGInt4))
486serial = UnsafeTypeExpression "serial"
486serial = UnsafeTypeExpression "serial"
488createTable
488createTable
489− :: KnownSymbol table
489+ :: (KnownSymbol table, SListI columns)
490 => Alias table
490 => Alias table
491− -> Rec (Aliased TypeExpression) columns
491+ -> NP (Aliased TypeExpression) columns
492 -> Statement '[] '[] schema ((table ::: columns) ': schema)
492 -> Statement '[] '[] schema ((table ::: columns) ': schema)
493createTable (Alias table) columns = UnsafeStatement $ mconcat
493createTable (Alias table) columns = UnsafeStatement $ mconcat
494 [ "CREATE TABLE "
494 [ "CREATE TABLE "
495 , fromString $ symbolVal' table
495 , fromString $ symbolVal' table
497− , ByteString.intercalate ", " . recordToList $
497+ , ByteString.intercalate ", " . hcollapse $
498− rmap (Const . renderColumn) columns
498+ hmap (K . renderColumn) columns
@@ -523,33 +523,33 @@ instance {-# OVERLAPPABLE #-}
523UPDATE statements
523UPDATE statements
524-----------------------------------------}
524-----------------------------------------}
526−set :: g x -> (Maybe `Compose` g) x
526+set :: g x -> (Maybe :.: g) x
527−set = Compose . Just
527+set = Comp . Just
529−same :: (Maybe `Compose` g) x
529+same :: (Maybe :.: g) x
530−same = Compose Nothing
530+same = Comp Nothing
533− :: HasTable table schema columns
533+ :: (HasTable table schema columns, SListI columns)
534 => Alias table
534 => Alias table
535− -> Rec (Aliased (Maybe `Compose` Expression params '[table ::: columns])) columns
535+ -> NP (Aliased (Maybe :.: Expression params '[table ::: columns])) columns
536 -> Expression params '[table ::: columns] ('Required ('NotNull 'PGBool))
536 -> Expression params '[table ::: columns] ('Required ('NotNull 'PGBool))
537 -> Statement params '[] schema schema
537 -> Statement params '[] schema schema
538update (Alias table) columns where' = UnsafeStatement $ mconcat
538update (Alias table) columns where' = UnsafeStatement $ mconcat
539 [ "UPDATE "
539 [ "UPDATE "
540 , fromString $ symbolVal' table
540 , fromString $ symbolVal' table
541 , " SET "
541 , " SET "
542− , ByteString.intercalate ", " . catMaybes . recordToList $
542+ , ByteString.intercalate ", " . catMaybes . hcollapse $
543− rmap (Const . renderSet) columns
543+ hmap (K . renderSet) columns
544 , " WHERE ", renderExpression where'
544 , " WHERE ", renderExpression where'
546 renderSet
546 renderSet
547− :: Aliased (Maybe `Compose` Expression params tables) column
547+ :: Aliased (Maybe :.: Expression params tables) column
548 -> Maybe ByteString
548 -> Maybe ByteString
549 renderSet = \case
549 renderSet = \case
550− Compose (Just expression) `As` Alias column -> Just $ mconcat
550+ Comp (Just expression) `As` Alias column -> Just $ mconcat
551 [ fromString $ symbolVal' column
551 [ fromString $ symbolVal' column
553 , renderExpression expression
553 , renderExpression expression
555− Compose Nothing `As` _ -> Nothing
555+ Comp Nothing `As` _ -> Nothing