Narc
Description
Query SQL databases using Nested Relational Calculus embedded in Haskell.
The primed functions in this module are in fact the syntactic forms of the embedded language. Use them as, for example:
foreach (table "employees" []) $ \emp -> having (primApp "<" [cnst 20000, project emp "salary"]) $ singleton (record [(project emp "name")])
- type NarcTerm = Gensym (Term ())
- narcTermToSQL :: NarcTerm -> Query
- unit :: NarcTerm
- class Const a
- primApp :: String -> [NarcTerm] -> NarcTerm
- abs :: (String -> NarcTerm) -> NarcTerm
- app :: NarcTerm -> NarcTerm -> NarcTerm
- ifthenelse :: NarcTerm -> NarcTerm -> NarcTerm -> NarcTerm
- singleton :: NarcTerm -> NarcTerm
- nil :: NarcTerm
- union :: NarcTerm -> NarcTerm -> NarcTerm
- record :: [(String, NarcTerm)] -> NarcTerm
- project :: NarcTerm -> String -> NarcTerm
- foreach :: NarcTerm -> (NarcTerm -> NarcTerm) -> NarcTerm
- having :: NarcTerm -> NarcTerm -> NarcTerm
The type of the embedded terms
Translation to an SQL representation
narcTermToSQL :: NarcTerm -> QuerySource
Translate a Narc term to an SQL query.
The language itself
primApp :: String -> [NarcTerm] -> NarcTermSource
Apply some primitive function, such as (+)
or avg
, to a list
of arguments.
ifthenelse :: NarcTerm -> NarcTerm -> NarcTerm -> NarcTermSource
A condition between two terms, as determined by the boolean value of the first term.
record :: [(String, NarcTerm)] -> NarcTermSource
Construct a record (name-value pairs) out of other terms; usually
used, with base values for the record elements, as the final
result of a query, corresponding to the select
clause of a SQL
query, but can also be used with nested results internally in a
query.