-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Simple storage interface to PostgreSQL -- -- Simple storage interface to PostgreSQL @package pg-store @version 0.4.0 module Database.PostgreSQL.Store.Tuple -- | Generic product type data Tuple (ts :: [Type]) [Empty] :: Tuple '[] [Cons] :: t -> !(Tuple ts) -> Tuple (t : ts) appendElement :: AppendElement ts => Tuple ts -> t -> Tuple (ts |> t) -- | Helper class to extract an element from a Tuple. class HasElement (n :: Nat) (ts :: [Type]) r | n ts -> r -- | Extract the n-th element from the product. getElementN :: HasElement n ts r => Tuple ts -> Tagged n r -- | Extract the n-th element from the product. getElementN :: HasElement n ts r => Tuple ts -> Tagged n r -- | Extract element at index 0. getElement0 :: Tuple (r : ts) -> r -- | Extract element at index 1. getElement1 :: Tuple (t0 : (r : ts)) -> r -- | Extract element at index 2. getElement2 :: Tuple (t0 : (t1 : (r : ts))) -> r -- | Extract element at index 3. getElement3 :: Tuple (t0 : (t1 : (t2 : (r : ts)))) -> r -- | Extract element at index 4. getElement4 :: Tuple (t0 : (t1 : (t2 : (t3 : (r : ts))))) -> r -- | Extract element at index 5. getElement5 :: Tuple (t0 : (t1 : (t2 : (t3 : (t4 : (r : ts)))))) -> r -- | Extract element at index 6. getElement6 :: Tuple (t0 : (t1 : (t2 : (t3 : (t4 : (t5 : (r : ts))))))) -> r -- | Extract element at index 7. getElement7 :: Tuple (t0 : (t1 : (t2 : (t3 : (t4 : (t5 : (t6 : (r : ts)))))))) -> r -- | Extract element at index 8. getElement8 :: Tuple (t0 : (t1 : (t2 : (t3 : (t4 : (t5 : (t6 : (t7 : (r : ts))))))))) -> r -- | Extract element at index 9. getElement9 :: Tuple (t0 : (t1 : (t2 : (t3 : (t4 : (t5 : (t6 : (t7 : (t8 : (r : ts)))))))))) -> r -- | Build a function type using the given parameter types and return type. -- | A value of type r can be created using an instance of -- Tuple ts. type WithTuple ts r = ConsTuple '[] (Tuple ts -> r) (FunctionType ts r) -- | Collect values to construct a Tuple ts, then apply the given -- function to it. withTuple :: (WithTuple ts r) => (Tuple ts -> r) -> FunctionType ts r instance Database.PostgreSQL.Store.Tuple.ShowElement '[] instance (GHC.Show.Show t, Database.PostgreSQL.Store.Tuple.ShowElement ts) => Database.PostgreSQL.Store.Tuple.ShowElement (t : ts) instance Database.PostgreSQL.Store.Tuple.ShowElement ts => GHC.Show.Show (Database.PostgreSQL.Store.Tuple.Tuple ts) instance Database.PostgreSQL.Store.Tuple.HasElement 0 (t : ts) t instance (1 GHC.TypeLits.<= n, Database.PostgreSQL.Store.Tuple.HasElement (n GHC.TypeLits.- 1) ts r) => Database.PostgreSQL.Store.Tuple.HasElement n (t : ts) r instance Database.PostgreSQL.Store.Tuple.AppendElement '[] instance Database.PostgreSQL.Store.Tuple.AppendElement ts => Database.PostgreSQL.Store.Tuple.AppendElement (t : ts) instance Database.PostgreSQL.Store.Tuple.ConsTuple ts (Database.PostgreSQL.Store.Tuple.Tuple ts -> r) r instance (Database.PostgreSQL.Store.Tuple.AppendElement ts, Database.PostgreSQL.Store.Tuple.ConsTuple (ts Database.PostgreSQL.Store.Tuple.|> t) a r) => Database.PostgreSQL.Store.Tuple.ConsTuple ts a (t -> r) module Database.PostgreSQL.Store.Types -- | SQL statement newtype Statement a Statement :: ByteString -> Statement a -- | Query object data Query a Query :: ByteString -> [Maybe (Oid, ByteString, Format)] -> Query a -- | SQL statement [queryStatement] :: Query a -> ByteString -- | Parameters [queryParams] :: Query a -> [Maybe (Oid, ByteString, Format)] -- | Preparable query object data PrepQuery ts a PrepQuery :: ByteString -> ByteString -> [Oid] -> (Tuple ts -> [Maybe (ByteString, Format)]) -> PrepQuery ts a -- | Name of the prepared statement [prepName] :: PrepQuery ts a -> ByteString -- | SQL statement [prepStatement] :: PrepQuery ts a -> ByteString -- | Parameter type hints [prepOids] :: PrepQuery ts a -> [Oid] -- | Parameter generator [prepParams] :: PrepQuery ts a -> Tuple ts -> [Maybe (ByteString, Format)] -- | Attach Text tag. toParam :: ByteString -> (ByteString, Format) -- | Attach Text tag. toTypedParam :: Oid -> ByteString -> (Oid, ByteString, Format) newtype Oid :: * Oid :: CUInt -> Oid data Format :: * instance GHC.Show.Show (Database.PostgreSQL.Store.Types.PrepQuery ts a) instance GHC.Classes.Ord (Database.PostgreSQL.Store.Types.Query a) instance GHC.Classes.Eq (Database.PostgreSQL.Store.Types.Query a) instance GHC.Show.Show (Database.PostgreSQL.Store.Types.Query a) instance GHC.Classes.Ord (Database.PostgreSQL.Store.Types.Statement a) instance GHC.Classes.Eq (Database.PostgreSQL.Store.Types.Statement a) instance GHC.Show.Show (Database.PostgreSQL.Store.Types.Statement a) module Database.PostgreSQL.Store.RowParser -- | Consumes w columns of a result set row in order to produce an -- instance of a. data RowParser (w :: Nat) a -- | Location of an error data RowErrorLocation RowErrorLocation :: Column -> Row -> RowErrorLocation -- | Errors that occur during row parsing data RowErrorDetail -- | Underlying RowParser wants more columns than are currently -- present. TooFewColumns :: RowErrorDetail -- | A column value could not be parsed. ColumnRejected :: RowErrorDetail -- | An error that occured when parsing a row data RowError RowError :: RowErrorLocation -> RowErrorDetail -> RowError -- | Process the each row of the Result with the given -- RowParser. processResultWith :: forall a n. (KnownNat n) => Result -> RowParser n a -> ExceptT RowError IO [a] -- | Transform the result of another RowParser. Similar to monadic -- bind. Also keeps track of how many columns are needed in total. (>>=$) :: forall a v b w. (KnownNat v) => RowParser v a -> (a -> RowParser w b) -> RowParser (v + w) b infixl 1 >>=$ -- | Chain two RowParsers, but discard the result of the first. (>>$) :: forall a v b w. (KnownNat v) => RowParser v a -> RowParser w b -> RowParser (v + w) b infixl 1 >>$ -- | Just like the '(*)' operator. (<*>$) :: forall a v b w. (KnownNat v) => RowParser v (a -> b) -> RowParser w a -> RowParser (v + w) b infixl 4 <*>$ -- | Terminate the parsing tree by returning the final result. finish :: a -> RowParser 0 a -- | Terminate the parsing tree with an error. cancel :: RowErrorDetail -> RowParser 0 a -- | Skip a number of columns. skipColumns :: RowParser n () -- | Check if the following n columns are not NULL. nonNullCheck :: Int -> RowParser 0 Bool -- | Process the contents of a column. processContent :: (Oid -> Maybe ByteString -> Maybe a) -> RowParser 1 a -- | Retrieve a column's type and content. retrieveColumn :: RowParser 1 (Oid, Maybe ByteString) -- | Retrieve a column's content. retrieveContent :: RowParser 1 ByteString instance GHC.Classes.Ord Database.PostgreSQL.Store.RowParser.RowError instance GHC.Classes.Eq Database.PostgreSQL.Store.RowParser.RowError instance GHC.Show.Show Database.PostgreSQL.Store.RowParser.RowError instance GHC.Classes.Ord Database.PostgreSQL.Store.RowParser.RowErrorDetail instance GHC.Classes.Eq Database.PostgreSQL.Store.RowParser.RowErrorDetail instance GHC.Show.Show Database.PostgreSQL.Store.RowParser.RowErrorDetail instance GHC.Classes.Ord Database.PostgreSQL.Store.RowParser.RowErrorLocation instance GHC.Classes.Eq Database.PostgreSQL.Store.RowParser.RowErrorLocation instance GHC.Show.Show Database.PostgreSQL.Store.RowParser.RowErrorLocation instance GHC.Base.Functor (Database.PostgreSQL.Store.RowParser.RowParser w) module Database.PostgreSQL.Store.Query.Builder -- | Generator for queries, its type parameter hints the type needed to -- generate the attached values data QueryGenerator a Gen :: Oid -> (a -> Maybe ByteString) -> QueryGenerator a Code :: ByteString -> QueryGenerator a With :: (a -> b) -> (QueryGenerator b) -> QueryGenerator a Merge :: (QueryGenerator a) -> (QueryGenerator a) -> QueryGenerator a -- | Assemble the query object. assemble :: QueryGenerator a -> a -> Query r -- | Assemble for query preparation. assemblePrep :: ByteString -> QueryGenerator (Tuple p) -> PrepQuery p r -- | Embed a generator which requires an external parameter. withOther :: a -> QueryGenerator a -> QueryGenerator b -- | Insert an identifying name. Takes care of proper quotation. genIdentifier :: ByteString -> QueryGenerator a -- | Connect two identifiers with a dot. Each identifier is surrounded by -- quotes if necessary. genNestedIdentifier :: ByteString -> ByteString -> QueryGenerator a -- | Surround with quotes and escape delimiting characters. genQuote :: ByteString -> QueryGenerator a -- | Join multiple query generators with a piece of code. joinGens :: ByteString -> [QueryGenerator a] -> QueryGenerator a -- | Redirect the n-th parameter for the given query withParamN :: forall n r ts. (HasElement n ts r) => QueryGenerator r -> Tagged n (QueryGenerator (Tuple ts)) -- | Redirect the 0th paramter to the given query generator. withParam0 :: QueryGenerator r -> QueryGenerator (Tuple (r : ts)) -- | Redirect the 1st paramter to the given query generator. withParam1 :: QueryGenerator r -> QueryGenerator (Tuple (t0 : (r : ts))) -- | Redirect the 2nd paramter to the given query generator. withParam2 :: QueryGenerator r -> QueryGenerator (Tuple (t0 : (t1 : (r : ts)))) -- | Redirect the 3rd paramter to the given query generator. withParam3 :: QueryGenerator r -> QueryGenerator (Tuple (t0 : (t1 : (t2 : (r : ts))))) -- | Redirect the 4th paramter to the given query generator. withParam4 :: QueryGenerator r -> QueryGenerator (Tuple (t0 : (t1 : (t2 : (t3 : (r : ts)))))) -- | Redirect the 5th paramter to the given query generator. withParam5 :: QueryGenerator r -> QueryGenerator (Tuple (t0 : (t1 : (t2 : (t3 : (t4 : (r : ts))))))) -- | Redirect the 6th paramter to the given query generator. withParam6 :: QueryGenerator r -> QueryGenerator (Tuple (t0 : (t1 : (t2 : (t3 : (t4 : (t5 : (r : ts)))))))) -- | Redirect the 7th paramter to the given query generator. withParam7 :: QueryGenerator r -> QueryGenerator (Tuple (t0 : (t1 : (t2 : (t3 : (t4 : (t5 : (t6 : (r : ts))))))))) -- | Redirect the 8th paramter to the given query generator. withParam8 :: QueryGenerator r -> QueryGenerator (Tuple (t0 : (t1 : (t2 : (t3 : (t4 : (t5 : (t6 : (t7 : (r : ts)))))))))) -- | Redirect the 9th paramter to the given query generator. withParam9 :: QueryGenerator r -> QueryGenerator (Tuple (t0 : (t1 : (t2 : (t3 : (t4 : (t5 : (t6 : (t7 : (t8 : (r : ts))))))))))) instance GHC.Base.Monoid (Database.PostgreSQL.Store.Query.Builder.QueryGenerator a) instance Data.Semigroup.Semigroup (Database.PostgreSQL.Store.Query.Builder.QueryGenerator a) instance Data.String.IsString (Database.PostgreSQL.Store.Query.Builder.QueryGenerator a) instance Data.Hashable.Class.Hashable (Database.PostgreSQL.Store.Query.Builder.QueryGenerator a) module Database.PostgreSQL.Store.Generics -- | Make sure a has a safe generic representation. Types that -- qualify implement Generic (GHC) and fulfill one of the -- following criteria: -- -- -- -- This constraint is mostly utilized to give the user more information -- about why their type has been rejected. type Generic a = (Generic a, GDataType (Rep a), DataTypeRep (Rep a) ~ Rep a) -- | KDataType representation of a data type type Rep a = AnalyzeDataType a (Rep a) -- | Build from generic representation. toGeneric :: (Generic a) => DataType (Rep a) -> a -- | Convert to generic representation. fromGeneric :: (Generic a) => a -> DataType (Rep a) -- | Information about a record data KRecord -- | Combination of two records TCombine :: KRecord -> KRecord -> KRecord -- | Single element with meta information and type TSingle :: Meta -> Type -> KRecord -- | Information about the constructors of an enumeration data KFlatSum -- | Combination of values TChoose :: KFlatSum -> KFlatSum -> KFlatSum -- | Single value of the enumeration TValue :: Meta -> KFlatSum -- | Information about a data type data KDataType -- | Record TRecord :: Meta -> Meta -> KRecord -> KDataType -- | Enumeration TFlatSum :: Meta -> KFlatSum -> KDataType -- | Mappings between a Generic representation and our -- KRecord-based representation class GRecord (rec :: KRecord) where type RecordRep rec :: * -> * data Record rec where { type family RecordRep rec :: * -> *; data family Record rec; } -- | From Generic representation toRecord :: GRecord rec => RecordRep rec x -> Record rec -- | To Generic representation fromRecord :: GRecord rec => Record rec -> RecordRep rec x -- | Mappings between a Generic representation and our -- KFlatSum-based representation class GFlatSum (enum :: KFlatSum) where type FlatSumRep enum :: * -> * data FlatSum enum where { type family FlatSumRep enum :: * -> *; data family FlatSum enum; } -- | From Generic representation toFlatSum :: GFlatSum enum => FlatSumRep enum x -> FlatSum enum -- | To Generic representation fromFlatSum :: GFlatSum enum => FlatSum enum -> FlatSumRep enum x -- | Mappings between a Generic representation and our -- KDataType-based representation class GDataType (dat :: KDataType) where type DataTypeRep dat :: * -> * data DataType dat where { type family DataTypeRep dat :: * -> *; data family DataType dat; } -- | From Generic representation toDataType :: GDataType dat => DataTypeRep dat x -> DataType dat -- | To Generic representation fromDataType :: GDataType dat => DataType dat -> DataTypeRep dat x -- | Analyze the Generic representation of the selectors. Make sure -- it has 1 or more fields. Then transform it into a KRecord. -- | Analyze the Generic representation of constructors. Make sure -- every constructor has zero fields. Then transform it into a -- KFlatSum. -- | Analyze the Generic representation of a data type. If only one -- constructor exists, further analyzing is delegated to -- AnalyzeRecordRep. When two or more exist, analyzing is -- performed by AnalyzeFlatSumRep. The results are gather in a -- KDataType instance. instance GHC.Show.Show typ => GHC.Show.Show (Database.PostgreSQL.Store.Generics.Record ('Database.PostgreSQL.Store.Generics.TSingle meta typ)) instance (GHC.Show.Show (Database.PostgreSQL.Store.Generics.Record lhs), GHC.Show.Show (Database.PostgreSQL.Store.Generics.Record rhs)) => GHC.Show.Show (Database.PostgreSQL.Store.Generics.Record ('Database.PostgreSQL.Store.Generics.TCombine lhs rhs)) instance GHC.Show.Show (Database.PostgreSQL.Store.Generics.FlatSum ('Database.PostgreSQL.Store.Generics.TValue meta)) instance (GHC.Show.Show (Database.PostgreSQL.Store.Generics.FlatSum lhs), GHC.Show.Show (Database.PostgreSQL.Store.Generics.FlatSum rhs)) => GHC.Show.Show (Database.PostgreSQL.Store.Generics.FlatSum ('Database.PostgreSQL.Store.Generics.TChoose lhs rhs)) instance GHC.Show.Show (Database.PostgreSQL.Store.Generics.Record rec) => GHC.Show.Show (Database.PostgreSQL.Store.Generics.DataType ('Database.PostgreSQL.Store.Generics.TRecord d c rec)) instance GHC.Show.Show (Database.PostgreSQL.Store.Generics.FlatSum enum) => GHC.Show.Show (Database.PostgreSQL.Store.Generics.DataType ('Database.PostgreSQL.Store.Generics.TFlatSum d enum)) instance Database.PostgreSQL.Store.Generics.GRecord ('Database.PostgreSQL.Store.Generics.TSingle meta typ) instance (Database.PostgreSQL.Store.Generics.GRecord lhs, Database.PostgreSQL.Store.Generics.GRecord rhs) => Database.PostgreSQL.Store.Generics.GRecord ('Database.PostgreSQL.Store.Generics.TCombine lhs rhs) instance Database.PostgreSQL.Store.Generics.GFlatSum ('Database.PostgreSQL.Store.Generics.TValue meta) instance (Database.PostgreSQL.Store.Generics.GFlatSum lhs, Database.PostgreSQL.Store.Generics.GFlatSum rhs) => Database.PostgreSQL.Store.Generics.GFlatSum ('Database.PostgreSQL.Store.Generics.TChoose lhs rhs) instance Database.PostgreSQL.Store.Generics.GRecord rec => Database.PostgreSQL.Store.Generics.GDataType ('Database.PostgreSQL.Store.Generics.TRecord d c rec) instance Database.PostgreSQL.Store.Generics.GFlatSum enum => Database.PostgreSQL.Store.Generics.GDataType ('Database.PostgreSQL.Store.Generics.TFlatSum d enum) module Database.PostgreSQL.Store.Entity -- | An entity that is used as a parameter or result of a query. class (KnownNat (Width a)) => Entity a where type Width a :: Nat type Width a = GEntityWidth (Rep a) genEntity = genGeneric parseEntity = parseGeneric where { type family Width a :: Nat; type Width a = GEntityWidth (Rep a); } -- | Embed the entity into the query. genEntity :: Entity a => QueryGenerator a -- | Embed the entity into the query. genEntity :: (Entity a, Generic a, GEntity (Rep a)) => QueryGenerator a -- | Retrieve an instance of a from the result set. parseEntity :: Entity a => RowParser (Width a) a -- | Retrieve an instance of a from the result set. parseEntity :: (Entity a, Generic a, GEntity (Rep a)) => RowParser (GEntityWidth (Rep a)) a -- | Embed an entity into the query. embedEntity :: (Entity e) => e -> QueryGenerator a -- | Parameter entity at index 0 param0 :: (Entity r) => QueryGenerator (Tuple (r : ts)) -- | Parameter entity at index 1 param1 :: (Entity r) => QueryGenerator (Tuple (t0 : (r : ts))) -- | Parameter entity at index 2 param2 :: (Entity r) => QueryGenerator (Tuple (t0 : (t1 : (r : ts)))) -- | Parameter entity at index 3 param3 :: (Entity r) => QueryGenerator (Tuple (t0 : (t1 : (t2 : (r : ts))))) -- | Parameter entity at index 4 param4 :: (Entity r) => QueryGenerator (Tuple (t0 : (t1 : (t2 : (t3 : (r : ts)))))) -- | Parameter entity at index 5 param5 :: (Entity r) => QueryGenerator (Tuple (t0 : (t1 : (t2 : (t3 : (t4 : (r : ts))))))) -- | Parameter entity at index 6 param6 :: (Entity r) => QueryGenerator (Tuple (t0 : (t1 : (t2 : (t3 : (t4 : (t5 : (r : ts)))))))) -- | Parameter entity at index 7 param7 :: (Entity r) => QueryGenerator (Tuple (t0 : (t1 : (t2 : (t3 : (t4 : (t5 : (t6 : (r : ts))))))))) -- | Parameter entity at index 8 param8 :: (Entity r) => QueryGenerator (Tuple (t0 : (t1 : (t2 : (t3 : (t4 : (t5 : (t6 : (t7 : (r : ts)))))))))) -- | Parameter entity at index 9 param9 :: (Entity r) => QueryGenerator (Tuple (t0 : (t1 : (t2 : (t3 : (t4 : (t5 : (t6 : (t7 : (t8 : (r : ts))))))))))) -- | Generic QueryGenerator for an entity. genGeneric :: (Generic a, GEntity (Rep a)) => QueryGenerator a -- | Generic RowParser for an entity. parseGeneric :: (Generic a, GEntity (Rep a)) => RowParser (GEntityWidth (Rep a)) a -- | Generic record entity class (KnownNat (GRecordWidth rec)) => GEntityRecord (rec :: KRecord) where type GRecordWidth rec :: Nat where { type family GRecordWidth rec :: Nat; } gEmbedRecord :: GEntityRecord rec => QueryGenerator (Record rec) gParseRecord :: GEntityRecord rec => RowParser (GRecordWidth rec) (Record rec) -- | Generic entity class (KnownNat (GEntityWidth dat)) => GEntity (dat :: KDataType) where type GEntityWidth dat :: Nat where { type family GEntityWidth dat :: Nat; } gEmbedEntity :: GEntity dat => QueryGenerator (DataType dat) gParseEntity :: GEntity dat => RowParser (GEntityWidth dat) (DataType dat) -- | This is required if you want to use the default implementations of -- genEntityor parseEntity with polymorphic data types. type GenericEntity a = (Generic a, GEntity (Rep a)) instance Database.PostgreSQL.Store.Entity.Entity typ => Database.PostgreSQL.Store.Entity.GEntityRecord ('Database.PostgreSQL.Store.Generics.TSingle meta typ) instance (Database.PostgreSQL.Store.Entity.GEntityRecord lhs, Database.PostgreSQL.Store.Entity.GEntityRecord rhs, GHC.TypeLits.KnownNat (Database.PostgreSQL.Store.Entity.GRecordWidth lhs GHC.TypeLits.+ Database.PostgreSQL.Store.Entity.GRecordWidth rhs)) => Database.PostgreSQL.Store.Entity.GEntityRecord ('Database.PostgreSQL.Store.Generics.TCombine lhs rhs) instance GHC.TypeLits.KnownSymbol name => Database.PostgreSQL.Store.Entity.GEntityEnum ('Database.PostgreSQL.Store.Generics.TValue ('GHC.Generics.MetaCons name f r)) instance (Database.PostgreSQL.Store.Entity.GEntityEnum lhs, Database.PostgreSQL.Store.Entity.GEntityEnum rhs) => Database.PostgreSQL.Store.Entity.GEntityEnum ('Database.PostgreSQL.Store.Generics.TChoose lhs rhs) instance Database.PostgreSQL.Store.Entity.GEntityRecord rec => Database.PostgreSQL.Store.Entity.GEntity ('Database.PostgreSQL.Store.Generics.TRecord d c rec) instance Database.PostgreSQL.Store.Entity.GEntityEnum enum => Database.PostgreSQL.Store.Entity.GEntity ('Database.PostgreSQL.Store.Generics.TFlatSum d enum) instance Database.PostgreSQL.Store.Entity.GenericEntity (a, b) => Database.PostgreSQL.Store.Entity.Entity (a, b) instance Database.PostgreSQL.Store.Entity.GenericEntity (a, b, c) => Database.PostgreSQL.Store.Entity.Entity (a, b, c) instance Database.PostgreSQL.Store.Entity.GenericEntity (a, b, c, d) => Database.PostgreSQL.Store.Entity.Entity (a, b, c, d) instance Database.PostgreSQL.Store.Entity.GenericEntity (a, b, c, d, e) => Database.PostgreSQL.Store.Entity.Entity (a, b, c, d, e) instance Database.PostgreSQL.Store.Entity.GenericEntity (a, b, c, d, e, f) => Database.PostgreSQL.Store.Entity.Entity (a, b, c, d, e, f) instance Database.PostgreSQL.Store.Entity.GenericEntity (a, b, c, d, e, f, g) => Database.PostgreSQL.Store.Entity.Entity (a, b, c, d, e, f, g) instance Database.PostgreSQL.Store.Entity.Entity a => Database.PostgreSQL.Store.Entity.Entity (GHC.Base.Maybe a) instance Database.PostgreSQL.Store.Entity.Entity GHC.Types.Bool instance Database.PostgreSQL.Store.Entity.Entity GHC.Integer.Type.Integer instance Database.PostgreSQL.Store.Entity.Entity GHC.Types.Int instance Database.PostgreSQL.Store.Entity.Entity GHC.Int.Int8 instance Database.PostgreSQL.Store.Entity.Entity GHC.Int.Int16 instance Database.PostgreSQL.Store.Entity.Entity GHC.Int.Int32 instance Database.PostgreSQL.Store.Entity.Entity GHC.Int.Int64 instance Database.PostgreSQL.Store.Entity.Entity GHC.Natural.Natural instance Database.PostgreSQL.Store.Entity.Entity GHC.Types.Word instance Database.PostgreSQL.Store.Entity.Entity GHC.Word.Word8 instance Database.PostgreSQL.Store.Entity.Entity GHC.Word.Word16 instance Database.PostgreSQL.Store.Entity.Entity GHC.Word.Word32 instance Database.PostgreSQL.Store.Entity.Entity GHC.Word.Word64 instance Database.PostgreSQL.Store.Entity.Entity GHC.Types.Double instance Database.PostgreSQL.Store.Entity.Entity GHC.Types.Float instance Database.PostgreSQL.Store.Entity.Entity Data.Scientific.Scientific instance Database.PostgreSQL.Store.Entity.Entity GHC.Base.String instance Database.PostgreSQL.Store.Entity.Entity Data.Text.Internal.Text instance Database.PostgreSQL.Store.Entity.Entity Data.Text.Internal.Lazy.Text instance Database.PostgreSQL.Store.Entity.Entity Data.ByteString.Internal.ByteString instance Database.PostgreSQL.Store.Entity.Entity Data.ByteString.Lazy.Internal.ByteString instance Database.PostgreSQL.Store.Entity.Entity Data.Aeson.Types.Internal.Value module Database.PostgreSQL.Store.Table -- | Description of a table data Table Table :: ByteString -> [ByteString] -> Table -- | Table name [tableName] :: Table -> ByteString -- | Table columns [tableCols] :: Table -> [ByteString] -- | Table entity with extra information about its name and column names class (Entity a) => TableEntity a where describeTableType = describeGenericTable -- | Describe the table type. describeTableType :: TableEntity a => Tagged a Table -- | Describe the table type. describeTableType :: (TableEntity a, GenericTable a) => Tagged a Table -- | Embed table name. genTableName :: Table -> QueryGenerator a -- | Embed a comma-seperated list of the table's columns. genTableColumns :: Table -> QueryGenerator a -- | Same as genTableColumns but expands the columns on an alias of -- the table name. genTableColumnsOn :: Table -> ByteString -> QueryGenerator a -- | Constraint for generic tables type GenericTable a = (Generic a, GTable (AnalyzeTable a)) -- | Fetch the table description for a generic table type. describeGenericTable :: forall a. (GenericTable a) => Tagged a Table -- | Type-level description of a record data KColumns TCombine :: KColumns -> KColumns -> KColumns TSelector :: Symbol -> Type -> KColumns -- | Type-level description of a table data KTable TTable :: Symbol -> KColumns -> KTable -- | Provide the means to demote KColumns to a value. class GColumns (rec :: KColumns) -- | Instantiate singleton gDescribeColumns :: GColumns rec => Tagged rec [ByteString] -- | Provide the means to demote KTable to a value. class GTable (tbl :: KTable) -- | Instantiate singleton gDescribeTable :: GTable tbl => Tagged tbl Table -- | Check the Generic representation of a record in order to -- generate an instance of KColumns. -- | Check the Generic representation of a data type in order to -- generate an instance of KTable. -- | Analyzes a type in order to retrieve its KTable representation. type AnalyzeTable a = AnalyzeTableRep a (Rep a) instance GHC.Classes.Ord Database.PostgreSQL.Store.Table.Table instance GHC.Classes.Eq Database.PostgreSQL.Store.Table.Table instance GHC.Show.Show Database.PostgreSQL.Store.Table.Table instance GHC.TypeLits.KnownSymbol name => Database.PostgreSQL.Store.Table.GColumns ('Database.PostgreSQL.Store.Table.TSelector name typ) instance (Database.PostgreSQL.Store.Table.GColumns lhs, Database.PostgreSQL.Store.Table.GColumns rhs) => Database.PostgreSQL.Store.Table.GColumns ('Database.PostgreSQL.Store.Table.TCombine lhs rhs) instance (GHC.TypeLits.KnownSymbol name, Database.PostgreSQL.Store.Table.GColumns cols) => Database.PostgreSQL.Store.Table.GTable ('Database.PostgreSQL.Store.Table.TTable name cols) -- | All of the quasi quoters in this module accept the same language. It -- is almost identical to the language that a PostgreSQL server accepts. -- Certain operators have been reused in order to achieve a nice -- integration with the features of this library. -- -- Each quasi quoter uses QueryGenerator as an intermediate -- representation. -- --

QueryGenerator

-- -- Other query generators can be embedded using the $(haskell -- code) construct. -- --
--   genCatSound :: QueryGenerator a
--   genCatSound = Code "'meow'"
--   
--   listCats :: Query String
--   listCats =
--       [pgQuery| SELECT name
--                 FROM animals
--                 WHERE sound = $(genCatSound) |]
--   
-- -- We inline the genCatSound generator which produces the SQL -- code 'meow'. As a result we have a query with this statement: -- --
--   SELECT *
--   FROM animals
--   WHERE sound = 'meow'
--   
-- -- It is also possible to produce QueryGenerators with the -- pgQueryGen quasi quoter. -- --
--   genCatSound :: QueryGenerator a
--   genCatSound = [pgQueryGen| 'meow' |]
--   
-- --

Entity

-- -- Everything that has an instance of Entity can also be used in -- these quasi quoters. So far, one can only utilize them in the form of -- named expressions. -- -- The $ operator will cause the value of the following named -- expression to be used in the query. Any use of $name is just -- a short cut for $(embedEntity name). -- --
--   listPeople :: Int -> Query String
--   listPeople minimumAge =
--       [pgQuery| SELECT name
--                 FROM people
--                 WHERE age > $minimumAge |]
--   
-- -- This query will list the names of people above a given age. -- --

TableEntity

-- -- The TableEntity type class lets you associate a table name and -- the name of its column with a data type. -- -- Given a table schema like the following: -- --
--   CREATE TABLE MyTable (
--       first  INTEGER NOT NULL,
--       second VARCHAR NOT NULL
--   )
--   
-- -- We produce Haskell code like this: -- --
--   data MyTable = MyTable {
--       first  :: Int,
--       second :: String
--   } deriving (Show, Eq, Ord, Generic)
--   
--   instance Entity MyTable
--   
--   instance TableEntity MyTable
--   
-- -- Alternatively we can implement Entity and TableEntity -- ourselves. In this case it is not needed. -- -- We utilize these type classes in the following way: -- --
--   listMyTable :: Query MyTable
--   listMyTable =
--       [pgQuery| SELECT #MyTable
--                 FROM @MyTable |]
--   
-- -- We expand the absolute column names using #MyTable and the -- table name using @MyTable. This results in the following SQL: -- --
--   SELECT MyTable.first, MyTable.second
--   FROM MyTable
--   
-- -- Aliasing the table name is also possible: -- --
--   listMyTable :: Query MyTable
--   listMyTable =
--       [pgQuery| SELECT #MyTable(t)
--                 FROM @MyTable AS t |]
--   
-- -- The alias is included in the resulting SQL: -- --
--   SELECT t.first, t.second
--   FROM MyTable t
--   
module Database.PostgreSQL.Store.Query.TH -- | Generate a QueryGenerator expression. -- -- See Database.PostgreSQL.Store.Query.TH for detailed description -- of the language accepted by this quasi quoter. pgQueryGen :: QuasiQuoter -- | Generate a Query. This utilizes an intermediate query generator -- of type QueryGenerator (). -- -- See Database.PostgreSQL.Store.Query.TH for detailed description -- of the language accepted by this quasi quoter. pgQuery :: QuasiQuoter -- | Generate a PrepQuery. The intermediate query generator has type -- QueryGenerator (Tuple ts) where ts has kind -- [Type]. ts represents the types of the parameters to -- this prepared query. -- -- It is highly recommended that supply a type signature, if you give the -- resulting expression a name, to avoid ambiguity. -- --
--   q :: PrepQuery '[Int, String] User
--   q = [pgPrepQuery| SELECT #User(u) FROM @User u WHERE age < $(param0) AND name LIKE $(param1) |]
--   
-- -- See Database.PostgreSQL.Store.Query.TH for detailed description -- of the language accepted by this quasi quoter. pgPrepQuery :: QuasiQuoter instance GHC.Classes.Ord Database.PostgreSQL.Store.Query.TH.QuerySegment instance GHC.Classes.Eq Database.PostgreSQL.Store.Query.TH.QuerySegment instance GHC.Show.Show Database.PostgreSQL.Store.Query.TH.QuerySegment -- | This module acts solely as a re-export unit. module Database.PostgreSQL.Store.Query module Database.PostgreSQL.Store.Errand -- | Error during errand data ErrandError -- | No Result has been returned. NoResult :: ErrandError -- | A user has thrown an error. UserError :: String -> ErrandError -- | Query execution failed. ExecError :: ExecStatus -> ErrorCode -> ByteString -> ByteString -> ByteString -> ErrandError -- | Result processing failed. ParseError :: RowError -> ErrandError -- | Error codes data ErrorCode UnknownErrorCause :: ByteString -> ErrorCode IntegrityViolation :: ErrorCode RestrictViolation :: ErrorCode NotNullViolation :: ErrorCode ForeignKeyViolation :: ErrorCode UniqueViolation :: ErrorCode CheckViolation :: ErrorCode ExclusionViolation :: ErrorCode -- | An interaction with the database data Errand a -- | Run an errand. runErrand :: Connection -> Errand a -> IO (Either ErrandError a) -- | Execute the query and return its internal result. execute :: (ErrandQuery q Result) => q r -> ErrandResult q Result -- | Same as execute but instead of a Result it returns the -- number of affected rows. execute' :: (ErrandQuery q Int) => q r -> ErrandResult q Int -- | Execute a query and process its result set. query :: (Entity r, ErrandQuery q [r]) => q r -> ErrandResult q [r] -- | Execute a query and process its result set using the provided -- RowParser. queryWith :: (ErrandQuery q [r], KnownNat n) => RowParser n r -> q r -> ErrandResult q [r] -- | Prepare a preparable query. prepare :: PrepQuery a r -> Errand () -- | Begin a transaction. beginTransaction :: Errand () -- | Commit transaction. commitTransaction :: Errand () -- | Create savepoint within transaction. saveTransaction :: ByteString -> Errand () -- | Roll back transaction. rollbackTransaction :: Errand () -- | Roll back to a specific savepoint. rollbackTransactionTo :: ByteString -> Errand () -- | Do something within a transaction. withTransaction :: Errand a -> Errand () instance Control.Monad.Error.Class.MonadError Database.PostgreSQL.Store.Errand.ErrandError Database.PostgreSQL.Store.Errand.Errand instance Control.Monad.IO.Class.MonadIO Database.PostgreSQL.Store.Errand.Errand instance GHC.Base.Alternative Database.PostgreSQL.Store.Errand.Errand instance GHC.Base.Monad Database.PostgreSQL.Store.Errand.Errand instance GHC.Base.Applicative Database.PostgreSQL.Store.Errand.Errand instance GHC.Base.Functor Database.PostgreSQL.Store.Errand.Errand instance GHC.Classes.Eq Database.PostgreSQL.Store.Errand.ErrandError instance GHC.Show.Show Database.PostgreSQL.Store.Errand.ErrandError instance GHC.Classes.Eq Database.PostgreSQL.Store.Errand.ErrorCode instance GHC.Show.Show Database.PostgreSQL.Store.Errand.ErrorCode instance GHC.Base.Monoid Database.PostgreSQL.Store.Errand.ErrandError instance Database.PostgreSQL.Store.Errand.ErrandQuery Database.PostgreSQL.Store.Types.Statement r instance Database.PostgreSQL.Store.Errand.ErrandQuery Database.PostgreSQL.Store.Types.Query r instance Database.PostgreSQL.Store.Tuple.WithTuple ts (Database.PostgreSQL.Store.Errand.Errand r) => Database.PostgreSQL.Store.Errand.ErrandQuery (Database.PostgreSQL.Store.Types.PrepQuery ts) r module Database.PostgreSQL.Store -- | An interaction with the database data Errand a -- | Run an errand. runErrand :: Connection -> Errand a -> IO (Either ErrandError a) -- | Execute the query and return its internal result. execute :: (ErrandQuery q Result) => q r -> ErrandResult q Result -- | Same as execute but instead of a Result it returns the -- number of affected rows. execute' :: (ErrandQuery q Int) => q r -> ErrandResult q Int -- | Execute a query and process its result set. query :: (Entity r, ErrandQuery q [r]) => q r -> ErrandResult q [r] -- | Execute a query and process its result set using the provided -- RowParser. queryWith :: (ErrandQuery q [r], KnownNat n) => RowParser n r -> q r -> ErrandResult q [r] -- | Prepare a preparable query. prepare :: PrepQuery a r -> Errand () -- | Begin a transaction. beginTransaction :: Errand () -- | Commit transaction. commitTransaction :: Errand () -- | Create savepoint within transaction. saveTransaction :: ByteString -> Errand () -- | Roll back transaction. rollbackTransaction :: Errand () -- | Roll back to a specific savepoint. rollbackTransactionTo :: ByteString -> Errand () -- | Do something within a transaction. withTransaction :: Errand a -> Errand () -- | Query object data Query a Query :: ByteString -> [Maybe (Oid, ByteString, Format)] -> Query a -- | SQL statement [queryStatement] :: Query a -> ByteString -- | Parameters [queryParams] :: Query a -> [Maybe (Oid, ByteString, Format)] -- | Preparable query object data PrepQuery ts a PrepQuery :: ByteString -> ByteString -> [Oid] -> (Tuple ts -> [Maybe (ByteString, Format)]) -> PrepQuery ts a -- | Name of the prepared statement [prepName] :: PrepQuery ts a -> ByteString -- | SQL statement [prepStatement] :: PrepQuery ts a -> ByteString -- | Parameter type hints [prepOids] :: PrepQuery ts a -> [Oid] -- | Parameter generator [prepParams] :: PrepQuery ts a -> Tuple ts -> [Maybe (ByteString, Format)] -- | Generate a Query. This utilizes an intermediate query generator -- of type QueryGenerator (). -- -- See Database.PostgreSQL.Store.Query.TH for detailed description -- of the language accepted by this quasi quoter. pgQuery :: QuasiQuoter -- | Generate a PrepQuery. The intermediate query generator has type -- QueryGenerator (Tuple ts) where ts has kind -- [Type]. ts represents the types of the parameters to -- this prepared query. -- -- It is highly recommended that supply a type signature, if you give the -- resulting expression a name, to avoid ambiguity. -- --
--   q :: PrepQuery '[Int, String] User
--   q = [pgPrepQuery| SELECT #User(u) FROM @User u WHERE age < $(param0) AND name LIKE $(param1) |]
--   
-- -- See Database.PostgreSQL.Store.Query.TH for detailed description -- of the language accepted by this quasi quoter. pgPrepQuery :: QuasiQuoter -- | Generate a QueryGenerator expression. -- -- See Database.PostgreSQL.Store.Query.TH for detailed description -- of the language accepted by this quasi quoter. pgQueryGen :: QuasiQuoter newtype Oid :: * Oid :: CUInt -> Oid -- | An entity that is used as a parameter or result of a query. class (KnownNat (Width a)) => Entity a where type Width a :: Nat type Width a = GEntityWidth (Rep a) genEntity = genGeneric parseEntity = parseGeneric where { type family Width a :: Nat; type Width a = GEntityWidth (Rep a); } -- | Embed the entity into the query. genEntity :: Entity a => QueryGenerator a -- | Embed the entity into the query. genEntity :: (Entity a, Generic a, GEntity (Rep a)) => QueryGenerator a -- | Retrieve an instance of a from the result set. parseEntity :: Entity a => RowParser (Width a) a -- | Retrieve an instance of a from the result set. parseEntity :: (Entity a, Generic a, GEntity (Rep a)) => RowParser (GEntityWidth (Rep a)) a -- | Description of a table data Table Table :: ByteString -> [ByteString] -> Table -- | Table name [tableName] :: Table -> ByteString -- | Table columns [tableCols] :: Table -> [ByteString] -- | Table entity with extra information about its name and column names class (Entity a) => TableEntity a where describeTableType = describeGenericTable -- | Describe the table type. describeTableType :: TableEntity a => Tagged a Table -- | Describe the table type. describeTableType :: (TableEntity a, GenericTable a) => Tagged a Table -- | Error during errand data ErrandError -- | No Result has been returned. NoResult :: ErrandError -- | A user has thrown an error. UserError :: String -> ErrandError -- | Query execution failed. ExecError :: ExecStatus -> ErrorCode -> ByteString -> ByteString -> ByteString -> ErrandError -- | Result processing failed. ParseError :: RowError -> ErrandError -- | Error codes data ErrorCode UnknownErrorCause :: ByteString -> ErrorCode IntegrityViolation :: ErrorCode RestrictViolation :: ErrorCode NotNullViolation :: ErrorCode ForeignKeyViolation :: ErrorCode UniqueViolation :: ErrorCode CheckViolation :: ErrorCode ExclusionViolation :: ErrorCode data ExecStatus :: * -- | The string sent to the server was empty. EmptyQuery :: ExecStatus -- | Successful completion of a command returning no data. CommandOk :: ExecStatus -- | Successful completion of a command returning data (such as a SELECT or -- SHOW). TuplesOk :: ExecStatus -- | Copy Out (from server) data transfer started. CopyOut :: ExecStatus -- | Copy In (to server) data transfer started. CopyIn :: ExecStatus -- | Copy In/Out data transfer started. CopyBoth :: ExecStatus -- | The server's response was not understood. BadResponse :: ExecStatus -- | A nonfatal error (a notice or warning) occurred. NonfatalError :: ExecStatus -- | A fatal error occurred. FatalError :: ExecStatus -- | The PGresult contains a single result tuple from the current command. -- This status occurs only when single-row mode has been selected for the -- query. SingleTuple :: ExecStatus -- | An error that occured when parsing a row data RowError RowError :: RowErrorLocation -> RowErrorDetail -> RowError -- | Location of an error data RowErrorLocation RowErrorLocation :: Column -> Row -> RowErrorLocation -- | Errors that occur during row parsing data RowErrorDetail -- | Underlying RowParser wants more columns than are currently -- present. TooFewColumns :: RowErrorDetail -- | A column value could not be parsed. ColumnRejected :: RowErrorDetail