1{-# language ScopedTypeVariables #-}
2{-# language TypeApplications #-}
4module Rel8.Statement.Select
11import Control.Exception ( throwIO )
12import Control.Monad ( (>=>) )
16import Hasql.Connection ( Connection )
17import qualified Hasql.Decoders as Hasql
18import qualified Hasql.Encoders as Hasql
19import qualified Hasql.Session as Hasql
20import qualified Hasql.Statement as Hasql
23import Rel8.Query ( Query )
24import Rel8.Query.SQL ( sqlForQuery, sqlForQueryWithNames )
25import Rel8.Table.Recontextualize ( Selects )
26import Rel8.Table.Serialize ( Serializable, parse )
29import qualified Data.Text as Text
30import Data.Text.Encoding ( encodeUtf8 )
33select :: forall exprs a. Serializable exprs a
34 => Query exprs -> Connection -> IO [a]
35select query = case sqlForQuery query of
36 Nothing -> const $ pure []
37 Just sql -> Hasql.run session >=> 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 => names -> Query exprs -> Connection -> IO [a]
52selectWithNames names query = case sqlForQueryWithNames names query of
53 Nothing -> const $ pure []
54 Just sql -> Hasql.run session >=> 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