haskelldb-2.2.4: A library of combinators for generating and executing SQL statements.

Copyright | Daan Leijen (c) 1999, daan@cs.uu.nl HWT Group (c) 2003, haskelldb-users@lists.sourceforge.net
License | BSD-style
Maintainer | haskelldb-users@lists.sourceforge.net
Stability | experimental
Portability | non portable
Safe Haskell | None
Language | Haskell98

Database.HaskellDB.PrimQuery

Contents

- Type Declarations
  - Types
  - Data types
- Function declarations

Description

PrimQuery defines the datatype of relational expressions (`PrimQuery`) and some useful functions on PrimQuery's

Synopsis

- type TableName = String
- type Attribute = String
- type Scheme = [Attribute]
- type Assoc = [(Attribute, PrimExpr)]
- type Name = String
- data PrimQuery
  - = BaseTable TableName Scheme
  - | Project Assoc PrimQuery
  - | Restrict PrimExpr PrimQuery
  - | Group Assoc PrimQuery
  - | Binary RelOp PrimQuery PrimQuery
  - | Special SpecialOp PrimQuery
  - | Empty
- data RelOp
  - = Times
  - | Union
  - | UnionAll
  - | Intersect
  - | Divide
  - | Difference
- data SpecialOp
  - = Order [OrderExpr]
  - | Top Int
  - | Offset Int
- data PrimExpr
  - = AttrExpr Attribute
  - | BinExpr BinOp PrimExpr PrimExpr
  - | UnExpr UnOp PrimExpr
  - | AggrExpr AggrOp PrimExpr
  - | ConstExpr Literal
  - | CaseExpr [(PrimExpr, PrimExpr)] PrimExpr
  - | ListExpr [PrimExpr]
  - | ParamExpr (Maybe Name) PrimExpr
  - | FunExpr Name [PrimExpr]
  - | CastExpr Name PrimExpr
- data OrderExpr = OrderExpr OrderOp PrimExpr
- data BinOp
  - = OpEq
  - | OpLt
  - | OpLtEq
  - | OpGt
  - | OpGtEq
  - | OpNotEq
  - | OpAnd
  - | OpOr
  - | OpLike
  - | OpIn
  - | OpOther String
  - | OpCat
  - | OpPlus
  - | OpMinus
  - | OpMul
  - | OpDiv
  - | OpMod
  - | OpBitNot
  - | OpBitAnd
  - | OpBitOr
  - | OpBitXor
  - | OpAsg
- data UnOp
  - = OpNot
  - | OpIsNull
  - | OpIsNotNull
  - | OpLength
  - | UnOpOther String
- data OrderOp
  - = OpAsc
  - | OpDesc
- data AggrOp
  - = AggrCount
  - | AggrSum
  - | AggrAvg
  - | AggrMin
  - | AggrMax
  - | AggrStdDev
  - | AggrStdDevP
  - | AggrVar
  - | AggrVarP
  - | AggrOther String
- data Literal
  - = NullLit
  - | DefaultLit
  - | BoolLit Bool
  - | StringLit String
  - | IntegerLit Integer
  - | DoubleLit Double
  - | DateLit CalendarTime
  - | OtherLit String
- extend :: Assoc -> PrimQuery -> PrimQuery
- times :: PrimQuery -> PrimQuery -> PrimQuery
- attributes :: PrimQuery -> Scheme
- attrInExpr :: PrimExpr -> Scheme
- attrInOrder :: [OrderExpr] -> Scheme
- substAttr :: Assoc -> PrimExpr -> PrimExpr
- isAggregate :: PrimExpr -> Bool
- isConstant :: PrimExpr -> Bool
- foldPrimQuery :: (t, TableName -> Scheme -> t, Assoc -> t -> t, PrimExpr -> t -> t, RelOp -> t -> t -> t, Assoc -> t -> t, SpecialOp -> t -> t) -> PrimQuery -> t
- foldPrimExpr :: (Attribute -> t, Literal -> t, BinOp -> t -> t -> t, UnOp -> t -> t, AggrOp -> t -> t, [(t, t)] -> t -> t, [t] -> t, Maybe Name -> t -> t, Name -> [t] -> t, Name -> t -> t) -> PrimExpr -> t

# Type Declarations

## Types

type TableName = String Source

type Attribute = String Source

type Scheme = [Attribute] Source

type Assoc = [(Attribute, PrimExpr)] Source

type Name = String Source

## Data types

data PrimQuery Source

Constructors

BaseTable TableName Scheme |
Project Assoc PrimQuery |
Restrict PrimExpr PrimQuery |
Group Assoc PrimQuery |
Binary RelOp PrimQuery PrimQuery |
Special SpecialOp PrimQuery |
Empty |

Instances

Show PrimQuery Source |

data RelOp Source

Constructors

Times |
Union |
UnionAll |
Intersect |
Divide |
Difference |

Instances

Show RelOp Source |

data SpecialOp Source

Constructors

Order [OrderExpr] |
Top Int |
Offset Int |

Instances

Show SpecialOp Source |

data PrimExpr Source

Constructors

AttrExpr Attribute |
BinExpr BinOp PrimExpr PrimExpr |
UnExpr UnOp PrimExpr |
AggrExpr AggrOp PrimExpr |
ConstExpr Literal |
CaseExpr [(PrimExpr, PrimExpr)] PrimExpr |
ListExpr [PrimExpr] |
ParamExpr (Maybe Name) PrimExpr |
FunExpr Name [PrimExpr] |
CastExpr Name PrimExpr | Cast an expression to a given type.

Instances

Read PrimExpr Source |
Show PrimExpr Source |

data OrderExpr Source

Constructors

OrderExpr OrderOp PrimExpr |

Instances

Show OrderExpr Source |

data BinOp Source

Constructors

OpEq |
OpLt |
OpLtEq |
OpGt |
OpGtEq |
OpNotEq |
OpAnd |
OpOr |
OpLike |
OpIn |
OpOther String |
OpCat |
OpPlus |
OpMinus |
OpMul |
OpDiv |
OpMod |
OpBitNot |
OpBitAnd |
OpBitOr |
OpBitXor |
OpAsg |

Instances

Read BinOp Source |
Show BinOp Source |

data UnOp Source

Constructors

OpNot |
OpIsNull |
OpIsNotNull |
OpLength |
UnOpOther String |

Instances

Read UnOp Source |
Show UnOp Source |

data OrderOp Source

Constructors

OpAsc |
OpDesc |

Instances

Show OrderOp Source |

data AggrOp Source

Constructors

AggrCount |
AggrSum |
AggrAvg |
AggrMin |
AggrMax |
AggrStdDev |
AggrStdDevP |
AggrVar |
AggrVarP |
AggrOther String |

Instances

Read AggrOp Source |
Show AggrOp Source |

data Literal Source

Constructors

NullLit |
DefaultLit | represents a default value
BoolLit Bool |
StringLit String |
IntegerLit Integer |
DoubleLit Double |
DateLit CalendarTime |
OtherLit String | used for hacking in custom SQL

Instances

Read Literal Source |
Show Literal Source |

# Function declarations

extend :: Assoc -> PrimQuery -> PrimQuery Source

Creates a projection of some attributes while keeping all other attributes in the relation visible too.

times :: PrimQuery -> PrimQuery -> PrimQuery Source

Takes the cartesian product of two queries.

attributes :: PrimQuery -> Scheme Source

Returns the schema (the attributes) of a query

attrInExpr :: PrimExpr -> Scheme Source

Returns all attributes in an expression.

attrInOrder :: [OrderExpr] -> Scheme Source

Returns all attributes in a list of ordering expressions.

substAttr :: Assoc -> PrimExpr -> PrimExpr Source

Substitute attribute names in an expression.

isAggregate :: PrimExpr -> Bool Source

isConstant :: PrimExpr -> Bool Source

Determines if a primitive expression represents a constant or is an expression only involving constants.

foldPrimQuery :: (t, TableName -> Scheme -> t, Assoc -> t -> t, PrimExpr -> t -> t, RelOp -> t -> t -> t, Assoc -> t -> t, SpecialOp -> t -> t) -> PrimQuery -> t Source

Fold on `PrimQuery`

foldPrimExpr :: (Attribute -> t, Literal -> t, BinOp -> t -> t -> t, UnOp -> t -> t, AggrOp -> t -> t, [(t, t)] -> t -> t, [t] -> t, Maybe Name -> t -> t, Name -> [t] -> t, Name -> t -> t) -> PrimExpr -> t Source

Fold on `PrimExpr`