module Database.PostgreSQL.Simple.Vector.Unboxed where
import Database.PostgreSQL.Simple (Connection, formatQuery, formatMany)
import Database.PostgreSQL.Simple.FromRow (FromRow(..))
import Database.PostgreSQL.Simple.ToRow (ToRow(..))
import Database.PostgreSQL.Simple.Internal (RowParser, exec)
import Database.PostgreSQL.Simple.Internal.PQResultUtils
import Database.PostgreSQL.Simple.Types ( Query (..) )
import qualified Data.Vector.Unboxed as VU
query :: (ToRow q, FromRow r, VU.Unbox r) => Connection -> Query -> q -> IO (VU.Vector r)
query = queryWith fromRow
query_ :: (FromRow r, VU.Unbox r) => Connection -> Query -> IO (VU.Vector r)
query_ = queryWith_ fromRow
queryWith :: (ToRow q, VU.Unbox r) => RowParser r -> Connection -> Query -> q -> IO (VU.Vector r)
queryWith parser conn template qs = do
result <- exec conn =<< formatQuery conn template qs
finishQueryWithVU parser conn template result
queryWith_ :: VU.Unbox r => RowParser r -> Connection -> Query -> IO (VU.Vector r)
queryWith_ parser conn q@(Query que) = do
result <- exec conn que
finishQueryWithVU parser conn q result
returning :: (ToRow q, FromRow r, VU.Unbox r) => Connection -> Query -> [q] -> IO (VU.Vector r)
returning = returningWith fromRow
returningWith :: (ToRow q, VU.Unbox r) => RowParser r -> Connection -> Query -> [q] -> IO (VU.Vector r)
returningWith _ _ _ [] = return VU.empty
returningWith parser conn q qs = do
result <- exec conn =<< formatMany conn q qs
finishQueryWithVU parser conn q result