hssqlppp-0.4.0: SQL parser and type checker

Database.HsSqlPpp.Catalog

Contents

Description

This module contains the database catalog data types and helper functions.

The catalog data type serves the following purposes:

  • Contains all the catalog information needed to type check against an existing database.
  • A copy of the catalog information from a default template1 database is included - defaultTemplate1Catalog.
  • It is used internally to keep track of updates to the catalog whilst running an annotation process (e.g. so that a select can type check against a create table given in the same source). It is also used to track other identifier types, such as attribute references in select expressions, and argument and variable types inside create function statements.

You can see what kind of stuff is contained in the Catalog type by looking at the CatalogUpdate type.

Synopsis

Data types

data Catalog

The main datatype, this holds the catalog and context information to type check against.

Updates

data CatalogUpdate

Constructors

CatCreateScalar Type String Bool

add a new scalar type with the name given, also creates an array type automatically

CatCreateDomain Type Type

add a new domain to the catalog

CatCreateComposite String [(String, Type)]

add a new composite type to the catalog

CatCreateCast Type Type CastContext

add a new cast to the catalog

CatCreateTable String [(String, Type)] [(String, Type)]

add a new table to the catalog with the given public and private columns also creates the composite type to go with this table

CatCreateView String [(String, Type)]

add the view to the catalog, using the column names and types supplied

CatCreateFunction FunFlav String [Type] Type Bool

add a new function to the catalog

CatDropFunction Bool String [Type]

drop a function from the catalog

ppCatUpdate :: CatalogUpdate -> String

attempt to show a readable representation of a CatalogUpdate value

bits and pieces

data CastContext

Use to note what the flavour of a cast is, i.e. if/when it can be used implicitly.

data CompositeFlavour

Used to distinguish between standalone composite types, and automatically generated ones, generated from a table or view respectively.

type CompositeDef = (String, CompositeFlavour, Type, Type)

Provides the definition of a composite type. The components are composite (or table or view) name, the flavour of the composite, the types of the composite attributes, and the types of the system columns iff the composite represents a table type (the third and fourth components are always CompositeTypes).

type FunctionPrototype = (String, [Type], Type, Bool)

The components are: function (or operator) name, argument types, return type and is variadic.

type DomainDefinition = (Type, Type)

The components are domain type, base type (todo: add check constraint).

Catalog values

emptyCatalog :: Catalog

Represents an empty catalog. This doesn't contain things like the 'and' operator, defaultCatalog contains these.

defaultCatalog :: Catalog

Represents what you probably want to use as a starting point if you are building an catalog from scratch. It contains information on built in function like things that aren't in the PostgreSQL catalog, such as greatest, coalesce, keyword operators like 'and', etc..

Catalog comparison

data CatalogDiff

items in first catalog and not second, items in second and not first.

compareCatalogs :: Catalog -> Catalog -> Catalog -> CatalogDiff

find differences between two catalogs

ppCatDiff :: CatalogDiff -> String

print a catdiff in a more human readable way than show.

Functions

updateCatalog :: Catalog -> [CatalogUpdate] -> Either [TypeError] Catalog

Applies a list of CatalogUpdates to an Catalog value to produce a new Catalog value.

operator utils

isOperatorName :: String -> Bool