Safe Haskell | None |
---|---|
Language | Haskell2010 |
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.
- data Catalog
- data CatalogUpdate
- = CatCreateScalar Type String Bool
- | CatCreateDomain Type Type
- | CatCreateComposite String [(String, Type)]
- | CatCreateCast Type Type CastContext
- | CatCreateTable String [(String, Type)] [(String, Type)]
- | CatCreateView String [(String, Type)]
- | CatCreateFunction FunFlav String [Type] Type Bool
- | CatDropFunction Bool String [Type]
- ppCatUpdate :: CatalogUpdate -> String
- data CastContext
- data CompositeFlavour
- type CompositeDef = (String, CompositeFlavour, Type, Type)
- type FunctionPrototype = (String, [Type], Type, Bool)
- type DomainDefinition = (Type, Type)
- data FunFlav
- emptyCatalog :: Catalog
- defaultCatalog :: Catalog
- defaultTemplate1Catalog :: Catalog
- data CatalogDiff = CatalogDiff [CatalogUpdate] [CatalogUpdate]
- compareCatalogs :: Catalog -> Catalog -> Catalog -> CatalogDiff
- ppCatDiff :: CatalogDiff -> String
- updateCatalog :: Catalog -> [CatalogUpdate] -> Either [TypeError] Catalog
- deconstructCatalog :: Catalog -> [CatalogUpdate]
- data OperatorType
- getOperatorType :: Catalog -> String -> Either [TypeError] OperatorType
- isOperatorName :: String -> Bool
Data types
The main datatype, this holds the catalog and context information to type check against.
Updates
data CatalogUpdate Source
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 CompositeType
s).
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.
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 CatalogUpdate
s to an Catalog
value
to produce a new Catalog value.
deconstructCatalog :: Catalog -> [CatalogUpdate] Source
operator utils
getOperatorType :: Catalog -> String -> Either [TypeError] OperatorType Source
isOperatorName :: String -> Bool Source