Skip to content

More powerful schema kind #4

@echatav

Description

@echatav

At the moment a schema is kinded as a TablesType, a list of named tables.

type TablesType = [(Symbol,[(Symbol,ColumnType)])]

This is wrong in two ways:

  1. Schemas contain more than just tables, they also contain views, user-defined functions, operators and types.
  2. A database can have more than 1 schema.
    From the PostgreSQL docs:

A database contains one or more named schemas, which in turn contain tables. Schemas also contain other kinds of named objects, including data types, functions, and operators. The same object name can be used in different schemas without conflict; for example, both schema1 and myschema can contain tables named mytable. Unlike databases, schemas are not rigidly separated: a user can access objects in any of the schemas in the database he is connected to, if he has privileges to do so.

In principle this could be a record datakind like

data SchemaType = SchemaType
  { tables :: TablesType
  , views :: TablesType
  , functions :: [(Symbol,[ColumnType],[ColumnType])]
  , typedefs :: [(Symbol,ColumnType)]
  }
type Database = [(Symbol,SchemaType)]

Unfortunately we don't get free type families from the record accessors as far as I know so you'd also have to define e.g.

GetTables :: SchemaType -> TablesType
ModifyTables :: (TablesType -> TablesType) -> SchemaType -> SchemaType

It might be easier to bite off small pieces of that, like support multiple schemas separately from having more than tables in schemas, and in doing the latter, take on each of views, functions, and typedefs separately.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions