hssqlppp-0.6.0: 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 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.

Synopsis

Data types

data Catalog Source

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

Updates

data CatalogUpdate Source

Constructors

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.

type CatName = Text Source

represents the name of something in the catalog, when schema support is added then this will change to (String,String)

Functions

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

Applies a list of CatalogUpdates 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

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