# gizmodel/sql/catalog/records

The catalog objects whose text has parts: each has one record type, one reader and one writer here. The parser writes them and the session, the binder and the catalog views read them; none of them splits the text itself. Parts stand between "\u0001", the items of a part between "\u0002".

```gizlang
import * as Records from "gizmodel/sql/catalog/records";
```

## Types

### `DomainCheck`

```gizlang
type DomainCheck = { name: string; check: string; }
```

A CHECK of a domain: its name and its condition over VALUE.

- `name`: `string`
- `check`: `string`

### `Domain`

```gizlang
type Domain = { base: string; notNull: bool; fill: string; checks: Vec<DomainCheck>; over: string; }
```

A domain as its catalog object ("domain") holds it: its base type, whether it refuses NULL, its default ("" for
none), its CHECK constraints in order, and the domain it is declared over ("" when over a plain type).

- `base`: `string`
- `notNull`: `bool`
- `fill`: `string`
- `checks`: `Vec<M197.DomainCheck>`
- `over`: `string`

### `PartitionKey`

```gizlang
type PartitionKey = { strategy: string; keys: Vec<string>; support: Vec<string>; }
```

The key of a partitioned table ("partkey"): its strategy (list, range or hash), its key expressions, and one
support name for each key or none. The parser gives each key's operator class there ("" for none); the stored
object of a hash key holds the class's extended hash function ("" for the type's own), and other strategies store
none.

- `strategy`: `string`
- `keys`: `Vec<string>`
- `support`: `Vec<string>`

### `PartitionBound`

```gizlang
type PartitionBound = { kind: string; values: Vec<string>; upper: Vec<string>; modulus: string; remainder: string; }
```

The bound of a partition ("partbound"), by `kind`: "default" takes the rows no other partition takes; "in" takes
the rows whose key is one of `values`; "range" those from `values` (included) to `upper` (excluded), one bound for
each key column; "hash" those whose key hash has `remainder` after division by `modulus` (both as the statement gave
them). `kind` is "" for a table that is no partition.

- `kind`: `string`
- `values`: `Vec<string>`
- `upper`: `Vec<string>`
- `modulus`: `string`
- `remainder`: `string`

### `Statistics`

```gizlang
type Statistics = { table: string; kinds: string; items: Vec<string>; }
```

Extended statistics ("pg statistics"): the table, the kinds as CREATE STATISTICS named them ("ndistinct,mcv"; ""
for every kind), and the items: a column name, or an expression in parentheses.

- `table`: `string`
- `kinds`: `string`
- `items`: `Vec<string>`

### `RuleRecord`

```gizlang
type RuleRecord = { event: string; instead: bool; condition: string; commands: string; disabled: bool; }
```

A rule ("pg rule", named "r on t"): the event it answers (select, insert, update or delete), whether it runs
INSTEAD of the statement (else ALSO), its WHERE condition ("" for none), its commands ("" for NOTHING), and whether
ALTER TABLE ... DISABLE RULE turned it off.

- `event`: `string`
- `instead`: `bool`
- `condition`: `string`
- `commands`: `string`
- `disabled`: `bool`

## Functions

### `domainRecord`

```gizlang
function domainRecord(domain: string, text: string): Domain
```

The reader of a domain object's text: the base type, "0" for NOT NULL, the default, one unnamed check (the form
before named checks; its name is DOMAIN_check), the named checks ("name\u0003check", "\u0004" between), and the
parent domain.

Effects: fail, alloc.

### `domainText`

```gizlang
function domainText(d: Domain): string
```

The writer of a domain object's text (domainRecord reads it); every check is written as a named one.

Effects: fail, alloc.

### `partitionKeyRecord`

```gizlang
function partitionKeyRecord(text: string): PartitionKey
```

The reader of a partition key's text; no keys for the text of a table that is not partitioned ("").

Effects: fail, alloc.

### `partitionKeyText`

```gizlang
function partitionKeyText(k: PartitionKey): string
```

The writer of a partition key's text (partitionKeyRecord reads it).

Effects: fail, alloc.

### `listBound`

```gizlang
function listBound(items: Vec<string>): string
```

The text of FOR VALUES IN (items).

Effects: fail, alloc.

### `rangeBound`

```gizlang
function rangeBound(lower: Vec<string>, upper: Vec<string>): string
```

The text of FOR VALUES FROM (lower) TO (upper).

Effects: fail, alloc.

### `hashBound`

```gizlang
function hashBound(modulus: string, remainder: string): string
```

The text of FOR VALUES WITH (MODULUS modulus, REMAINDER remainder).

Effects: fail, alloc.

### `partitionBoundRecord`

```gizlang
function partitionBoundRecord(text: string): PartitionBound
```

The reader of a partition bound's text (DEFAULT_BOUND, listBound, rangeBound and hashBound write it).

Effects: fail, alloc.

### `checksOf`

```gizlang
function checksOf(text: string): Vec<string>
```

The CHECK conditions of a table ("check"), in order: a "c" entry of the table's constraint object names one by its
position here.

Effects: fail, alloc.

### `checksText`

```gizlang
function checksText(checks: Vec<string>): string
```

The writer of a table's CHECK conditions (checksOf reads it): "\u0001" ends each.

Effects: fail, alloc.

### `statisticsRecord`

```gizlang
function statisticsRecord(text: string): Option<Statistics>
```

The reader of extended statistics' text; none for a text of another shape.

Effects: fail, alloc.

### `statisticsText`

```gizlang
function statisticsText(s: Statistics): string
```

The writer of extended statistics' text (statisticsRecord reads it).

Effects: fail, alloc.

### `ruleRecord`

```gizlang
function ruleRecord(text: string): Option<RuleRecord>
```

The reader of a rule's text; none for a text of another shape.

Effects: fail, alloc.

### `ruleText`

```gizlang
function ruleText(r: RuleRecord): string
```

The writer of a rule's text (ruleRecord reads it).

Effects: fail, alloc.

## Constants

### `DEFAULT_BOUND`

```gizlang
const DEFAULT_BOUND = "default"
```

The text of the default partition's bound.

