1{-# language ScopedTypeVariables #-}
2{-# language TypeApplications #-}
4module Rel8.Statement.Select
11import Control.Exception ( throwIO )
15import Hasql.Connection ( Connection )
16import qualified Hasql.Decoders as Hasql
17import qualified Hasql.Encoders as Hasql
18import qualified Hasql.Session as Hasql
19import qualified Hasql.Statement as Hasql
22import Rel8.Query ( Query )
23import Rel8.Query.SQL ( sqlForQuery, sqlForQueryWithNames )
24import Rel8.Schema.Name ( Selects )
25import Rel8.Table.Serialize ( Serializable, parse )
28import qualified Data.Text as Text
29import Data.Text.Encoding ( encodeUtf8 )
32-- | Run a @SELECT@ query, returning all rows.
33select :: forall exprs a. Serializable exprs a
34 => Connection -> Query exprs -> IO [a]
35select c query = case sqlForQuery query of
37 Just sql -> Hasql.run session c >>= either throwIO pure
39 session = Hasql.statement () statement
40 statement = Hasql.Statement bytes params decode prepare
41 bytes = encodeUtf8 (Text.pack sql)
42 params = Hasql.noParams
43 decode = Hasql.rowList (parse @exprs @a)
47selectWithNames :: forall exprs a names.
49 , Serializable exprs a
51 => Connection -> names -> Query exprs -> IO [a]
52selectWithNames c names query = case sqlForQueryWithNames names query of
54 Just sql -> Hasql.run session c >>= either throwIO pure
56 session = Hasql.statement () statement
57 statement = Hasql.Statement bytes params decode prepare
58 bytes = encodeUtf8 (Text.pack sql)
59 params = Hasql.noParams
60 decode = Hasql.rowList (parse @exprs @a)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list