1{-# language FlexibleContexts #-}
2{-# language MonoLocalBinds #-}
4module Rel8.Statement.View
13import qualified Hasql.Decoders as Hasql
14import qualified Hasql.Encoders as Hasql
15import qualified Hasql.Statement as Hasql
18import Rel8.Query ( Query )
19import Rel8.Schema.Name ( Selects )
20import Rel8.Schema.Table ( TableSchema )
21import Rel8.Statement.Insert ( ppInto )
22import Rel8.Statement.Select ( ppSelect )
25import Text.PrettyPrint ( Doc, (<+>), ($$), text )
28import qualified Data.Text as Text
29import Data.Text.Encoding ( encodeUtf8 )
32-- | Given a 'TableSchema' and 'Query', @createView@ runs a @CREATE VIEW@
33-- statement that will save the given query as a view. This can be useful if
34-- you want to share Rel8 queries with other applications.
35createView :: Selects names exprs
36 => TableSchema names -> Query exprs -> Hasql.Statement () ()
37createView schema query = Hasql.Statement bytes params decode prepare
39 bytes = encodeUtf8 (Text.pack sql)
40 params = Hasql.noParams
41 decode = Hasql.noResult
44 doc = ppCreateView schema query
47ppCreateView :: Selects names exprs
48 => TableSchema names -> Query exprs -> Doc
49ppCreateView schema query =
50 text "CREATE VIEW" <+>
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