Copyright | 2014-2017 Kei Hibino |
---|---|
License | BSD3 |
Maintainer | ex8k.hibino@gmail.com |
Stability | experimental |
Portability | unknown |
Safe Haskell | None |
Language | Haskell2010 |
Database.Relational.Documentation
Description
This module is documentation module for relational-record. The project page of relational-record is http://khibino.github.io/haskell-relational-record/ .
Synopsis
- query :: (MonadQualify ConfigureQuery m, MonadQuery m) => Relation () r -> m (Record Flat r)
- queryMaybe :: (MonadQualify ConfigureQuery m, MonadQuery m) => Relation () r -> m (Record Flat (Maybe r))
- on :: MonadQuery m => Predicate Flat -> m ()
- wheres :: MonadRestrict Flat m => Predicate Flat -> m ()
- groupBy :: MonadAggregate m => Record Flat r -> m (Record Aggregated r)
- having :: MonadRestrict Aggregated m => Predicate Aggregated -> m ()
- distinct :: MonadQuery m => m ()
- all' :: MonadQuery m => m ()
- (<-#) :: forall (m :: Type -> Type) r v. Monad m => AssignTarget r v -> Record Flat v -> Assignings r m ()
- inner :: Relation () a -> Relation () b -> [JoinRestriction a b] -> Relation () (a, b)
- left :: Relation () a -> Relation () b -> [JoinRestriction a (Maybe b)] -> Relation () (a, Maybe b)
- right :: Relation () a -> Relation () b -> [JoinRestriction (Maybe a) b] -> Relation () (Maybe a, b)
- full :: Relation () a -> Relation () b -> [JoinRestriction (Maybe a) (Maybe b)] -> Relation () (Maybe a, Maybe b)
- on' :: ([JoinRestriction a b] -> Relation pc (a, b)) -> [JoinRestriction a b] -> Relation pc (a, b)
- type JoinRestriction a b = Record Flat a -> Record Flat b -> Predicate Flat
- data Relation p r
- relation :: QuerySimple (Record Flat r) -> Relation () r
- aggregateRelation :: QueryAggregate (Record Aggregated r) -> Relation () r
- type UpdateTarget p r = Record Flat r -> Assign r (PlaceHolders p)
- updateTarget :: (Record Flat r -> Assign r ()) -> UpdateTarget () r
- type Restriction p r = Record Flat r -> Restrict (PlaceHolders p)
- restriction :: (Record Flat r -> Restrict ()) -> Restriction () r
- data Record c t
- data Flat
- data Aggregated
- data Exists
- data OverWindow
- data Pi r0 r1
- (!) :: PersistableWidth a => Record c a -> Pi a b -> Record c b
- (<.>) :: Pi a b -> Pi b c -> Pi a c
- type ShowConstantTermsSQL = LiteralSQL
- value :: (LiteralSQL t, OperatorContext c) => t -> Record c t
- values :: (LiteralSQL t, OperatorContext c) => [t] -> RecordList (Record c) t
- (.=.) :: OperatorContext c => Record c ft -> Record c ft -> Record c (Maybe Bool)
- (.<.) :: OperatorContext c => Record c ft -> Record c ft -> Record c (Maybe Bool)
- (.<=.) :: OperatorContext c => Record c ft -> Record c ft -> Record c (Maybe Bool)
- (.>.) :: OperatorContext c => Record c ft -> Record c ft -> Record c (Maybe Bool)
- (.>=.) :: OperatorContext c => Record c ft -> Record c ft -> Record c (Maybe Bool)
- (.<>.) :: OperatorContext c => Record c ft -> Record c ft -> Record c (Maybe Bool)
- and' :: OperatorContext c => Record c (Maybe Bool) -> Record c (Maybe Bool) -> Record c (Maybe Bool)
- or' :: OperatorContext c => Record c (Maybe Bool) -> Record c (Maybe Bool) -> Record c (Maybe Bool)
- in' :: OperatorContext c => Record c t -> RecordList (Record c) t -> Record c (Maybe Bool)
- (.||.) :: OperatorContext c => Record c a -> Record c a -> Record c a
- like :: (OperatorContext c, IsString a, LiteralSQL a) => Record c a -> a -> Record c (Maybe Bool)
- like' :: (OperatorContext c, IsString a) => Record c a -> Record c a -> Record c (Maybe Bool)
- (.+.) :: (OperatorContext c, Num a) => Record c a -> Record c a -> Record c a
- (.-.) :: (OperatorContext c, Num a) => Record c a -> Record c a -> Record c a
- (.*.) :: (OperatorContext c, Num a) => Record c a -> Record c a -> Record c a
- (./.) :: (OperatorContext c, Num a) => Record c a -> Record c a -> Record c a
- isNothing :: (OperatorContext c, HasColumnConstraint NotNull r) => Record c (Maybe r) -> Predicate c
- isJust :: (OperatorContext c, HasColumnConstraint NotNull r) => Record c (Maybe r) -> Predicate c
- fromMaybe :: (OperatorContext c, HasColumnConstraint NotNull r) => Record c r -> Record c (Maybe r) -> Record c r
- not' :: OperatorContext c => Record c (Maybe Bool) -> Record c (Maybe Bool)
- exists :: OperatorContext c => RecordList (Record Exists) r -> Record c (Maybe Bool)
- negate' :: (OperatorContext c, Num a) => Record c a -> Record c a
- fromIntegral' :: (SqlContext c, Integral a, Num b) => Record c a -> Record c b
- showNum :: (SqlContext c, Num a, IsString b) => Record c a -> Record c b
- casesOrElse :: OperatorContext c => [(Predicate c, Record c a)] -> Record c a -> Record c a
- case' :: OperatorContext c => Record c a -> [(Record c a, Record c b)] -> Record c b -> Record c b
- count :: (Integral b, AggregatedContext ac, SqlContext ac) => Record Flat a -> Record ac b
- sum' :: (Num a, AggregatedContext ac, SqlContext ac) => Record Flat a -> Record ac (Maybe a)
- avg :: (Num a, Fractional b, AggregatedContext ac, SqlContext ac) => Record Flat a -> Record ac (Maybe b)
- max' :: (Ord a, AggregatedContext ac, SqlContext ac) => Record Flat a -> Record ac (Maybe a)
- min' :: (Ord a, AggregatedContext ac, SqlContext ac) => Record Flat a -> Record ac (Maybe a)
- every :: (AggregatedContext ac, SqlContext ac) => Predicate Flat -> Record ac (Maybe Bool)
- any' :: (AggregatedContext ac, SqlContext ac) => Predicate Flat -> Record ac (Maybe Bool)
- some' :: (AggregatedContext ac, SqlContext ac) => Predicate Flat -> Record ac (Maybe Bool)
- over :: SqlContext c => Record OverWindow a -> Window c () -> Record c a
- rank :: Integral a => Record OverWindow a
- denseRank :: Integral a => Record OverWindow a
- rowNumber :: Integral a => Record OverWindow a
- percentRank :: Record OverWindow Double
- cumeDist :: Record OverWindow Double
- union :: Relation () a -> Relation () a -> Relation () a
- except :: Relation () a -> Relation () a -> Relation () a
- intersect :: Relation () a -> Relation () a -> Relation () a
- just :: ProjectableMaybe p => p a -> p (Maybe a)
- flattenMaybe :: ProjectableMaybe p => p (Maybe (Maybe a)) -> p (Maybe a)
- (?!) :: PersistableWidth a => Record c (Maybe a) -> Pi a b -> Record c (Maybe b)
- (?!?) :: PersistableWidth a => Record c (Maybe a) -> Pi a (Maybe b) -> Record c (Maybe b)
- (<?.>) :: Pi a (Maybe b) -> Pi b c -> Pi a (Maybe c)
- (<?.?>) :: Pi a (Maybe b) -> Pi b (Maybe c) -> Pi a (Maybe c)
- (?+?) :: (OperatorContext c, Num a) => Record c (Maybe a) -> Record c (Maybe a) -> Record c (Maybe a)
- negateMaybe :: (OperatorContext c, Num a) => Record c (Maybe a) -> Record c (Maybe a)
- sumMaybe :: (Num a, AggregatedContext ac, SqlContext ac) => Record Flat (Maybe a) -> Record ac (Maybe a)
- placeholder :: (PersistableWidth t, SqlContext c, Monad m) => (Record c t -> m a) -> m (PlaceHolders t, a)
- query' :: MonadQuery m => Relation p r -> m (PlaceHolders p, Record Flat r)
- left' :: Relation pa a -> Relation pb b -> [JoinRestriction a (Maybe b)] -> Relation (pa, pb) (a, Maybe b)
- relation' :: SimpleQuery p r -> Relation p r
- updateTarget' :: (Record Flat r -> Assign r (PlaceHolders p)) -> UpdateTarget p r
- restriction' :: (Record Flat r -> Restrict (PlaceHolders p)) -> Restriction p r
- union' :: Relation p a -> Relation q a -> Relation (p, q) a
- class ProductConstructor c
- class ProductIsoFunctor (f :: Type -> Type) where
- (|$|) :: ProductConstructor (a -> b) => (a -> b) -> f a -> f b
- class ProductIsoFunctor f => ProductIsoApplicative (f :: Type -> Type) where
- pureP :: ProductConstructor a => a -> f a
- (|*|) :: f (a -> b) -> f a -> f b
- (><) :: ProductIsoApplicative p => p a -> p b -> p (a, b)
- relationalQuery :: Relation p r -> Query p r
- typedInsert :: PersistableWidth r => Table r -> Pi r r' -> Insert r'
- typedInsertQuery :: Table r -> Pi r r' -> Relation p r' -> InsertQuery p
- typedUpdate :: Table r -> (Record Flat r -> Assign r (PlaceHolders p)) -> Update p
- typedDelete :: Table r -> (Record Flat r -> Restrict (PlaceHolders p)) -> Delete p
- typedKeyUpdate :: Table a -> Pi a p -> KeyUpdate p a
- derivedInsert :: (PersistableWidth r, TableDerivable r) => Pi r r' -> Insert r'
- derivedInsertQuery :: TableDerivable r => Pi r r' -> Relation p r' -> InsertQuery p
- derivedUpdate :: TableDerivable r => (Record Flat r -> Assign r (PlaceHolders p)) -> Update p
- derivedDelete :: TableDerivable r => (Record Flat r -> Restrict (PlaceHolders p)) -> Delete p
- class FromSql q a
- class PersistableWidth a => ToSql q a
- data RecordFromSql q a
- data RecordToSql q a
- prepareNoFetch :: (UntypeableNoFetch s, IConnection conn) => conn -> s p -> IO (PreparedStatement p ())
- bind :: ToSql SqlValue p => PreparedStatement p a -> p -> BoundStatement a
- execute :: ToSql SqlValue p => PreparedStatement p a -> p -> IO (ExecutedStatement a)
- executeNoFetch :: ToSql SqlValue a => PreparedStatement a () -> a -> IO Integer
- prepareQuery :: IConnection conn => conn -> Query p a -> IO (PreparedQuery p a)
- fetch :: FromSql SqlValue a => ExecutedStatement a -> IO (Maybe a)
- runQuery :: (IConnection conn, ToSql SqlValue p, FromSql SqlValue a) => conn -> Query p a -> p -> IO [a]
- runQuery' :: (IConnection conn, ToSql SqlValue p, FromSql SqlValue a) => conn -> Query p a -> p -> IO [a]
- prepareInsert :: IConnection conn => conn -> Insert a -> IO (PreparedInsert a)
- runInsert :: (IConnection conn, ToSql SqlValue a) => conn -> Insert a -> a -> IO Integer
- prepareInsertQuery :: IConnection conn => conn -> InsertQuery p -> IO (PreparedInsertQuery p)
- runInsertQuery :: (IConnection conn, ToSql SqlValue p) => conn -> InsertQuery p -> p -> IO Integer
- prepareUpdate :: IConnection conn => conn -> Update p -> IO (PreparedUpdate p)
- runUpdate :: (IConnection conn, ToSql SqlValue p) => conn -> Update p -> p -> IO Integer
- prepareDelete :: IConnection conn => conn -> Delete p -> IO (PreparedDelete p)
- runDelete :: (IConnection conn, ToSql SqlValue p) => conn -> Delete p -> p -> IO Integer
- prepareKeyUpdate :: IConnection conn => conn -> KeyUpdate p a -> IO (PreparedKeyUpdate p a)
- bindKeyUpdate :: ToSql SqlValue a => PreparedKeyUpdate p a -> a -> BoundStatement ()
- runKeyUpdate :: (IConnection conn, ToSql SqlValue a) => conn -> KeyUpdate p a -> a -> IO Integer
Concepts
User interface of Relational Record has main two part of modules.
Database.Relational
- Relational Query Building DSL
Database.Record and Database.HDBC.Record
- Database Operation Actions
Relational Query Building DSL
Relational Query (Database.Relational) module defines Typed DSL to build complex SQL query.
Monadic Query Context Building
On building query, query structures can be accumulated in monadic context.
Monadic Operators
Some operators are defined to build query structures in monadic context.
query
and queryMaybe
operators grow query product of monadic context like join operation of SQL.
on
operator appends a new condition into recent join product condition.
groupBy
operator aggregates flat record value, and can be used only in MonadAggregate
context.
wheres
and having
operators appends a new condition into whole query condition.
having
only accepts aggregated record value, and can be used only in MonadRestrict
Aggregated
context.
distinct
operator and all'
operator specify SELECT DISTINCT or SELECT ALL, the last specified in monad is used.
<-#
operator assigns update target column and record value to build update statement structure.
queryMaybe :: (MonadQualify ConfigureQuery m, MonadQuery m) => Relation () r -> m (Record Flat (Maybe r)) #
having :: MonadRestrict Aggregated m => Predicate Aggregated -> m () #
(<-#) :: forall (m :: Type -> Type) r v. Monad m => AssignTarget r v -> Record Flat v -> Assignings r m () #
Direct Join Operators
Not monadic style join is supported by some direct join operators.
inner
, left
, right
, full
operators can construct join products directly like SQL.
inner
operator is INNER JOIN of SQL, left
operator is LEFT OUTER JOIN of SQL, and so on.
on'
operator specifies condition of join product.
JoinRestriction
is the type of lambda form which expresses condition of join product.
left :: Relation () a -> Relation () b -> [JoinRestriction a (Maybe b)] -> Relation () (a, Maybe b) #
right :: Relation () a -> Relation () b -> [JoinRestriction (Maybe a) b] -> Relation () (Maybe a, b) #
full :: Relation () a -> Relation () b -> [JoinRestriction (Maybe a) (Maybe b)] -> Relation () (Maybe a, Maybe b) #
on' :: ([JoinRestriction a b] -> Relation pc (a, b)) -> [JoinRestriction a b] -> Relation pc (a, b) #
Finalize Context
Several operators are defined to make Relation
type with finalizing query monadic context.
relation
operator finalizes flat (not aggregated) query monadic context,
and aggregateRelation
operator finalizes aggregated query monadic context.
Both operator convert monadic context into Relation
type,
and finalized Relation
can be reused as joining and sub-querying in another queries.
updateTarget
operator finalize monadic context into UpdateTarget
type
which can be used as update statement.
restriction
operator finalize monadic context into Restriction
type
which can be used as delete statement.
aggregateRelation :: QueryAggregate (Record Aggregated r) -> Relation () r #
type UpdateTarget p r = Record Flat r -> Assign r (PlaceHolders p) #
updateTarget :: (Record Flat r -> Assign r ()) -> UpdateTarget () r #
type Restriction p r = Record Flat r -> Restrict (PlaceHolders p) #
restriction :: (Record Flat r -> Restrict ()) -> Restriction () r #
Record
SQL expression corresponds to Haskell record phantom type in this DSL.
Record Type
Record
c a is projected SQL value type corresponding to Haskell record type a with context type c.
Flat
is not aggregated query context type,
Aggregated
is aggregated query context type,
OverWindow
is window function context type, and so on.
Module Database.Relational.Context contains documentation of other context types.
Instances
ProjectableMaybe (Record c) | |
Defined in Database.Relational.Projectable | |
Show (Record c t) | |
data Aggregated #
data OverWindow #
Projection Path
!
operator is record value selector using projection path type Pi
r0 r1.
Pi
r0 r1 is projection path type selecting column type r1 from record type r0.
<.>
operator makes composed projection path from two projection paths.
fst'
and snd'
are projection paths for pair type.
Instances
ProductIsoFunctor (Pi a) | |
Defined in Database.Relational.Pi.Unsafe | |
ProductIsoApplicative (Pi a) | |
ProductIsoEmpty (Pi a) () | |
Category Pi | |
PersistableWidth r0 => Show (Pi r0 r1) | |
Overloaded Projection
On newer or equal GHC 8.0, overloaded projections are supported. So you can use projections like below:
a ! #foo .=. b ! #bar
instead of:
a ! A.foo' .=. b ! B.bar'
Function application style is also available:
#foo a .=. #bar b
#fst
and #snd
are overloaded-projection for pair type.
Record Operators
Some operators are defined to calculate record values.
For example,
value
operator lifts from Haskell value into Record
corresponding SQL row value,
which conversion is implicitly specified by ShowConstantTermsSQL
class.
Generic programming with default signature is available to define instances of ShowConstantTermsSQL
.
values
operator converts from Haskell list value into RecordList
, corresponding SQL set value,
.=.
operator is equal compare operation of record value correspond to SQL =,
.+.
operator is plus operation of record value correspond to SQL +, and so on.
Module Database.Relational.Projectable contains documentation of other record operators.
type ShowConstantTermsSQL = LiteralSQL #
and' :: OperatorContext c => Record c (Maybe Bool) -> Record c (Maybe Bool) -> Record c (Maybe Bool) #
or' :: OperatorContext c => Record c (Maybe Bool) -> Record c (Maybe Bool) -> Record c (Maybe Bool) #
isNothing :: (OperatorContext c, HasColumnConstraint NotNull r) => Record c (Maybe r) -> Predicate c #
isJust :: (OperatorContext c, HasColumnConstraint NotNull r) => Record c (Maybe r) -> Predicate c #
fromMaybe :: (OperatorContext c, HasColumnConstraint NotNull r) => Record c r -> Record c (Maybe r) -> Record c r #
fromIntegral' :: (SqlContext c, Integral a, Num b) => Record c a -> Record c b #
casesOrElse :: OperatorContext c => [(Predicate c, Record c a)] -> Record c a -> Record c a #
case' :: OperatorContext c => Record c a -> [(Record c a, Record c b)] -> Record c b -> Record c b #
Aggregate and Window Functions
Typed aggregate function operators are defined. Aggregated value types is distinguished with Flat value types.
For example,
sum'
operator is aggregate function of flat (not aggregated) record value
correspond to SQL SUM(...),
rank
operator is window function of record value correspond to SQL RANK(), and so on.
To convert window function result into normal record, use the over
operator with built Window
monad.
Module Database.Relational.Projectable contains documentation of other aggregate function operators and window function operators.
avg :: (Num a, Fractional b, AggregatedContext ac, SqlContext ac) => Record Flat a -> Record ac (Maybe b) #
over :: SqlContext c => Record OverWindow a -> Window c () -> Record c a #
rank :: Integral a => Record OverWindow a #
denseRank :: Integral a => Record OverWindow a #
rowNumber :: Integral a => Record OverWindow a #
percentRank :: Record OverWindow Double #
cumeDist :: Record OverWindow Double #
Set Operators
Several operators are defined to manipulate relation set.
union
operator makes union relation set of two relation set correspond to SQL UNION.
except
operator makes difference relation set of two relation set correspond to SQL EXCEPT.
intersect
operator makes intersection relation set of two relation set correspond to SQL INTERSECT.
Maybe Records
Some operators are provided to manage records with Maybe
phantom type.
just
operator creates Maybe
typed record,
flattenMaybe
operator joins nested Maybe
typed record.
Maybe
type flavor of operators against projection path, record and aggregation are also provided.
For example,
?!
operator is maybe flavor of !
,
<?.>
operator is maybe flavor of <.>
.
?!?
operator and <?.?>
operator join
two Maybe
phantom functors.
?
is same as ?!
, which is assumed to use with overloaded-projection like (? #foo)
.
??
is same as ?!?
, which is assumed to use with overloaded-projection like (?? #foo)
.
?+?
operator is maybe flavor of .+.
,
negateMaybe
operator is maybe flavor of negate'
,
sumMaybe
operator is maybe flavor of sum'
.
Module Database.Relational.Projectable and Database.Relational.ProjectableExtended
contain documentation of other Maybe
flavor operators.
flattenMaybe :: ProjectableMaybe p => p (Maybe (Maybe a)) -> p (Maybe a) #
(?+?) :: (OperatorContext c, Num a) => Record c (Maybe a) -> Record c (Maybe a) -> Record c (Maybe a) #
negateMaybe :: (OperatorContext c, Num a) => Record c (Maybe a) -> Record c (Maybe a) #
sumMaybe :: (Num a, AggregatedContext ac, SqlContext ac) => Record Flat (Maybe a) -> Record ac (Maybe a) #
Placeholders
placeholders
operator takes
a lambda-form which argument is Record
typed placeholders and its scope is restricted by that lambda-form
and then creates dummy value with Placeholders
typed which propagate placeholder type information into Relation
layer.
Placeholders' flavor of operators against query operation and set operation are also provided, to realize type safe placeholders.
query'
, left'
, relation'
, updateTarget'
, restriction'
, and union'
operator are placeholders' flavor query
, left
, relation
, updateTarget
, restriction
and union
.
Module Database.Relational.Relation and Database.Relational.Effect contains documentation of other placeholders' flavor operators.
placeholder :: (PersistableWidth t, SqlContext c, Monad m) => (Record c t -> m a) -> m (PlaceHolders t, a) #
left' :: Relation pa a -> Relation pb b -> [JoinRestriction a (Maybe b)] -> Relation (pa, pb) (a, Maybe b) #
updateTarget' :: (Record Flat r -> Assign r (PlaceHolders p)) -> UpdateTarget p r #
restriction' :: (Record Flat r -> Restrict (PlaceHolders p)) -> Restriction p r #
Record Mapping
Applicative style record mapping is supported, for Record
, Pi
and PlaceHolders
.
|$|
operator can be used on ProductIsoFunctor
context, and
|*|
operator can be used on ProductIsoApplicative
context with ProductConstructor
,
like Foo |$| record1 |*| record2 |*| record3
, Foo |$| placeholders1 |*| placeholders2 |*| placeholders3, and so on.
><
operator constructs pair result. x >< y is the same as (,) |$| x |*| y.
class ProductConstructor c Source #
Define product isomorphic inference rule to specify record constructor
Minimal complete definition
class ProductIsoFunctor (f :: Type -> Type) where Source #
Restricted functor on products.
Methods
(|$|) :: ProductConstructor (a -> b) => (a -> b) -> f a -> f b infixl 4 Source #
Instances
ProductIsoFunctor (ProductConst a) | |
Defined in Database.Record.Persistable Methods (|$|) :: ProductConstructor (a0 -> b) => (a0 -> b) -> ProductConst a a0 -> ProductConst a b Source # | |
Functor f => ProductIsoFunctor (WrappedFunctor f) | |
Defined in Data.Functor.ProductIsomorphic.Instances Methods (|$|) :: ProductConstructor (a -> b) => (a -> b) -> WrappedFunctor f a -> WrappedFunctor f b Source # | |
ProductIsoFunctor (Pi a) | |
Defined in Database.Relational.Pi.Unsafe | |
ProductIsoFunctor (WrappedAlter f a) | |
Defined in Data.Functor.ProductIsomorphic.Instances Methods (|$|) :: ProductConstructor (a0 -> b) => (a0 -> b) -> WrappedAlter f a a0 -> WrappedAlter f a b Source # |
class ProductIsoFunctor f => ProductIsoApplicative (f :: Type -> Type) where Source #
Restricted applicative functor on products.
Methods
pureP :: ProductConstructor a => a -> f a Source #
Instances
Monoid a => ProductIsoApplicative (ProductConst a) | |
Defined in Database.Record.Persistable Methods pureP :: ProductConstructor a0 => a0 -> ProductConst a a0 Source # (|*|) :: ProductConst a (a0 -> b) -> ProductConst a a0 -> ProductConst a b Source # | |
Applicative f => ProductIsoApplicative (WrappedFunctor f) | |
Defined in Data.Functor.ProductIsomorphic.Instances Methods pureP :: ProductConstructor a => a -> WrappedFunctor f a Source # (|*|) :: WrappedFunctor f (a -> b) -> WrappedFunctor f a -> WrappedFunctor f b Source # | |
ProductIsoApplicative (Pi a) | |
Alternative f => ProductIsoApplicative (WrappedAlter f a) | |
Defined in Data.Functor.ProductIsomorphic.Instances Methods pureP :: ProductConstructor a0 => a0 -> WrappedAlter f a a0 Source # (|*|) :: WrappedAlter f a (a0 -> b) -> WrappedAlter f a a0 -> WrappedAlter f a b Source # |
(><) :: ProductIsoApplicative p => p a -> p b -> p (a, b) #
Database Statements
Some functions are defined to expand query structure into flat SQL statements to be used by database operation.
relationalQuery
function converts Relation
type info flat SQL query like SELECT statement.
derivedInsert
function converts Pi
key type info flat SQL INSERT statement.
derivedInsertValue
function converts InsertTarget
into flat SQL INSERT statement.
derivedInsertQuery
function converts Pi
key type and Relation
type info flat SQL INSERT ... SELECT ... statement.
derivedUpdate
function converts UpdateTarget
type into flat SQL UPDATE statement.
derivedDelete
function converts Restriction
into flat SQL DELETE statement.
derivedKeyUpdate
function converts Pi
key type info flat SQL UPDATE statement.
Some functions which requires to be specified table type,
typedInsert
, typedInsertQuery
, typedUpdate
and typedDelete
.
These functions are useful when table type is undecidable from its statement contexts.
relationalQuery :: Relation p r -> Query p r #
typedInsert :: PersistableWidth r => Table r -> Pi r r' -> Insert r' #
typedInsertQuery :: Table r -> Pi r r' -> Relation p r' -> InsertQuery p #
typedUpdate :: Table r -> (Record Flat r -> Assign r (PlaceHolders p)) -> Update p #
typedDelete :: Table r -> (Record Flat r -> Restrict (PlaceHolders p)) -> Delete p #
typedKeyUpdate :: Table a -> Pi a p -> KeyUpdate p a #
derivedInsert :: (PersistableWidth r, TableDerivable r) => Pi r r' -> Insert r' #
derivedInsertQuery :: TableDerivable r => Pi r r' -> Relation p r' -> InsertQuery p #
derivedUpdate :: TableDerivable r => (Record Flat r -> Assign r (PlaceHolders p)) -> Update p #
derivedDelete :: TableDerivable r => (Record Flat r -> Restrict (PlaceHolders p)) -> Delete p #
Database Operations
Some HDBC actions are defined for database side effects.
Conversion interfaces to communicate with database
Some record conversion interfaces are defined to communicate with database.
The conversions are implicitly specified by FromSql
class and ToSql
class.
Generic programming with default signature is available to define instances of FromSql
and ToSql
.
The explicit definitions correnponsing those classes are RecordFromSql
and RecordToSql
.
FromSql
q
a
is implicit rule to derive RecordFromSql
q
a
record parser function against type a
.
Generic programming (https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#generic-programming)
with default signature is available for FromSql
class,
so you can make instance like below:
{-# LANGUAGE DeriveGeneric #-} import GHC.Generics (Generic) import Database.HDBC (SqlValue) -- data Foo = Foo { ... } deriving Generic instance FromSql SqlValue Foo
Instances
FromSql q () | Implicit derivation rule of |
Defined in Database.Record.FromSql Methods recordFromSql :: RecordFromSql q () Source # | |
(HasColumnConstraint NotNull a, FromSql q a, PersistableType q) => FromSql q (Maybe a) | Implicit derivation rule of |
Defined in Database.Record.FromSql Methods recordFromSql :: RecordFromSql q (Maybe a) Source # |
class PersistableWidth a => ToSql q a Source #
ToSql
q
a
is implicit rule to derive RecordToSql
q
a
record printer function for type a
.
Generic programming (https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#generic-programming)
with default signature is available for ToSql
class,
so you can make instance like below:
{-# LANGUAGE DeriveGeneric #-} import GHC.Generics (Generic) import Database.HDBC (SqlValue) -- data Foo = Foo { ... } deriving Generic instance ToSql SqlValue Foo
To make instances of ToSql
manually,
ToSql
q
a
and RecordToSql
'q a
are composable with monadic context.
When, you have data constructor and objects like below.
data MyRecord = MyRecord Foo Bar Baz
instance ToSql SqlValue Foo where ... instance ToSql SqlValue Bar where ... instance ToSql SqlValue Baz where ...
You can get composed ToSql
implicit rule like below.
instance ToSql SqlValue MyRecord where recordToSql = recordToSql = wrapToSql $ \ (MyRecord x y z) -> do putRecord x putRecord y putRecord z
Instances
ToSql q () | Implicit derivation rule of |
Defined in Database.Record.ToSql Methods recordToSql :: RecordToSql q () Source # | |
(PersistableType q, ToSql q a) => ToSql q (Maybe a) | Implicit derivation rule of |
Defined in Database.Record.ToSql Methods recordToSql :: RecordToSql q (Maybe a) Source # |
data RecordFromSql q a Source #
RecordFromSql
q
a
is data-type wrapping function
to convert from list of database value type (to receive from database) [q
] into Haskell type a
This structure is similar to parser.
While running RecordFromSql
behavior is the same as non-fail-able parser
which parse list of database value type [q
] stream.
So, RecordFromSql
q
is Monad
and Applicative
instance like parser monad.
When, you have data constructor and objects like below.
data MyRecord = MyRecord Foo Bar Baz
foo ::RecordFromSql
SqlValue Foo foo = ... bar ::RecordFromSql
SqlValue Bar bar = ... baz ::RecordFromSql
SqlValue Baz baz = ...
You can get composed RecordFromSql
like below.
myRecord :: RecordFromSql SqlValue MyRecord myRecord = MyRecord <$> foo <*> bar <*> baz
Instances
Monad (RecordFromSql q) |
|
Defined in Database.Record.FromSql Methods (>>=) :: RecordFromSql q a -> (a -> RecordFromSql q b) -> RecordFromSql q b (>>) :: RecordFromSql q a -> RecordFromSql q b -> RecordFromSql q b return :: a -> RecordFromSql q a | |
Functor (RecordFromSql q) | Derived |
Defined in Database.Record.FromSql Methods fmap :: (a -> b) -> RecordFromSql q a -> RecordFromSql q b (<$) :: a -> RecordFromSql q b -> RecordFromSql q a | |
Applicative (RecordFromSql q) | Derived |
Defined in Database.Record.FromSql Methods pure :: a -> RecordFromSql q a (<*>) :: RecordFromSql q (a -> b) -> RecordFromSql q a -> RecordFromSql q b liftA2 :: (a -> b -> c) -> RecordFromSql q a -> RecordFromSql q b -> RecordFromSql q c (*>) :: RecordFromSql q a -> RecordFromSql q b -> RecordFromSql q b (<*) :: RecordFromSql q a -> RecordFromSql q b -> RecordFromSql q a |
data RecordToSql q a Source #
RecordToSql
q
a
is data-type wrapping function
to convert from Haskell type a
into list of database value type (to send to database) [q
].
This structure is similar to printer.
While running RecordToSql
behavior is the same as list printer.
which appends list of database value type [q
] stream.
Generalized Statement
Actions to manage generalized SQL statements.
prepareNoFetch :: (UntypeableNoFetch s, IConnection conn) => conn -> s p -> IO (PreparedStatement p ()) #
executeNoFetch :: ToSql SqlValue a => PreparedStatement a () -> a -> IO Integer #
Select
Actions to manage SELECT statements.
runQuery
function is lazy-read and runQuery'
function is strict version,
please use carefully.
prepareQuery :: IConnection conn => conn -> Query p a -> IO (PreparedQuery p a) #
runQuery :: (IConnection conn, ToSql SqlValue p, FromSql SqlValue a) => conn -> Query p a -> p -> IO [a] #
runQuery' :: (IConnection conn, ToSql SqlValue p, FromSql SqlValue a) => conn -> Query p a -> p -> IO [a] #
Insert Values
Actions to manage INSERT ... VALUES ... statements.
prepareInsert :: IConnection conn => conn -> Insert a -> IO (PreparedInsert a) #
Insert Select Results
Actions to manage INSERT ... SELECT ... statements.
prepareInsertQuery :: IConnection conn => conn -> InsertQuery p -> IO (PreparedInsertQuery p) #
runInsertQuery :: (IConnection conn, ToSql SqlValue p) => conn -> InsertQuery p -> p -> IO Integer #
Update
Actions to manage UPDATE statements.
prepareUpdate :: IConnection conn => conn -> Update p -> IO (PreparedUpdate p) #
Delete
Actions to manage DELETE statements.
prepareDelete :: IConnection conn => conn -> Delete p -> IO (PreparedDelete p) #
Update by Key
Actions to manage UPDATE statements which updates columns other than specified key of the records selected by specified key.
prepareKeyUpdate :: IConnection conn => conn -> KeyUpdate p a -> IO (PreparedKeyUpdate p a) #
bindKeyUpdate :: ToSql SqlValue a => PreparedKeyUpdate p a -> a -> BoundStatement () #
runKeyUpdate :: (IConnection conn, ToSql SqlValue a) => conn -> KeyUpdate p a -> a -> IO Integer #