narc-0.1: Query SQL databases using Nested Relational Calculus embedded in Haskell.

Narc

Contents

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")])

Synopsis

The type of the embedded terms

type NarcTermSource

Arguments

 = Gensym (Term ())

Bleck. Rename.

Translation to an SQL representation

narcTermToSQL :: NarcTerm -> QuerySource

Translate a Narc term to an SQL query.

The language itself

unit :: NarcTermSource

A dummy value, or zero-width record.

class Const a Source

Instances

primApp :: String -> [NarcTerm] -> NarcTermSource

Apply some primitive function, such as (+) or avg, to a list of arguments.

abs :: (String -> NarcTerm) -> NarcTermSource

Create a functional abstraction.

app :: NarcTerm -> NarcTerm -> NarcTermSource

Apply a functional term to an argument.

ifthenelse :: NarcTerm -> NarcTerm -> NarcTerm -> NarcTermSource

A condition between two terms, as determined by the boolean value of the first term.

singleton :: NarcTerm -> NarcTermSource

A singleton collection of one item.

nil :: NarcTermSource

An empty collection.

union :: NarcTerm -> NarcTerm -> NarcTermSource

The union of two collections

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.

project :: NarcTerm -> String -> NarcTermSource

Project a field out of a record value.

foreach :: NarcTerm -> (NarcTerm -> NarcTerm) -> NarcTermSource

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.

having :: NarcTerm -> NarcTerm -> NarcTermSource

Filter the current iteration as per the condition in the first argument. Corresponds to a where clause in a SQL query.