1{-# language MonoLocalBinds #-}
2{-# language ScopedTypeVariables #-}
3{-# language TypeApplications #-}
5module Rel8.Statement.Select
12import Control.Exception ( throwIO )
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.Schema.Name ( Selects )
26import Rel8.Table.Serialize ( Serializable, parse )
29import qualified Data.Text as Text
30import Data.Text.Encoding ( encodeUtf8 )
33-- | Run a @SELECT@ query, returning all rows.
34select :: forall exprs a. Serializable exprs a
35 => Connection -> Query exprs -> IO [a]
36select c query = case sqlForQuery query of
38 Just sql -> Hasql.run session c >>= either throwIO pure
40 session = Hasql.statement () statement
41 statement = Hasql.Statement bytes params decode prepare
42 bytes = encodeUtf8 (Text.pack sql)
43 params = Hasql.noParams
44 decode = Hasql.rowList (parse @exprs @a)
48selectWithNames :: forall exprs a names.
50 , Serializable exprs a
52 => Connection -> names -> Query exprs -> IO [a]
53selectWithNames c names query = case sqlForQueryWithNames names query of
55 Just sql -> Hasql.run session c >>= either throwIO pure
57 session = Hasql.statement () statement
58 statement = Hasql.Statement bytes params decode prepare
59 bytes = encodeUtf8 (Text.pack sql)
60 params = Hasql.noParams
61 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