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:
let employeesSchema = [("name", TString), ("salary", TNum)] in let employeesTable = table "employees" employeesSchema in foreach employeesTable $ \emp -> having (primApp "<" [cnst 20000, project emp "salary"]) $ singleton (record [("name", project emp "name")])
- narcToSQL :: NarcTerm -> Query
- narcToSQLString :: NarcTerm -> String
- serialize :: Query -> String
- unit :: NarcTerm
- table :: Tabname -> [(Field, Type)] -> NarcTerm
- cnst :: Constable a => a -> NarcTerm
- 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
- result :: [(String, NarcTerm)] -> NarcTerm
- data Type
Translation to an SQL representation
Translate a Narc term to an SQL query string--perhaps the central | function of the interface.
Query to its ASCII SQL serialization.
Dies on those
Querys that don't represent valid SQL queries.
The language itself
A reference to a named database table; second argument is its schema type.
Lift a constant value into a query.
Constable types currently include
Apply some primitive function, such as
avg, to a list
A condition between two terms, as determined by the boolean value of the first term.
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
For each item in the collection resulting from the first argument, give it to the function which is the second argument and evaluate--this corresponds to a loop, or two one part of a cross in traditional SQL queries.
Filter the current iteration as per the condition in the first
argument. Corresponds to a
where clause in a SQL query.
A shortcut for giving the typical bottom of a ``FLWOR-style'' comprehension:
foreach t $ \row -> having (project x "a" > 2) $ result [("result", project x "b")]