hssqlppp-0.4.2: SQL parser and type checker

Safe HaskellNone
LanguageHaskell2010

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 Source

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

Instances

Updates

data CatalogUpdate Source

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 Source

attempt to show a readable representation of a CatalogUpdate value

bits and pieces

data CastContext Source

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

data CompositeFlavour Source

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

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

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) Source

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

type DomainDefinition = (Type, Type) Source

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

Catalog values

emptyCatalog :: Catalog Source

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

defaultCatalog :: Catalog Source

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 Source

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

Instances

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

find differences between two catalogs

ppCatDiff :: CatalogDiff -> String Source

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

Functions

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

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

operator utils