hssqlppp-0.5.18: 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

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

Instances

Updates

data CatalogUpdate

Constructors

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

CatCreateAggregate CatName [CatName] CatName

register a aggregate: name, param types, return type

CatCreateTable 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

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

type CatName = Text

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

data CatNameExtra

type name and precision and nullability

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 Postgres catalog, such as greatest, coalesce, keyword operators like 'and', etc..

defaultTemplate1Catalog :: Catalog

The catalog from a default template1 database in roughly the latest postgres. 'select version()' from the dbms this catalog was generated from: 'PostgreSQL 9.4.2 on x86_64-unknown-linux-gnu, compiled by gcc-4.9.real (Debian 4.9.2-17) 4.9.2, 64-bit'.

Catalog comparison

Functions

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

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

testing support

data Environment

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

represents type check failure upstream, don't produce additional type check errors