@@ -21,9 +21,11 @@ import Data.Monoid
21import Data.Proxy
21import Data.Proxy
22import Data.String
22import Data.String
23import Data.Vinyl
23import Data.Vinyl
24+import Data.Vinyl.Functor
24import GHC.OverloadedLabels
25import GHC.OverloadedLabels
25import GHC.TypeLits
26import GHC.TypeLits
28+import qualified Data.ByteString as ByteString
27import qualified Data.ByteString.Char8 as Char8
29import qualified Data.ByteString.Char8 as Char8
29import Squeel.PostgreSQL.Type
31import Squeel.PostgreSQL.Type
@@ -33,7 +35,7 @@ class HasField label xs x where
33instance {-# OVERLAPPING #-} KnownSymbol label
35instance {-# OVERLAPPING #-} KnownSymbol label
34 => HasField label ('(label, x) ': xs) x where
36 => HasField label ('(label, x) ': xs) x where
35 fieldName _ _ _ = Char8.pack (symbolVal (Proxy @label))
37 fieldName _ _ _ = Char8.pack (symbolVal (Proxy @label))
36−instance HasField label xs y
38+instance {-# OVERLAPPABLE #-} HasField label xs y
37 => HasField label (x ': xs) y where
39 => HasField label (x ': xs) y where
38 fieldName _ _ _ = fieldName (Proxy @label) (Proxy @xs) (Proxy @y)
40 fieldName _ _ _ = fieldName (Proxy @label) (Proxy @xs) (Proxy @y)
@@ -232,9 +234,28 @@ subselect selection = Relation
232 , offsetting = Nothing
234 , offsetting = Nothing
237+newtype Insertion ps xss = UnsafeInsertion {renderInsertion :: ByteString }
240+ :: forall label xss xs ps
241+ . HasField label xss xs
243+ -> Rec (Aliased (Expression ps '[])) xs
245+into table values = UnsafeInsertion $ "INTO "
246+ <> fieldName table (Proxy @xss) (Proxy @xs)
248+ <> ByteString.intercalate ", "
249+ (recordToList (rmap (Const . renderExpression . unalias) values))
235newtype Query ps xss yss zs = UnsafeQuery { renderQuery :: ByteString }
251newtype Query ps xss yss zs = UnsafeQuery { renderQuery :: ByteString }
236newtype PreparedQuery ps xss yss zs =
252newtype PreparedQuery ps xss yss zs =
237 UnsafePreparedQuery { renderPreparedQuery :: ByteString }
253 UnsafePreparedQuery { renderPreparedQuery :: ByteString }
239select :: Selection ps xss ys -> Query ps xss xss ys
255select :: Selection ps xss ys -> Query ps xss xss ys
256+select selection = UnsafeQuery $
240−select selection = UnsafeQuery $ "SELECT " <> renderSelection selection <> ";"
257+ "SELECT " <> renderSelection selection <> ";"
259+insert :: Insertion ps xss -> Query ps xss xss '[]
260+insert insertion = UnsafeQuery $
261+ "INSERT " <> renderInsertion insertion <> ";"