-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | ribbit
--
-- ribbit
@package ribbit
@version 0.2.0.1
-- | This module attepts to define a type-level language for describing
-- database shcemas (i.e. schemas "as a type"), and the queries that
-- operate on them in such a way that the meaning of a query is
-- immediately obvious to anyone who knows SQL, and that can be extended
-- and deconstructed by library users for their own purposes.
module Database.Ribbit
-- | String two types together. Int :> Int
-- :> Int is similar in principal to the nested tuple
-- (Int, (Int, Int)), but looks a whole lot nicer
-- when the number of elements becomes large.
data a :> b
(:>) :: a -> b -> (:>) a b
infixr 5 :>
infixr 5 :>
class Table relation where {
type family DBSchema relation;
type family Name relation :: Symbol;
}
-- | Define a field in a database schema.
data Field name typ
-- | SELECT combinator, used for starting a SELECT
-- statement.
data Select fields
-- | FROM combinator, used for attaching a SELECT projection to a
-- relation in the database.
data From proj relation
infixl 6 `From`
-- | Cross product operator for FROM clauses.
data X l r
infixr 7 `X`
-- | AS combinator, used for attaching a name to a table in a FROM
-- clause.
data As relation name
infix 8 `As`
-- | WHERE combinator, used for attaching conditions to a query.
data Where query conditions
infixl 6 `Where`
-- | AND combinator for conditions.
data And l r
infixr 8 `And`
-- | OR combinator for conditions.
data Or l r
infixr 7 `Or`
-- | "=" combinator for conditions.
data Equals l r
infix 9 `Equals`
-- | "?" combinator, used to indicate the presence of a query parameter.
data (?)
-- | Produce the type represeting the placeholder ("?") values in a
-- paramaterized query.
type family ArgsType query
-- | Produce the type of rows return by a query.
type family ResultType query
-- | Render a type-level query as text.
class Render query
render :: Render query => proxy query -> Text
instance (GHC.Show.Show a, GHC.Show.Show b) => GHC.Show.Show (a Database.Ribbit.:> b)
instance (GHC.Classes.Ord a, GHC.Classes.Ord b) => GHC.Classes.Ord (a Database.Ribbit.:> b)
instance (GHC.Classes.Eq a, GHC.Classes.Eq b) => GHC.Classes.Eq (a Database.Ribbit.:> b)
instance forall k (fields :: k). Database.Ribbit.Render fields => Database.Ribbit.Render (Database.Ribbit.Select fields)
instance GHC.TypeLits.KnownSymbol field => Database.Ribbit.Render '[field]
instance (GHC.TypeLits.KnownSymbol field, Database.Ribbit.Render more) => Database.Ribbit.Render (field : more)
instance forall k1 k2 (relation :: k2) (proj :: k1). (GHC.TypeLits.KnownSymbol (Database.Ribbit.Name relation), Database.Ribbit.Render proj, Database.Ribbit.Table relation) => Database.Ribbit.Render (Database.Ribbit.From proj relation)
instance forall k1 k2 (query :: k2) (conditions :: k1). (Database.Ribbit.Render query, Database.Ribbit.Render conditions) => Database.Ribbit.Render (Database.Ribbit.Where query conditions)
instance forall k1 k2 (l :: k2) (r :: k1). (Database.Ribbit.Render (Database.Ribbit.Expr l), Database.Ribbit.Render (Database.Ribbit.Expr r)) => Database.Ribbit.Render (Database.Ribbit.Equals l r)
instance forall k1 k2 (l :: k2) (r :: k1). (Database.Ribbit.Render l, Database.Ribbit.Render r) => Database.Ribbit.Render (Database.Ribbit.And l r)
instance forall k1 k2 (l :: k2) (r :: k1). (Database.Ribbit.Render l, Database.Ribbit.Render r) => Database.Ribbit.Render (Database.Ribbit.Or l r)
instance Database.Ribbit.Render (Database.Ribbit.Expr (Database.Ribbit.?))
instance GHC.TypeLits.KnownSymbol a => Database.Ribbit.Render (Database.Ribbit.Expr a)
instance Database.Ribbit.Render (Database.Ribbit.?)
instance forall k1 k2 (l :: k2) (r :: k1) (lname :: GHC.Types.Symbol) (rname :: GHC.Types.Symbol). (Database.Ribbit.Table l, Database.Ribbit.Table r, GHC.TypeLits.KnownSymbol lname, GHC.TypeLits.KnownSymbol rname) => Database.Ribbit.Table (Database.Ribbit.X (Database.Ribbit.As l lname) (Database.Ribbit.As r rname))
-- | "postgresql-simple"-backed query ribbit implementation.
module Database.Ribbit.PostgreSQL
-- | Execute a query against a PostgreSQL database connection.
query :: (MonadIO m, Render query, ToRow (ArgsType query), FromRow (ResultType query)) => Connection -> Proxy query -> ArgsType query -> m [ResultType query]
-- | Like FromRow, but defined here so we can avoid orphaned
-- instances.
class FromRow a
-- | Like ToRow, but defined here to avoid orphan instances.
class ToRow a
instance Database.Ribbit.PostgreSQL.FromRow a => Database.PostgreSQL.Simple.FromRow.FromRow (Database.Ribbit.PostgreSQL.Wrap a)
instance Database.Ribbit.PostgreSQL.ToRow a => Database.PostgreSQL.Simple.ToRow.ToRow (Database.Ribbit.PostgreSQL.Wrap a)
instance (Database.Ribbit.PostgreSQL.ToRow a, Database.Ribbit.PostgreSQL.ToRow b) => Database.Ribbit.PostgreSQL.ToRow (a Database.Ribbit.:> b)
instance Database.PostgreSQL.Simple.ToField.ToField a => Database.Ribbit.PostgreSQL.ToRow (Data.Tuple.Only.Only a)
instance Database.Ribbit.PostgreSQL.ToRow ()
instance (Database.Ribbit.PostgreSQL.FromRow a, Database.Ribbit.PostgreSQL.FromRow b) => Database.Ribbit.PostgreSQL.FromRow (a Database.Ribbit.:> b)
instance Database.PostgreSQL.Simple.FromField.FromField a => Database.Ribbit.PostgreSQL.FromRow (Data.Tuple.Only.Only a)