Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module contains the database catalog data types and helper functions.
The catalog data type holds the catalog information needed to type check sql code, and a catalog value is produced after typechecking sql which represents the catalog that would be produced (e.g. for sql containing ddl)
You can create a catalog using the CatalogUpdate
type, and there
is example and util in the repo which reads a catalog from
an existing database in postgres.
- data Catalog
- data CatalogUpdate
- = CatCreateSchema CatName
- | CatCreateScalarType CatName
- | CatCreateDomainType CatName CatName
- | CatCreateArrayType CatName CatName
- | CatCreatePrefixOp CatName CatName CatName
- | CatCreatePostfixOp CatName CatName CatName
- | CatCreateBinaryOp CatName CatName CatName CatName
- | CatCreateFunction CatName [CatName] Bool CatName
- | CatCreateVariadicFunction CatName [CatName] Bool CatName
- | CatCreateSpecialOp CatName [CatName] Bool CatName
- | CatCreateAggregate CatName [CatName] CatName
- | CatCreateTable (CatName, CatName) [(CatName, CatNameExtra)]
- | CatCreateCast CatName CatName CastContext
- | CatCreateTypeCategoryEntry CatName (Text, Bool)
- data CastContext
- data CompositeFlavour
- type CatName = Text
- data CatNameExtra = CatNameExtra {
- catName :: CatName
- catPrecision :: Maybe Int
- catScale :: Maybe Int
- catNullable :: Bool
- mkCatNameExtra :: CatName -> CatNameExtra
- mkCatNameExtraNN :: CatName -> CatNameExtra
- updateCatalog :: [CatalogUpdate] -> Catalog -> Either [TypeError] Catalog
- deconstructCatalog :: Catalog -> [CatalogUpdate]
- data Environment
- brokeEnvironment :: Environment
- envSelectListEnvironment :: [(Text, TypeExtra)] -> Either [TypeError] Environment
Data types
The main datatype, this holds the catalog and context information to type check against.
Updates
data CatalogUpdate Source
CatCreateSchema CatName | register a schema with the given name |
CatCreateScalarType CatName | register a base scalar type with the given name |
CatCreateDomainType CatName CatName | register a domain type with name and base type |
CatCreateArrayType CatName CatName | register an array type with name and base type |
CatCreatePrefixOp CatName CatName CatName | register a prefix op, opname, param type, return type |
CatCreatePostfixOp CatName CatName CatName | register a postfix op, opname, param type, return type |
CatCreateBinaryOp CatName CatName CatName CatName | register a binary op, opname, the two param types, return type |
CatCreateFunction CatName [CatName] Bool CatName | register a function: name, param types, retsetof, return type |
CatCreateVariadicFunction CatName [CatName] Bool CatName | register a variadic function: name, param types, retsetof, return type the last parameter will be wrapped in an array type |
CatCreateSpecialOp CatName [CatName] Bool CatName | special ops include between, substring, position, basically all operators/functions which use mixfix or extra syntax (not including non scalar functions like aggregates) |
CatCreateAggregate CatName [CatName] CatName | register a aggregate: name, param types, return type |
CatCreateTable (CatName, CatName) [(CatName, CatNameExtra)] | register a table only: name, (colname,typename) pairs |
CatCreateCast CatName CatName CastContext | register a cast in the catalog |
CatCreateTypeCategoryEntry CatName (Text, Bool) | register a type category for a type (used in the implicit cast resolution) |
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
represents the name of something in the catalog, when schema support is added then this will change to (String,String)
data CatNameExtra Source
type name and precision and nullability
CatNameExtra | |
|
Functions
updateCatalog :: [CatalogUpdate] -> Catalog -> Either [TypeError] Catalog Source
Applies a list of CatalogUpdate
s to an Catalog
value
to produce a new Catalog value. TODO: there will be a split
between the individual low level updates which just update
one row
in the catalog type, and the high level updates
which correspond to ddl (e.g. create type will also add the
array type, create table will add a table, supply the
private columns automatically, and add the composite type)
highlevel not implemented yet. You must use the correct case and
the canonical names for identifiers/types
deconstructCatalog :: Catalog -> [CatalogUpdate] Source
testing support
data Environment Source
Represent an environment using an abstracted version of the syntax which produced the environment. This structure has all the catalog queries resolved. No attempt is made to combine environment parts from different sources, they are just stacked together, the logic for working with combined environments is in the query functions below
brokeEnvironment :: Environment Source
represents type check failure upstream, don't produce additional type check errors
envSelectListEnvironment :: [(Text, TypeExtra)] -> Either [TypeError] Environment Source