Reylo Type Defs

previewView JSON Schema

A format for types.

Reylo writes the type of every parameter and column it analyzes in it. A type says which values a slot can hold, precisely enough to pick a representation in any language that holds them all.

Types

Each type is an object with a kind.

Most other fields narrow the kind: a size, bounds, a pattern, a character set. A program reads kind and the fields it needs, and ignores the rest, since a field it doesn't know can only narrow the type or describe it. A few fields widen a type instead, each named under its kind below.

// A 32-bit integer from 0 to 150, which Postgres calls int4
{ "kind": "integer", "bits": 32, "min": "0", "max": "150", "label": "int4" }
  • Values inside a type are strings, in the kind's canonical text, so a 64-bit bound or a date survives any encoding. Counts, such as bits, and code points are integers.
  • A flag appears only when it's true. Its absence means false.
  • A label is the database's name for the type, where it has one. It never changes what the type means.
  • A comment is the documentation the source keeps on a named type, and a title is a short name written for a reader, as JSON Schema's title, while the label is the name the database knows the type by. Neither says anything of the values.

Slots

Where a value stands, with whether it may be null.

A column, a parameter, a struct's field, an array's element, a tuple's element and a map's key and value are each a slot: a type, and nullable where the value may be null. Nullability is on the slot and never in the type, since an outer join makes any column nullable.

// Text that may be null
{ "type": { "kind": "text" }, "nullable": true }

Kinds

Every type has one of these kinds:

KindWhat it holds
booleanA truth value
integerA whole number of a fixed width
floatAn IEEE 754 binary float
decimalAn exact decimal
textText
bytesBytes
uuidA 128-bit identifier
enumOne of a list of values
dateA calendar date
timeA time of day
datetimeA date and time as a wall clock reads it
instantA point on the timeline
zoned_datetimeA point on the timeline, with its time zone
durationA length of time
arrayElements in order
tupleValues in order, with no names
structNamed fields
mapKeys to values
tableRows of columns
jsonA JSON value
unionOne of several types
intersectionValues of every member at once
tagged_unionOne of several alternatives, named by a tag
rangeA range of an ordered type
multirangeNon-overlapping ranges
geometryAn OGC simple feature
xmlXML
nullAlways null
opaqueA type the format doesn't structure
unknownNothing is known

boolean

A truth value.

A comparison's result is one on every database, though MySQL and SQLite deliver it as 1 or 0.

Types
// Any truth value
{ "kind": "boolean" }
Holds

truefalse

Databases

Postgresboolean

MySQL—

SQLite—

integer

A whole number of a fixed width.

Its range follows from bits, two's complement unless unsigned. A bound is always inclusive, since x > 0 is x >= 1.

Types
// A 32-bit integer
{ "kind": "integer", "bits": 32 }

// A 64-bit unsigned integer
{ "kind": "integer", "bits": 64, "unsigned": true }

// From 0 to 150, and a multiple of 5
{ "kind": "integer", "bits": 32, "min": "0", "max": "150", "multiple_of": "5" }
Holds

-214748364802147483647

Databases

Postgressmallintintegerbigintoid

MySQLtinyintsmallintmediumintintbigintyearboolean

SQLiteinteger

float

An IEEE 754 binary float.

Its exponent and mantissa widths fix its range and precision, so a program picks the smallest float it has that holds both. It holds the infinities and NaN only where infinity and nan say so.

Types
// A double
{ "kind": "float", "exponent_bits": 11, "mantissa_bits": 52 }

// A double that also holds Infinity, -Infinity and NaN
{ "kind": "float", "exponent_bits": 11, "mantissa_bits": 52, "infinity": true, "nan": true }

// A single-precision float above 0
{ "kind": "float", "exponent_bits": 8, "mantissa_bits": 23, "exclusive_min": "0" }
Holds

1.5-0InfinityNaN

Databases

Postgresrealdouble precision

MySQLfloatdouble

SQLitereal

decimal

An exact decimal.

Its precision counts its digits, and its scale the digits after the point. A decimal is a number, so 1.5 and 1.50 are one value.

Types
// Up to 10 digits, 2 after the point
{ "kind": "decimal", "precision": 10, "min_scale": 2, "max_scale": 2 }

// Any decimal below 10^131072, NaN and the infinities too
{ "kind": "decimal", "min_scale": 0, "max_scale": 16383, "exclusive_min": "-1e131072", "exclusive_max": "1e131072", "infinity": true, "nan": true }
Holds

1.5099999999.99NaN

Databases

Postgresnumeric

MySQLdecimal

SQLite—

text

With no encoding, it's any valid Unicode text. An encoding names the character set its values are held in, from a fixed list, and ill_formed lets them be any sequence of that set's code units, valid or not. code_points narrows the characters further. Its size counts code points unless its unit says otherwise, and a pattern is an I-Regexp every value matches whole. A format names what the text is meant to be, by JSON Schema's format names or a source's own. It says nothing of the values, so a rule every value keeps is a pattern.

Types
// At most 255 code points
{ "kind": "text", "size": { "max": 255 } }

// Any character but NUL, as Postgres's text holds
{ "kind": "text", "code_points": [[1, 1114111]] }

// Text with an @ in it
{ "kind": "text", "pattern": "[^@]+@[^@]+" }

// Text meant to be an email address, by JSON Schema's format name
{ "kind": "text", "format": "email" }

// Text Latin-1 holds, as MySQL's latin1 stores it
{ "kind": "text", "encoding": "windows-1252" }

// At most 65,535 bytes of UTF-8
{ "kind": "text", "encoding": "UTF-8", "size": { "unit": "byte", "max": 65535 } }

// Bytes meant as UTF-8 that nothing checked, which may not be valid Unicode
{ "kind": "text", "encoding": "UTF-8", "ill_formed": true }
Holds

"ada@example.com""happy"""

Databases

Postgrestextvarcharcharname

MySQLcharvarchartinytexttextmediumtextlongtext

SQLitetext

bytes

A value's length is stated where the type fixes one.

Types
// Any number of bytes
{ "kind": "bytes" }

// Exactly 16 bytes
{ "kind": "bytes", "size": { "exact": 16 } }

// A PNG image
{ "kind": "bytes", "media_type": "image/png" }
Holds

0x01020x

Databases

Postgresbyteamacaddrmacaddr8

MySQLbinaryvarbinarytinyblobblobmediumbloblongblob

SQLiteblob

uuid

A 128-bit identifier.

It holds any 128 bits, written in RFC 9562's text form. Its versions say every value has one of those RFC 9562 versions: a UUID that uuidv7() or gen_random_uuid() makes, or a column whose CHECKs hold uuid_extract_version to one and keep it non-null. A column with a default uuidv7() has none, since an insert may write any UUID.

Types
// Any 128 bits
{ "kind": "uuid" }

// A version 7 UUID
{ "kind": "uuid", "versions": [7] }
Holds

019a6b2c-3d4e-7f80-9a1b-2c3d4e5f6071

Databases

Postgresuuid

MySQL—

SQLite—

enum

One of a list of values.

Its type is the type of every value, and its values the list, each in that type's canonical text. One value makes a literal, which a constant the statement writes is: select 'user' as kind gives the enum of "user".

Types
// One of two strings
{ "kind": "enum", "type": { "kind": "text" }, "values": ["happy", "sad"] }

// The integer 1
{ "kind": "enum", "type": { "kind": "integer", "bits": 32 }, "values": ["1"] }

// The literal true
{ "kind": "enum", "type": { "kind": "boolean" }, "values": ["true"] }
Holds

"happy"1

Databases

Postgresan enuma column a CHECK keeps to a lista constant

MySQLenuma constant

SQLitea constant

date

A calendar date.

Its bounds are ISO 8601 text, with a sign and more than four digits where a year needs them. With no bounds, it runs from 0001-01-01 to 9999-12-31.

Types
// Any date from 0001 to 9999
{ "kind": "date" }

// From 4714 BC to the year 5874897, and infinity and -infinity too
{ "kind": "date", "min": "-4713-11-24", "max": "+5874897-12-31", "infinity": true }
Holds

2026-11-04-infinity

Databases

Postgresdate

MySQLdate

SQLite—

time

A time of day.

Its tick is its smallest step, in seconds. It holds 24:00:00 only where its bounds say so, and keeps a UTC offset where offset says so.

Types
// To the microsecond, up to 24:00:00
{ "kind": "time", "tick": "1/1000000", "max": "24:00:00" }

// To the second, with its UTC offset
{ "kind": "time", "tick": "1", "offset": true }
Holds

09:30:0024:00:00

Databases

Postgrestimetimetz

MySQL—

SQLite—

datetime

A date and time as a wall clock reads it.

With no zone, it can't be read as an instant.

Types
// To the millisecond
{ "kind": "datetime", "tick": "1/1000" }
Holds

2026-11-04T09:30:00.123

Databases

Postgrestimestamp

MySQLdatetime

SQLite—

instant

A point on the timeline.

It's the moment alone, as Temporal's Instant is, written in UTC however a session prints it. Its bounds are in UTC.

Types
// To the microsecond, and infinity and -infinity too
{ "kind": "instant", "tick": "1/1000000", "infinity": true }
Holds

2026-11-04T17:30:00.123456Z

Databases

Postgrestimestamptz

MySQLtimestamp

SQLite—

zoned_datetime

A point on the timeline, with the time zone it was written in.

Each value keeps its zone, a region or a UTC offset, as Temporal's ZonedDateTime does, and is written as RFC 9557 writes one. With offset_only, every zone is an offset.

Types
// To the millisecond, in any zone
{ "kind": "zoned_datetime", "tick": "1/1000" }

// To 100 nanoseconds, with an offset, as SQL Server's datetimeoffset keeps it
{ "kind": "zoned_datetime", "tick": "1/10000000", "offset_only": true }
Holds

2026-11-04T09:30:00-08:00[America/Los_Angeles]2026-11-04T09:30:00-08:00[-08:00]

Databases

Postgres—

MySQL—

SQLite—

duration

A length of time.

Its parts are months, days and a time, each signed on its own, so 1 month and 30 days are two values. Its max is an ISO 8601 duration of the parts it has, each at the largest magnitude it reaches.

Types
// Months, days and a time to the microsecond
{ "kind": "duration", "max": "P2147483648M2147483648DT2562047788H54.775808S", "tick": "1/1000000" }

// A time alone, up to 838 hours, to the second
{ "kind": "duration", "max": "PT838H59M59S", "tick": "1" }
Holds

P1M3DPT1H30MP-2D

Databases

Postgresinterval

MySQLtime

SQLite—

array

Elements, in order.

Each element is a slot of its own, so it says whether it may be null. An array is flat: a two-dimensional one is an array of arrays. A pgvector vector is an array of floats, and a set an array whose elements never repeat, distinct, as MySQL's SET is.

Types
// Integers, each of which may be null
{ "kind": "array", "element": { "type": { "kind": "integer", "bits": 32 }, "nullable": true } }

// Exactly 3 floats
{ "kind": "array", "size": { "exact": 3 }, "element": { "type": { "kind": "float", "exponent_bits": 8, "mantissa_bits": 23 } } }

// Members that never repeat
{ "kind": "array", "distinct": true, "element": { "type": { "kind": "enum", "type": { "kind": "text" }, "values": ["a", "b", "c"] } } }
Holds

[1, null, 3][]

Databases

Postgresany arraybitvarbitlsegpolygonvectorhalfvec

MySQLsetbit

SQLite—

tuple

Values in order, each of its own type, with no names.

Its elements are always there. Its optional_elements may be missing from the end, and its rest takes any number after them.

Types
// An integer, then text that may be null
{ "kind": "tuple", "elements": [{ "type": { "kind": "integer", "bits": 32 } }, { "type": { "kind": "text" }, "nullable": true }] }

// Text, then any number of integers
{ "kind": "tuple", "elements": [{ "type": { "kind": "text" } }], "rest": { "type": { "kind": "integer", "bits": 32 } } }
Holds

[1, "a"][2, null]

Databases

Postgres—

MySQL—

SQLite—

struct

Named fields, in order.

Each field is a slot with a name. It may be optional, its key left out, with a default the key takes when it is. A struct holds exactly its fields, unless extra lets it hold other keys too, each a value in its slot. A field may have a title.

Types
// A point
{
  "kind": "struct",
  "fields": [
    { "name": "x", "type": { "kind": "float", "exponent_bits": 11, "mantissa_bits": 52 } },
    { "name": "y", "type": { "kind": "float", "exponent_bits": 11, "mantissa_bits": 52 } }
  ]
}

// An optional field, with its default and its comment
{
  "kind": "struct",
  "fields": [
    { "name": "id", "type": { "kind": "integer", "bits": 64 } },
    { "name": "role", "optional": true, "default": "member", "comment": "What the user may do", "type": { "kind": "enum", "type": { "kind": "text" }, "values": ["admin", "member"] } }
  ]
}

// An open object, whose other keys hold text
{
  "kind": "struct",
  "fields": [{ "name": "id", "type": { "kind": "integer", "bits": 64 } }],
  "extra": { "type": { "kind": "text" } }
}

// A title on the struct and on a field, beside the database's name for the type
{
  "kind": "struct",
  "title": "Mailing address",
  "label": "public.address",
  "fields": [{ "name": "zip", "title": "ZIP code", "type": { "kind": "text" } }]
}
Holds

{ "x": 1, "y": 2 }

Databases

Postgresa composite typepointlineboxpathcircle

MySQL—

SQLite—

map

Keys to values, each key once.

The key is a slot, as the value is, and the size counts the keys. A map whose keys may repeat is an array of { key, value } structs.

Types
// Text keys to text that may be null
{ "kind": "map", "key": { "type": { "kind": "text" } }, "value": { "type": { "kind": "text" }, "nullable": true } }

// At most 64 keys
{ "kind": "map", "key": { "type": { "kind": "text" } }, "value": { "type": { "kind": "integer", "bits": 32 } }, "size": { "max": 64 } }
Holds

{ "color": "red", "size": null }

Databases

Postgreshstore

MySQL—

SQLite—

table

Rows of columns.

It's what a statement returns, and its cardinality says how many rows: one, at_most_one, many or none. Each column is a field, never optional. Where there may be many rows, unique lists the sets of columns no two rows share, a table's primary key first, and order the columns the rows are sorted on.

Types
// Rows, unique by id, newest first
{
  "kind": "table",
  "cardinality": "many",
  "columns": [
    { "name": "id", "type": { "kind": "integer", "bits": 64 } },
    { "name": "created_at", "type": { "kind": "instant", "tick": "1/1000000" } }
  ],
  "unique": [["id"]],
  "order": [{ "column": "created_at", "desc": true, "nulls": "first" }]
}

// One row, a count
{ "kind": "table", "cardinality": "one", "columns": [{ "name": "n", "type": { "kind": "integer", "bits": 64 } }] }
Holds

[{ "id": 1 }, { "id": 2 }]

Databases

Postgresa statement's result

MySQLa statement's result

SQLitea statement's result

json

A JSON value.

Its content is what a statement built, in these same types, and its schema a JSON Schema every value satisfies. With neither, it's any JSON.

Types
// Any JSON value
{ "kind": "json" }

// An object of an id and a title
{
  "kind": "json",
  "content": {
    "type": {
      "kind": "struct",
      "fields": [
        { "name": "id", "type": { "kind": "integer", "bits": 64 } },
        { "name": "title", "type": { "kind": "text" } }
      ]
    }
  }
}

// What a JSON Schema admits
{ "kind": "json", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "required": ["x"] } }
Holds

{ "id": 1, "title": "Hello" }null

Databases

Postgresjsonjsonb

MySQLjson

SQLite—

union

One of several types.

A union is flat, of two members or more, and lists its members in the order of the kinds. A union of structs that each give one field a different literal is a discriminated union, as OpenAPI's discriminator and TypeScript describe one: each value says which member it is by that field.

Types
// An integer or text
{ "kind": "union", "members": [{ "kind": "integer", "bits": 64 }, { "kind": "text" }] }

// A cat or a dog, which its type field names
{
  "kind": "union",
  "members": [
    { "kind": "struct", "fields": [{ "name": "type", "type": { "kind": "enum", "type": { "kind": "text" }, "values": ["cat"] } }, { "name": "meows", "type": { "kind": "boolean" } }] },
    { "kind": "struct", "fields": [{ "name": "type", "type": { "kind": "enum", "type": { "kind": "text" }, "values": ["dog"] } }, { "name": "barks", "type": { "kind": "boolean" } }] }
  ]
}
Holds

12"abc"

Databases

Postgresinetcidr

MySQL—

SQLiteany column outside a strict table

intersection

Values of every member at once.

It's JSON Schema's allOf and TypeScript's &. An intersection one struct can write, of structs whose fields agree or of a struct and a map with text keys, is written as that struct.

Types
// A cat or a dog, with an id beside whichever it is
{
  "kind": "intersection",
  "members": [
    {
      "kind": "union",
      "members": [
        { "kind": "struct", "fields": [{ "name": "meows", "type": { "kind": "boolean" } }], "extra": { "type": { "kind": "unknown" }, "nullable": true } },
        { "kind": "struct", "fields": [{ "name": "barks", "type": { "kind": "boolean" } }], "extra": { "type": { "kind": "unknown" }, "nullable": true } }
      ]
    },
    { "kind": "struct", "fields": [{ "name": "id", "type": { "kind": "integer", "bits": 64 } }], "extra": { "type": { "kind": "unknown" }, "nullable": true } }
  ]
}
Holds

{ "id": 1, "meows": true }

Databases

Postgres—

MySQL—

SQLite—

tagged_union

One of several alternatives, each named by a tag.

Every value carries its tag beside the value, even where the value is null. Unlike a union's members, two alternatives may hold one type.

Types
// A number or text, each tagged
{
  "kind": "tagged_union",
  "alternatives": [
    { "tag": "num", "type": { "kind": "integer", "bits": 32 }, "nullable": true },
    { "tag": "str", "type": { "kind": "text" }, "nullable": true }
  ]
}
Holds

{ "tag": "num", "value": 1 }

Databases

Postgres—

MySQL—

SQLite—

range

A range of an ordered type.

It may be empty, and either end may be unbounded.

Types
// A range of instants
{ "kind": "range", "subtype": { "kind": "instant", "tick": "1/1000000" } }
Holds

[2026-11-04T09:00Z, 2026-11-04T10:00Z)empty

Databases

Postgresint4rangeint8rangenumrangetsrangetstzrangedaterange

MySQL—

SQLite—

multirange

Non-overlapping ranges, in order.

Types
// Ranges of integers
{ "kind": "multirange", "subtype": { "kind": "integer", "bits": 32 } }
Holds

{[1,3), [5,8)}{}

Databases

Postgresint4multirangeint8multirangenummultirangetsmultirangetstzmultirangedatemultirange

MySQL—

SQLite—

geometry

An OGC simple feature.

It may name its model, its spatial reference, its subtype and its coordinates.

Types
// A point in WGS 84, with X and Y
{ "kind": "geometry", "srid": 4326, "subtype": "point", "coordinates": "xy" }

// Any shape on the sphere
{ "kind": "geometry", "model": "geodetic" }
Holds

SRID=4326;POINT(-71.06 42.36)

Databases

Postgresgeometrygeography

MySQLgeometrypointlinestringpolygonmultipointmultilinestringmultipolygongeometrycollection

SQLite—

xml

A document with one root, or with fragment several.

Types
// A document
{ "kind": "xml" }

// A fragment, which may have several roots
{ "kind": "xml", "fragment": true }
Holds

<a/><a/><b/>

Databases

Postgresxml

MySQL—

SQLite—

null

Always null.

It stands in a nullable slot, for a value a statement always writes as null.

Types
// The field a json_build_object('a', null) writes
{ "kind": "null" }
Holds

null

Databases

Postgresa null the statement writes

MySQLa null the statement writes

SQLite—

opaque

A type the format doesn't structure.

Its label is all the format says. A program that meets a kind it doesn't know reads it as this one.

Types
// A Postgres extension's type, known by its name
{ "kind": "opaque", "label": "ltree" }
Holds

top.science.physics

Databases

Postgresmoneytsvectortsquerypg_lsnan extension's type

MySQL—

SQLite—

unknown

Nothing is known about the values.

A parameter nothing in the statement types is one, where allow_untyped_params lets it through.

Types
// Any value
{ "kind": "unknown" }
Databases

Postgres—

MySQL—

SQLiteany column in a strict table

Specification

Every type and field, as TypeScript, generated from the format's JSON Schema:

spec/index.ts
export type Type =
  | BooleanType
  | IntegerType
  | FloatType
  | DecimalType
  | TextType
  | BytesType
  | UuidType
  | EnumType
  | DateType
  | TimeType
  | DateTimeType
  | InstantType
  | ZonedDateTimeType
  | DurationType
  | ArrayType
  | TupleType
  | StructType
  | MapType
  | TableType
  | JsonType
  | UnionType
  | IntersectionType
  | TaggedUnionType
  | RangeType
  | MultirangeType
  | GeometryType
  | XmlType
  | NullType
  | OpaqueType
  | UnknownType;

export interface Base {
  label?: string;
  comment?: string;
  title?: string;
}

export interface InclusivelyBounded {
  min?: string;
  max?: string;
}

export interface Bounded extends InclusivelyBounded {
  exclusive_min?: string;
  exclusive_max?: string;
}

export interface Size {
  exact?: number;
  min?: number;
  max?: number;
}

export interface Sized {
  size?: Size;
}

export interface BooleanType extends Base {
  kind: "boolean";
}

export interface IntegerType extends Base, InclusivelyBounded {
  kind: "integer";
  bits: number;
  unsigned?: true;
  multiple_of?: string;
}

export interface FloatType extends Base, Bounded {
  kind: "float";
  exponent_bits: number;
  mantissa_bits: number;
  infinity?: true;
  nan?: true;
}

export interface DecimalType extends Base, Bounded {
  kind: "decimal";
  precision?: number;
  min_scale?: number;
  max_scale?: number;
  infinity?: true;
  nan?: true;
  multiple_of?: string;
}

export interface TextType extends Base {
  kind: "text";
  encoding?: Charset;
  ill_formed?: true;
  code_points?: [number, number][];
  size?: TextSize;
  pattern?: string;
  media_type?: string;
  format?: string;
}

export interface TextSize extends Size {
  unit?: "code_unit" | "byte";
}

export type Charset =
  | "UTF-8"
  | "UTF-16"
  | "UTF-32"
  | "CESU-8"
  | "GB18030"
  | "US-ASCII"
  | "ISO-8859-1"
  | "ISO-8859-2"
  | "ISO-8859-3"
  | "ISO-8859-4"
  | "ISO-8859-5"
  | "ISO-8859-6"
  | "ISO-8859-7"
  | "ISO-8859-8"
  | "ISO-8859-9"
  | "ISO-8859-10"
  | "ISO-8859-13"
  | "ISO-8859-14"
  | "ISO-8859-15"
  | "ISO-8859-16"
  | "windows-874"
  | "windows-1250"
  | "windows-1251"
  | "windows-1252"
  | "windows-1253"
  | "windows-1254"
  | "windows-1255"
  | "windows-1256"
  | "windows-1257"
  | "windows-1258"
  | "IBM437"
  | "IBM850"
  | "IBM852"
  | "IBM866"
  | "KOI8-R"
  | "KOI8-U"
  | "macintosh"
  | "TIS-620"
  | "DEC-MCS"
  | "hp-roman8"
  | "SEN_850200_B"
  | "Shift_JIS"
  | "Windows-31J"
  | "EUC-JP"
  | "ISO-2022-JP"
  | "EUC-KR"
  | "GB2312"
  | "GBK"
  | "Big5"
  | "Big5-HKSCS";

export interface BytesType extends Base, Sized {
  kind: "bytes";
  media_type?: string;
}

export interface UuidType extends Base {
  kind: "uuid";
  versions?: number[];
}

export interface EnumType extends Base {
  kind: "enum";
  type: Type;
  values: string[];
}

export interface DateType extends Base, Bounded {
  kind: "date";
  infinity?: true;
}

export interface TimeType extends Base, Bounded {
  kind: "time";
  tick: string;
  offset?: true;
}

export interface DateTimeType extends Base, Bounded {
  kind: "datetime";
  tick: string;
  infinity?: true;
}

export interface InstantType extends Base, Bounded {
  kind: "instant";
  tick: string;
  infinity?: true;
}

export interface ZonedDateTimeType extends Base, Bounded {
  kind: "zoned_datetime";
  tick: string;
  offset_only?: true;
  infinity?: true;
}

export interface DurationType extends Base {
  kind: "duration";
  max: string;
  tick?: string;
  infinity?: true;
}

export interface ArrayType extends Base, Sized {
  kind: "array";
  element: Slot;
  distinct?: true;
}

export interface TupleType extends Base {
  kind: "tuple";
  elements: Slot[];
  optional_elements?: Slot[];
  rest?: Slot;
}

export interface StructType extends Base {
  kind: "struct";
  fields: Field[];
  extra?: Slot;
}

export interface MapType extends Base, Sized {
  kind: "map";
  key: Slot;
  value: Slot;
}

export interface TableType extends Base {
  kind: "table";
  cardinality: "one" | "at_most_one" | "many" | "none";
  columns: Field[];
  unique?: string[][];
  order?: SortKey[];
}

export interface SortKey {
  column: string;
  desc?: true;
  nulls: "first" | "last";
}

export interface JsonType extends Base {
  kind: "json";
  content?: Slot;
  schema?: { $schema: string; [keyword: string]: unknown; };
}

export interface UnionType extends Base {
  kind: "union";
  members: Type[];
}

export interface IntersectionType extends Base {
  kind: "intersection";
  members: Type[];
}

export interface TaggedUnionType extends Base {
  kind: "tagged_union";
  alternatives: Alternative[];
}

export interface Alternative extends Slot {
  tag: string;
}

export interface RangeType extends Base {
  kind: "range";
  subtype: Type;
}

export interface MultirangeType extends Base {
  kind: "multirange";
  subtype: Type;
}

export interface GeometryType extends Base {
  kind: "geometry";
  model?: "planar" | "geodetic";
  srid?: number;
  subtype?: "point" | "linestring" | "polygon" | "multipoint" | "multilinestring" | "multipolygon" | "geometrycollection";
  coordinates?: "xy" | "xyz" | "xym" | "xyzm";
}

export type XmlType = XmlDocument | XmlFragment;

export interface XmlDocument extends Base {
  kind: "xml";
  fragment?: false;
  schemas?: string[];
}

export interface XmlFragment extends Base {
  kind: "xml";
  fragment: true;
}

export interface NullType {
  kind: "null";
}

export interface OpaqueType extends Base {
  kind: "opaque";
  label: string;
}

export interface UnknownType {
  kind: "unknown";
}

export interface StatementDescriptor {
  $schema: "https://reylo.dev/typedefs/preview.json";
  dialect: Dialect;
  sql: string;
  kind?: "select" | "insert" | "update" | "delete" | "merge" | "other";
  comment?: string;
  params: Param[];
  result: TableType;
  capabilities?: Capabilities;
  diagnostics: Diagnostic[];
}

export interface Diagnostic {
  message: string;
  start: number;
  end: number;
  code?: string;
}

export interface Slot {
  type: Type;
  nullable?: true;
}

export interface Field extends Slot {
  name: string;
  optional?: true;
  default?: string;
  comment?: string;
  title?: string;
}

export interface Param extends Slot {
  name: string;
  optional?: true;
  comment?: string;
}

export interface Dialect {
  name: string;
  version: string;
}

export interface Capabilities {
  tables: { [table: string]: Access; } | "unknown";
  ddl?: true;
  transaction?: true;
  session?: true;
  external?: true;
}

export type Access = "read" | "readlock" | "write";
Released under the MIT License. Copyright © 2026 Colin McDonnell.

On this page